Class: ExpressTemplates::Components::ContentFor

Inherits:
Container show all
Includes:
ExpressTemplates::Components::Capabilities::Configurable
Defined in:
lib/express_templates/components/content_for.rb

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

#handlers, #locals, #stack

Instance Method Summary collapse

Methods included from ExpressTemplates::Components::Capabilities::Configurable

included

Methods included from ExpressTemplates::Components::Capabilities::Parenting

included

Methods inherited from Base

inherited

Methods included from ExpressTemplates::Components::Capabilities::Iterating

included

Methods included from ExpressTemplates::Components::Capabilities::Wrapping

included

Methods included from ExpressTemplates::Components::Capabilities::Rendering

included

Methods included from ExpressTemplates::Components::Capabilities::Templating

included

Methods included from Macro

included

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

#compileObject



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
   = @args[0]
  result = %Q|\ncontent_for(:#{}|
  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