Class: Phlex::Rails::Template::Registry
- Inherits:
-
Object
- Object
- Phlex::Rails::Template::Registry
- Defined in:
- lib/phlex/rails/template/registry.rb
Instance Method Summary collapse
- #build(view_context, handler_name, &template_block) ⇒ Object
- #configurator_class_for(handler_name) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(handler_name, configurator_class = nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
7 8 9 |
# File 'lib/phlex/rails/template/registry.rb', line 7 def initialize @handlers = {} end |
Instance Method Details
#build(view_context, handler_name, &template_block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/phlex/rails/template/registry.rb', line 23 def build(view_context, handler_name, &template_block) configurator_class = configurator_class_for(handler_name) configurator = configurator_class.new(view_context) component_class = Class.new(configurator.component_class) do define_method(:view_template, &template_block) end configurator.build(component_class) end |
#configurator_class_for(handler_name) ⇒ Object
19 20 21 |
# File 'lib/phlex/rails/template/registry.rb', line 19 def configurator_class_for(handler_name) @handlers[handler_name] || Configurator end |
#register(handler_name, configurator_class = nil, &block) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/phlex/rails/template/registry.rb', line 11 def register(handler_name, configurator_class = nil, &block) if block_given? @handlers[handler_name] = Class.new(Configurator, &block) else @handlers[handler_name] = configurator_class end end |