class Cucumber::Formatter::HtmlBuilder

Constants

VALID_EMBED_TYPES

Public Instance Methods

build_document!() click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 27
def build_document!
  declare! # <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

  self << '<html xmlns ="http://www.w3.org/1999/xhtml">'

  set_head_tags
end
declare!() click to toggle source
Calls superclass method
# File lib/cucumber/formatter/html_builder.rb, line 23
def declare!
  super(:DOCTYPE, :html, :PUBLIC, '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd')
end
embed(type: nil, src: nil, label: nil, id: nil) click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 19
def embed(type: nil, src: nil, label: nil, id: nil)
  prepend_to_span('embed', string_to_embed(type: type, src: src, label: label, id: id))
end
format_features!(features) click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 35
def format_features!(features)
  step_count = features && features.step_count || 0

  self << '<body>'
  self << "<!-- Step count #{step_count}-->"
  self << '<div class="cucumber">'

  div(id: 'cucumber-header') do
    div(id: 'label') do
      h1 'Cucumber Features'
    end

    summary_div
  end
end

Private Instance Methods

expand_collapse() click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 74
def expand_collapse
  div(id: 'expand-collapse') do
    p('Expand All', id: 'expander')
    p('Collapse All', id: 'collapser')
  end
end
inline_css() click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 87
def inline_css
  style(type: 'text/css') do
    pn = ::Pathname.new(::File.dirname(__FILE__) + '/cucumber.css')
    self << pn.read
  end
end
inline_jquery() click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 101
def inline_jquery
  pn = ::Pathname.new(::File.dirname(__FILE__) + '/jquery-min.js')
  pn.read
end
inline_js() click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 94
def inline_js
  script(type: 'text/javascript') do
    self << inline_jquery
    self << inline_js_content
  end
end
inline_js_content() click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 106
def inline_js_content # rubocop:disable
  pn = ::Pathname.new(::File.dirname(__FILE__) + '/inline-js.js')
  pn.read
end
prepend_to_span(span_class, content) click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 81
def prepend_to_span(span_class, content)
  span(class: span_class) do |pre|
    pre << content
  end
end
set_head_tags() click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 111
def set_head_tags
  head do
    meta('http-equiv' => 'Content-Type', :content => 'text/html;charset=utf-8')
    title 'Cucumber'
    inline_css
    inline_js
  end
end
string_to_embed(type: nil, src: nil, label: nil, id: nil) click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 53
def string_to_embed(type: nil, src: nil, label: nil, id: nil)
  raise ::ArgumentError, 'missing required argument' unless type && src && label && id # for Ruby 2.0 compatibility
  raise InvalidEmbedTypeError unless VALID_EMBED_TYPES.include?(type)

  if type == :image
    %{<a href="" onclick="img=document.getElementById('#{id}'); img.style.display = (img.style.display == 'none' ? 'block' : 'none');return false">#{label}</a><br>&nbsp;
    <img id="#{id}" style="display: none" src="#{src}"/>}
  else
    %{<a id="#{id}" href="#{src}" title="#{label}">#{label}</a>}
  end
end
summary_div() click to toggle source
# File lib/cucumber/formatter/html_builder.rb, line 65
def summary_div
  div(id: 'summary') do
    p('', id: 'totals')
    p('', id: 'duration')

    expand_collapse
  end
end