class Shortcode::Presenter

Attributes

attributes[R]
configuration[R]
content[R]

Public Class Methods

new(name, configuration, attributes, content, additional_attributes) click to toggle source
# File lib/shortcode/presenter.rb, line 22
def initialize(name, configuration, attributes, content, additional_attributes)
  @configuration = configuration
  @attributes = attributes
  @content = content
  @additional_attributes = additional_attributes
  initialize_custom_presenter(name)
end
register(configuration, presenter) click to toggle source
# File lib/shortcode/presenter.rb, line 3
def self.register(configuration, presenter)
  validate presenter
  [*presenter.for].each { |k| configuration.presenters[k.to_sym] = presenter }
end
validate(presenter) click to toggle source
# File lib/shortcode/presenter.rb, line 8
def self.validate(presenter)
  unless presenter.respond_to?(:for)
    raise ArgumentError, "The presenter must define the class method #for"
  end
  unless presenter.private_instance_methods(false).include?(:initialize)
    raise ArgumentError, "The presenter must define an initialize method"
  end
  %w[content attributes].each do |method|
    unless presenter.method_defined?(method.to_sym)
      raise ArgumentError, "The presenter must define the method ##{method}"
    end
  end
end

Private Instance Methods

initialize_custom_presenter(name) click to toggle source
# File lib/shortcode/presenter.rb, line 38
def initialize_custom_presenter(name)
  return unless configuration.presenters.key?(name.to_sym)
  presenter   = configuration.presenters[name.to_sym].new(@attributes, @content, @additional_attributes)
  @attributes = presenter.attributes
  @content    = presenter.content
end