Sha256: b2fe19037386d0fbeadadecad3f88ce560587c6e06d6d1290ce863c0d927e245

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

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"
    # }
    # ```
    # Or:
    # ```ruby
    # content_for(:page_title), "People"
    # ```
    class ContentFor < Container
      include Capabilities::Configurable
      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
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
express_admin-1.2.1 vendor/gems/express_templates/lib/express_templates/components/content_for.rb
express_admin-1.2.0 vendor/gems/express_templates/lib/express_templates/components/content_for.rb
express_templates-0.5.0 lib/express_templates/components/content_for.rb
express_templates-0.4.2 lib/express_templates/components/content_for.rb
express_templates-0.4.1 lib/express_templates/components/content_for.rb
express_templates-0.4.0 lib/express_templates/components/content_for.rb
express_templates-0.3.6 lib/express_templates/components/content_for.rb
express_templates-0.3.5 lib/express_templates/components/content_for.rb
express_templates-0.3.4 lib/express_templates/components/content_for.rb
express_templates-0.3.2 lib/express_templates/components/content_for.rb