Module: ExpressTemplates::Components::Capabilities::Wrapping::ClassMethods
- Defined in:
- lib/express_templates/components/capabilities/wrapping.rb
Instance Method Summary collapse
- #_yield(*args) ⇒ Object
-
#wrap_with(fragment, dont_wrap_if: false) ⇒ Object
Enclose whatever the component would already generate inside the specified fragment wherever we encounter _yield.
- #wrapper_name(name = nil) ⇒ Object
Instance Method Details
#_yield(*args) ⇒ Object
75 76 77 |
# File 'lib/express_templates/components/capabilities/wrapping.rb', line 75 def _yield(*args) "{{_yield}}" end |
#wrap_with(fragment, dont_wrap_if: false) ⇒ Object
Enclose whatever the component would already generate inside the specified fragment wherever we encounter _yield
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/express_templates/components/capabilities/wrapping.rb', line 47 def wrap_with(fragment, dont_wrap_if: false ) wrapper_name(fragment) wrapper_src = _lookup(fragment).source inner_src = _lookup(:markup).source_body wrapped_src = wrapper_src.gsub!(/\W_yield\W/, inner_src) fragment_src = if dont_wrap_if %Q(-> { unless_block(Proc.from_source(#{dont_wrap_if.source.inspect}), alt: Proc.from_source(%q(-> {#{inner_src}}))) { #{Proc.from_source(wrapped_src).source_body} } }) else wrapped_src end _store :markup, Proc.from_source(fragment_src) end |
#wrapper_name(name = nil) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/express_templates/components/capabilities/wrapping.rb', line 67 def wrapper_name(name = nil) if name.nil? @wrapper_name || :markup else @wrapper_name = name end end |