Module: EL::ContentHelpers
- Included in:
- E
- Defined in:
- lib/el/content_helpers.rb
Instance Method Summary collapse
-
#capture_html(&proc) ⇒ Object
execute given content block and return the result.
-
#content_for(key, &proc) ⇒ Object
capture content and then render it into a different place.
-
#content_for?(key) ⇒ Boolean
check whether content block exists for some key.
-
#yield_content(key, *args) ⇒ Object
render a content block captured by ‘content_for`.
Instance Method Details
#capture_html(&proc) ⇒ Object
execute given content block and return the result. useful when you need to display same snippet multiple times and want it rendered only once
52 53 54 |
# File 'lib/el/content_helpers.rb', line 52 def capture_html &proc proc.call end |
#content_for(key, &proc) ⇒ Object
capture content and then render it into a different place
28 29 30 |
# File 'lib/el/content_helpers.rb', line 28 def content_for key, &proc (@__el__content_for ||= {})[key] = proc end |
#content_for?(key) ⇒ Boolean
check whether content block exists for some key
33 34 35 |
# File 'lib/el/content_helpers.rb', line 33 def content_for? key (@__el__content_for || {})[key] end |
#yield_content(key, *args) ⇒ Object
render a content block captured by ‘content_for`
38 39 40 |
# File 'lib/el/content_helpers.rb', line 38 def yield_content key, *args (proc = content_for?(key)) && proc.call(*args) end |