module Triplet::DSL

Constants

TAGS
VOID_TAGS

Attributes

output_buffer[RW]

Public Instance Methods

render_triplet(triplet) click to toggle source
# File lib/triplet/dsl.rb, line 44
def render_triplet(triplet)
  if triplet.is_a?(String)
    triplet
  elsif triplet.is_a?(Array)
    # If the array size is 3 and the first object is a
    # symbol, it's likely a renderable triplet
    if triplet.length == 3 && triplet[0].is_a?(Symbol)
      tag, attrs, children = triplet

      content_tag(tag, attrs) do
        if children.is_a?(Array)
          safe_join(children.map { |c| render_triplet(c) }, "")
        else
          render_triplet(children)
        end
      end
    else
      safe_join(triplet.map { |c| render_triplet(c) }, "")
    end
  else
    triplet.to_s
  end
end

Private Instance Methods

capture(*args) { |*args| ... } click to toggle source

Override capture to support triplets

# File lib/triplet/dsl.rb, line 73
def capture(*args)
  value = nil
  buffer = with_output_buffer { value = yield(*args) }
  if (string = buffer.presence || value) && string.is_a?(String)
    ERB::Util.html_escape string
  elsif value.is_a?(Array) # This is the only change, adds triplet support
    render_triplet(value)
  end
end