Sha256: cb22c11979f7f81adac50c74d09eeec8fac53c10a48e3f10174be6c06f8af536

Contents?: true

Size: 972 Bytes

Versions: 12

Compression:

Stored size: 972 Bytes

Contents

# frozen_string_literal: true

module Talkie
  class CommentsRenderer
    attr_reader :commentable

    def initialize(view_context, commentable, options = {})
      @view_context = view_context
      @commentable = commentable
      @options = options
    end

    def render
      @view_context.render "talkie/comments/template"
    end

    def nested_enabled?
      @options[:nested] || false
    end

    def deletable?
      @options[:deletable] || false
    end

    def display_user_avatar?
      @options[:display_user_avatar].present?
    end

    def display_user_handler?
      @options[:display_user_handler] || false
    end

    def root_comments
      comments = @commentable.root_parents
      comments = comments.includes(:creator) if display_user_info?
      comments = comments.includes(:children) if nested_enabled?

      comments
    end

    private

    def display_user_info?
      display_user_handler? || display_user_avatar?
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
talkie-0.5.1 lib/talkie/comments_renderer.rb
talkie-0.5.0 lib/talkie/comments_renderer.rb
talkie-0.4.1 lib/talkie/comments_renderer.rb
talkie-0.4.0 lib/talkie/comments_renderer.rb
talkie-0.3.5 lib/talkie/comments_renderer.rb
talkie-0.3.4 lib/talkie/comments_renderer.rb
talkie-0.3.3 lib/talkie/comments_renderer.rb
talkie-0.3.2 lib/talkie/comments_renderer.rb
talkie-0.3.1 lib/talkie/comments_renderer.rb
talkie-0.3.0 lib/talkie/comments_renderer.rb
talkie-0.2.0 lib/talkie/comments_renderer.rb
talkie-0.1.1 lib/talkie/comments_renderer.rb