Sha256: 807b492a3e7ddac58f46d88652bb96f2617441f97bf579a5cfd490b970c49ab8

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "talkie/comments_renderer"

module Talkie
  module RendererHelper
    extend ActiveSupport::Concern

    DELEGATED_METHODS_TO_COMMENTS_RENDERER = %i[commentable
                                                root_comments
                                                nested_enabled?
                                                display_user_handler?
                                                display_user_avatar?].freeze

    HELPER_METHODS = %i[talkie_on
                        nested_enabled?
                        display_user_handler?
                        display_user_avatar?
                        root_comments
                        commentable].freeze

    included do
      delegate *DELEGATED_METHODS_TO_COMMENTS_RENDERER, to: :comments_renderer
      helper_method *HELPER_METHODS
    end

    protected

    def talkie_on(*args)
      options = args.extract_options!
      commentable = args[0]

      @comments_renderer ||= Talkie::CommentsRenderer.new(view_context, commentable, options)

      @comments_renderer.render
    end

    def comments_renderer
      @comments_renderer
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
talkie-0.1.0 lib/talkie/renderer_helper.rb