Class: ExpressTemplates::Components::ContentFor
Overview
Provide a wrapper for the content_for helper which accepts a block of express template code.
Example:
“‘ruby content_for(:header)
h1 "Title"
“‘
Instance Attribute Summary
Attributes inherited from Expander
Instance Method Summary collapse
Methods included from ExpressTemplates::Components::Capabilities::Configurable
Methods included from ExpressTemplates::Components::Capabilities::Parenting
Methods inherited from Base
Methods included from ExpressTemplates::Components::Capabilities::Iterating
Methods included from ExpressTemplates::Components::Capabilities::Wrapping
Methods included from ExpressTemplates::Components::Capabilities::Rendering
Methods included from ExpressTemplates::Components::Capabilities::Templating
Methods included from Macro
Methods inherited from Expander
#expand, #initialize, #initialize_expander, #method_missing, #process_children!, register_macros_for
Constructor Details
This class inherits a constructor from ExpressTemplates::Expander
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ExpressTemplates::Expander
Instance Method Details
#compile ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/express_templates/components/content_for.rb', line 15 def compile children_markup = compile_children content_label = @args[0] result = %Q|\ncontent_for(:#{content_label}| if children_markup.empty? if @args[1].kind_of?(String) children_markup = @args[1] # append children as argument result << %Q|, "#{children_markup}".html_safe).to_s| else # no markup specified - must be referencing the content result << ").to_s" end else # append children in block form result << %Q|) { (#{children_markup.gsub(/^\s+/, '')}).html_safe }.to_s| end result end |