Module: Slotify::Extensions::PartialRenderer
- Defined in:
- lib/slotify/extensions/partial_renderer.rb
Instance Method Summary collapse
- #decorate_strict_slots_errors ⇒ Object
- #missing_strict_locals_error?(error) ⇒ Boolean
- #render_partial_template(view, locals, template, layout, block) ⇒ Object
Instance Method Details
#decorate_strict_slots_errors ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/slotify/extensions/partial_renderer.rb', line 20 def decorate_strict_slots_errors yield rescue ActionView::Template::Error => error if missing_strict_locals_error?(error) local_names = error.cause..scan(/\s:(\w+)/).flatten if local_names.any? slot_names = local_names.intersection(error.template.strict_slots_keys).map { ":#{_1}" } if slot_names.any? = "missing #{"slot".pluralize(slot_names.size)}: #{slot_names.join(", ")} for #{error.template.short_identifier}" raise Slotify::StrictSlotsError, end end end raise error end |
#missing_strict_locals_error?(error) ⇒ Boolean
36 37 38 39 |
# File 'lib/slotify/extensions/partial_renderer.rb', line 36 def missing_strict_locals_error?(error) error.template && defined?(ActionView::StrictLocalsError) && error.cause.is_a?(ActionView::StrictLocalsError) || (error.cause.is_a?(ArgumentError) && error.cause..match(/missing local/)) end |
#render_partial_template(view, locals, template, layout, block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/slotify/extensions/partial_renderer.rb', line 4 def render_partial_template(view, locals, template, layout, block) return super unless template.strict_slots? view.slotify = Slotify::Slots.new(view, template.strict_slots_keys) view.capture_with_outer_slotify_access(&block) if block locals = locals.merge(view.slotify.slot_locals) decorate_strict_slots_errors do super(view, locals, template, layout, block) end ensure view.slotify = view.slotify.outer_slotify if view.slotify end |