xhtml_report_generator 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ require 'base64'
1
2
  # The module name doesn't matter, just make sure at the end to 'extend' it
2
3
  # because it will be 'eval'ed by the initialize method of the XhtmlReportGenerator::Generator class.
3
4
  module Custom
@@ -118,6 +119,25 @@ module Custom
118
119
  return @current
119
120
  end
120
121
 
122
+ # @param path [String] absolute or relative path to the image that should be inserted into the report
123
+ # @param attrs [Hash] attributes for the <img> element, any valid html attributes can be specified
124
+ # you may specify attributes such "alt", "height", "width"
125
+ # @option attrs [String] "class" by default every heading is added to the left table of contents (toc)
126
+ def image(path, attributes = {})
127
+ # read image as binary and do a base64 encoding
128
+ binary_data = Base64.strict_encode64(IO.binread(path))
129
+ type = File.extname(path).gsub('.', '')
130
+ # create the element
131
+ temp = REXML::Element.new("img")
132
+ # add the picture
133
+ temp.add_attribute("src","data:image/#{type};base64,#{binary_data}")
134
+ temp.add_attributes(attributes)
135
+
136
+ @div_middle.insert_after(@current, temp)
137
+ @current = temp
138
+ return @current
139
+ end
140
+
121
141
  # Scans all REXML::Text children of an REXML::Element for any occurrences of regex.
122
142
  # The text will be matched as one, not line by line as you might think.
123
143
  # If you want to write a regexp matching multiple lines keep in mind that the dot "." by default doesn't
@@ -1,5 +1,5 @@
1
1
  module XhtmlReportGenerator
2
- VERSION = '2.0.3'
2
+ VERSION = '2.1.0'
3
3
  end
4
4
 
5
5
  # puts XhtmlReportGenerator::VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xhtml_report_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-28 00:00:00.000000000 Z
12
+ date: 2015-10-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "The generator can be used to create xhtml files. It comes with some
15
15
  default utility functions.\n== Here is an example usage\n gen1 = XhtmlReportGenerator::Generator.new\n
@@ -47,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - ! '>='
49
49
  - !ruby/object:Gem::Version
50
- version: 1.8.7
50
+ version: 1.9.3
51
51
  required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements: