Class: Props::Partialer

Inherits:
Object
  • Object
show all
Defined in:
lib/props_template/extensions/partial_renderer.rb

Instance Method Summary collapse

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, options)
  partial, pass_opts = [*options[: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(all_options)
  first_opts = all_options[0]

  if first_opts[:partial]
    partial_opts = block_opts_to_render_opts(@builder, first_opts)
    renderer = PartialRenderer.new(@context, partial_opts)

    all_options.map do |opts|
      opts[:_template] = renderer.template
      opts
    end
  else
    all_options
  end
end

#handle(options) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/props_template/extensions/partial_renderer.rb', line 41

def handle(options)
  pass_opts = block_opts_to_render_opts(@builder, options)
  renderer = PartialRenderer.new(@context, pass_opts)
  template = options[:_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 refine_options(options, item = nil)
  PartialRenderer.refine_options(options, item)
end