Module: Props::LayoutPatch
- Defined in:
- lib/props_template/layout_patch.rb
Instance Method Summary collapse
- #render(context, options) ⇒ Object
- #render_props_template(view, template, path, locals) ⇒ Object
- #resolve_props_layout(layout, keys, formats) ⇒ Object
Instance Method Details
#render(context, options) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/props_template/layout_patch.rb', line 3 def render(context, ) [:locals] ||= {} [:locals][:json] = nil @details = extract_details() template = determine_template() if template.handler == Props::Handler && [:layout] prepend_formats(template.format) render_props_template(context, template, [:layout], [:locals]) else super(context, ) end end |
#render_props_template(view, template, path, locals) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/props_template/layout_patch.rb', line 18 def render_props_template(view, template, path, locals) layout_locals = locals.dup layout_locals.delete(:json) layout = resolve_props_layout(path, layout_locals, [formats.first]) body = layout.render(view, layout_locals) do |json| locals[:json] = json template.render(view, locals) end build_rendered_template(body, template) end |
#resolve_props_layout(layout, keys, formats) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/props_template/layout_patch.rb', line 32 def resolve_props_layout(layout, keys, formats) details = @details.dup details[:formats] = formats case layout when String begin if layout.start_with?("/") ActiveSupport::Deprecation.warn "Rendering layouts from an absolute path is deprecated." @lookup_context.with_fallbacks.find_template(layout, nil, false, [], details) else @lookup_context.find_template(layout, nil, false, [], details) end end when Proc resolve_layout(layout.call(@lookup_context, formats), keys, formats) else layout end end |