Class: Props::Partialer
- Inherits:
-
Object
- Object
- Props::Partialer
- Defined in:
- lib/props_template/extensions/partial_renderer.rb
Instance Method Summary collapse
- #block_opts_to_render_opts(builder, options) ⇒ Object
- #find_and_add_template(all_options) ⇒ Object
- #handle(options) ⇒ Object
-
#initialize(base, context, builder) ⇒ Partialer
constructor
A new instance of Partialer.
- #refine_options(options, item = nil) ⇒ Object
Constructor Details
#initialize(base, context, builder) ⇒ Partialer
Returns a new instance of Partialer.
5 6 7 8 9 |
# File 'lib/props_template/extensions/partial_renderer.rb', line 5 def initialize(base, context, builder) @context = context @builder = builder @base = base end |
Instance Method Details
#block_opts_to_render_opts(builder, options) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/props_template/extensions/partial_renderer.rb', line 27 def block_opts_to_render_opts(builder, ) partial, pass_opts = [*[:partial]] pass_opts ||= {} pass_opts[:locals] ||= {} pass_opts[:locals][:json] = @builder pass_opts[:partial] = partial pass_opts end |
#find_and_add_template(all_options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/props_template/extensions/partial_renderer.rb', line 11 def find_and_add_template() first_opts = [0] if first_opts[:partial] partial_opts = block_opts_to_render_opts(@builder, first_opts) renderer = PartialRenderer.new(@context, partial_opts) .map do |opts| opts[:_template] = renderer.template opts end else end end |
#handle(options) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/props_template/extensions/partial_renderer.rb', line 41 def handle() pass_opts = block_opts_to_render_opts(@builder, ) renderer = PartialRenderer.new(@context, pass_opts) template = [:_template] || renderer.template renderer.render(template, pass_opts) end |
#refine_options(options, item = nil) ⇒ Object
37 38 39 |
# File 'lib/props_template/extensions/partial_renderer.rb', line 37 def (, item = nil) PartialRenderer.(, item) end |