Module: ComponentHelper
- Defined in:
- app/helpers/component_helper.rb
Instance Method Summary collapse
-
#component(name, **kwargs, &block) ⇒ Object
(also: #comp)
Create a component in a view.
-
#method_missing(symbol, *args, **kwargs, &block) ⇒ Object
Create a component in a view with shorthand syntax.
-
#respond_to_missing?(symbol, *args) ⇒ Boolean
:nodoc:.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, **kwargs, &block) ⇒ Object
Create a component in a view with shorthand syntax. This is the same as calling component with the same arguments.
48 49 50 51 52 |
# File 'app/helpers/component_helper.rb', line 48 def method_missing symbol, *args, **kwargs, &block super unless respond_to?(symbol) component symbol, *args, **kwargs, &block end |
Instance Method Details
#component(name, **kwargs, &block) ⇒ Object Also known as: comp
Create a component in a view.
other components inside this block. You can set locals inside this block.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/component_helper.rb', line 16 def component name, **kwargs, &block component = Component.new(name, kwargs, lookup_context, nil, block) component._renderer = proc do |partial, locals, captured| render partial, locals do captured end end component._capture = proc do |component, block| if block capture do block.call(component) end end end component._capture_self component._yield_renderer end |
#respond_to_missing?(symbol, *args) ⇒ Boolean
:nodoc:
55 56 57 58 |
# File 'app/helpers/component_helper.rb', line 55 def respond_to_missing? symbol, *args lookup_context.exists?("components/#{symbol}/#{symbol}", [], true) || lookup_context.exists?("components/#{symbol}", [], true) end |