module Piggly::Reporter::HtmlDsl

Markup DSL

Constants

HTML_PATTERN
HTML_REPLACE

Public Instance Methods

e(string) click to toggle source
# File lib/piggly/reporter/html_dsl.rb, line 48
def e(string)
  string.fast_xs
end
html(output = "") { || ... } click to toggle source
# File lib/piggly/reporter/html_dsl.rb, line 13
def html(output = "")
  begin
    @htmltag_output, htmltag_output = output, @htmltag_output
    # @todo: doctype
    yield
  ensure
    # restore
    @htmltag_output = htmltag_output
  end
end
tag(name, content = nil, attributes = {}) { || ... } click to toggle source
# File lib/piggly/reporter/html_dsl.rb, line 24
def tag(name, content = nil, attributes = {})
  if content.is_a?(Hash) and attributes.empty?
    content, attributes = nil, content
  end

  attributes = attributes.inject("") do |string, pair|
    k, v = pair
    string << %[ #{k}="#{v}"]
  end

  if content.nil?
    if block_given?
      @htmltag_output << "<#{name}#{attributes}>"
      yield
      @htmltag_output << "</#{name}>"
    else
      @htmltag_output << "<#{name}#{attributes}/>"
    end
  else
    @htmltag_output << "<#{name}#{attributes}>#{content.to_s}</#{name}>"
  end
end