Method: Custom#code

Defined in:
lib/xhtml_report_generator/custom.rb

#code(attrs = {}, &block) ⇒ REXML::Element

Appends a

 node after the @current node

Parameters:

  • attrs (Hash) (defaults to: {})

    attributes for the

     element. The following classes can be passed as attributes and are predefined with a different
    background for your convenience !{"class" => "code0"} (light-blue), !{"class" => "code1"} (red-brown),
    !{"class" => "code2"} (light-green), !{"class" => "code3"} (light-yellow). You may also specify your own background
    as follows: !{"style" => "background: #FF00FF;"}.

Yield Returns:

  • (String)

    the text to be added to the

     element

Returns:

  • (REXML::Element)

    the Element which was just added



130
131
132
133
134
135
136
137
138
139
# File 'lib/xhtml_report_generator/custom.rb', line 130

def code(attrs={}, &block)
  temp = REXML::Element.new("pre")
  temp.add_attributes(attrs)
  @div_middle.insert_after(@current, temp)
  @current = temp
  raise "Block argument is mandatory" unless block_given?
  text = encoding_fixer(block.call())
  @current.add_text(text)
  return @current
end