module EL::ContentHelpers
Public Instance Methods
capture_html(&proc)
click to toggle source
execute given content block and return the result. useful when you need to display same snippet multiple times and want it rendered only once
@example
assets = capture_html do js_tag(:jquery) + css_tag(:ui) end
# File lib/el/content_helpers.rb, line 52 def capture_html &proc proc.call end
content_for(key, &proc)
click to toggle source
capture content and then render it into a different place
@example
content_for :assets do js_tag :jquery end p content_for?(:assets) #=> #<Proc:0x00... yield_content :assets #=> '<script src="jquery.js" type="text/javascript"></script>'
@example
content_for :account do |name, email| form_tag! do input_tag(value: name) + input_tag(value: email) end end yield_content :account, :foo, 'foo@bar.com' #=> '<form><input value="foo"><input value="foo@bar.com"></form>'
# File lib/el/content_helpers.rb, line 28 def content_for key, &proc (@__el__content_for ||= {})[key] = proc end
content_for?(key)
click to toggle source
check whether content block exists for some key
# File lib/el/content_helpers.rb, line 33 def content_for? key (@__el__content_for || {})[key] end
yield_content(key, *args)
click to toggle source
render a content block captured by ‘content_for`
# File lib/el/content_helpers.rb, line 38 def yield_content key, *args (proc = content_for?(key)) && proc.call(*args) end