Module: Components

Defined in:
lib/components.rb,
lib/components/base.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ActionController, ActionView, Caching Classes: Base, View

Class Method Summary collapse

Class Method Details

.merge_standard_component_options!(args, standard_options, arity) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/components.rb', line 11

def self.merge_standard_component_options!(args, standard_options, arity)
  if standard_options
    # when the method's arity is positive, it only accepts a fixed list of arguments, so we can't add another.
    args << {} unless args.last.is_a?(Hash) or not arity < 0
    args.last.reverse_merge!(standard_options) if args.last.is_a?(Hash)
  end
end

.render(name, component_args = [], options = {}) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/components.rb', line 2

def self.render(name, component_args = [], options = {})
  klass, method = name.split('/')
  component = (klass + "_component").camelcase.constantize.new
  component.form_authenticity_token = options[:form_authenticity_token]
  merge_standard_component_options!(component_args, options[:standard_component_options], component.method(method).arity)
  component.logger.debug "Rendering component #{name}"
  component.send(method, *component_args).to_s
end