Sha256: c904a8d0d6a4dcb3c32c8d60fb3d9cd7fcd9df60be87b9435baa04c5810b0911

Contents?: true

Size: 1014 Bytes

Versions: 4

Compression:

Stored size: 1014 Bytes

Contents

module ExpressTemplates
  module Components
    # Provide a wrapper for the content_for helper which
    # accepts a block of express template code.
    #
    # Example:
    #
    # ```ruby
    # content_for(:header) {
    #   h1 "Title"
    # }
    # ```
    class ContentFor < Container
      include Capabilities::Configurable
      def compile
        children_markup = compile_children
        content_label = @args[0]
        result = %Q|content_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)|
          else
            # no markup specified - must be referencing the content
            result << ")"
          end
        else
          # append children in block form
          result << %Q|) { (#{children_markup.gsub(/^\s+/, '')}).html_safe }|
        end
        %Q("\#\{#{result}\}")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
express_templates-0.3.0 lib/express_templates/components/content_for.rb
express_templates-0.2.7 lib/express_templates/components/content_for.rb
express_templates-0.2.6 lib/express_templates/components/content_for.rb
express_templates-0.2.5 lib/express_templates/components/content_for.rb