xhtml_report_generator 0.0.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38ba586873ac2380d55080740068cfbd34564413
4
- data.tar.gz: 794724eeb48ba9c1815fb4087510d1b1d2197e1d
3
+ metadata.gz: ee7cef2f258529bb6cda36c4dc3f57099eed7cb6
4
+ data.tar.gz: 236b3246f37cf842901a2841d444094e557ecec7
5
5
  SHA512:
6
- metadata.gz: 67ab6ba2bf9fc04633b9ae0304ca80ae2731208b5d61892ffebc8ade79548bd9148ae5d5381589b7f29bf7fd6b9e4098863b6927ab9be33b9c41c5399d75e2c5
7
- data.tar.gz: a30a760b5de3eaf866b231ca06c3821a95188b8fb0c4fa0fffdd731f43ba91b922a6cf8ebf09eb5e1de122399e8b17fc91c8a3baae6ed1b85962a1340c109ccc
6
+ metadata.gz: 140ca1648b99672e2e184d3a17e1e6364c90f8c8e446aa71441f424746fea1408a3ac1652d8c1da2fa4ce136f28c2c4078bee0773de581f0b29987ff1e60517f
7
+ data.tar.gz: e11a1be493f829854522b8d8f9c577fcb3afbdf3883e4717ae4e0d4bfdcf48666b795d3c5f90170d06f68fab60e90ec003889441ad788007192c827972ac3c81
@@ -7,7 +7,8 @@ require 'rexml/document'
7
7
  module XhtmlReportGenerator
8
8
  class Generator
9
9
  attr_accessor :document
10
- # @param opts [Hash]
10
+ # @param opts [Hash] See the example for an explanation of the valid symbols
11
+ # @example Valid symbols for the opts Hash
11
12
  # :jquery if specified, path to a version of jquery, that will be inlined into the html header section
12
13
  # :toc if specified, path to a javascript.js.rb file that contains the magic to generate all
13
14
  # :css if specified, path to a css file that contains the markup rules for your generated reports
@@ -31,7 +32,7 @@ module XhtmlReportGenerator
31
32
  # all existing Generator classes
32
33
  instance_eval symbols[:custom_rb]
33
34
 
34
- @document = Generator.createXhtml("Title")
35
+ @document = Generator.createXhtmlDoc("Title")
35
36
  head = @document.elements["//head"]
36
37
  # insert the custom css, and javascript files
37
38
  style = head.add_element("style", {"type" => "text/css"})
@@ -47,7 +48,7 @@ module XhtmlReportGenerator
47
48
 
48
49
  # Creates a minimal valid xhtml document including header title and body elements
49
50
  # @param title [String] Title in the header section
50
- def self.createXhtml(title)
51
+ def self.createXhtmlDoc(title)
51
52
  header = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
52
53
  header += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
53
54
 
@@ -1,12 +1,14 @@
1
1
  # The module needs to be called 'Custom'
2
2
  module Custom
3
+
3
4
  #puts Module.nesting
4
- # css classes mapped to toc
5
- # creates the basic page layout and sets the current Element to
6
- # //body/div[@class='middle']
5
+
6
+ # creates the basic page layout and sets the current Element to the main content area (middle div)
7
+ # @example The middle div is matched by the following xPath
8
+ # //body/div[@class='middle']
7
9
  def createLayout
8
10
  @body = @document.elements["//body"]
9
-
11
+ # only add the layout if it is not already there
10
12
  if !@layout
11
13
  @body.add_element("div", {"class" => "head"})
12
14
  @body.add_element("div", {"class" => "lefttoc", "id" => "ltoc"})
@@ -23,44 +25,55 @@ module Custom
23
25
  div = @document.elements["//body/div[@class='head']"]
24
26
  div.text = title
25
27
  end
28
+
29
+ def getTitle()
30
+ pagetitle = @document.elements["//head/title"]
31
+ return pagetitle.text
32
+ end
26
33
 
27
- # set the current element the first element matched by the xpath expression
28
- def setPosition!(xpath)
34
+ # set the current element to the first element matched by the xpath expression.
35
+ # The current element is the one which was last added
36
+ def setCurrent!(xpath)
29
37
  @current = @document.elements[xpath]
30
38
  end
39
+
40
+ # returns the current xml element
41
+ def getCurrent()
42
+ return @current
43
+ end
31
44
 
32
- def code(text)
33
- pre = REXML::Element.new("pre")
34
- parent = @div_middle.insert_after(@current, pre)
35
- @current = pre
45
+ # Appends a <pre> node after the @current node
46
+ def code(text, attrs={})
47
+ temp = REXML::Element.new("pre")
48
+ temp.add_attributes(attrs)
49
+ @div_middle.insert_after(@current, temp)
50
+ @current = temp
36
51
  @current.add_text(text)
37
-
52
+ return @current
38
53
  end
39
-
54
+
55
+ # Appends a <p> node after the @current node
40
56
  def content(text, attrs={})
41
- @current = @div_middle.add_element("p", attrs)
57
+ temp = REXML::Element.new("p")
58
+ temp.add_attributes(attrs)
59
+ @div_middle.insert_after(@current, temp)
60
+ @current = temp
42
61
  @current.add_text(text)
43
62
  return @current
44
63
  end
45
64
 
46
- def html(text, attrs={})
47
- @current = @div_middle.add_element("p", attrs)
65
+ # insert arbitrary xml code after the @current element in the content pane (div middle)
66
+ def html(text)
48
67
  # we need to create a new document with a pseudo root
49
68
  doc = REXML::Document.new("<root>"+text+"</root>")
50
- # then we move all children of root to the actual <p> </p> element
69
+ # then we move all children of root to the actual div middle element and insert after current
51
70
  for i in doc.root.to_a do
52
- @current.add(i)
71
+ @div_middle.insert_after(@current, i)
72
+ @current = i
53
73
  end
54
74
  return @current
55
75
  end
56
76
 
57
- #TODO
58
- def contentAfter(locaiton, text)
59
- end
60
-
61
- #TODO
62
- def contentBefore(locaiton, text)
63
- end
64
77
 
65
78
  # puts a <span> </span> tag around all captures of the regex
66
79
  # NOTE: nested captures are not supported and don't make sense in this context!!
@@ -131,16 +144,31 @@ module Custom
131
144
  end # for i in arr do
132
145
  end
133
146
 
134
- # creates a table from csv data
135
- def table (table_data)
147
+ # creates a html table from two dimensional array of the form Array[row][col]
148
+ def table (table_data, table_attrs={}, tr_attrs={}, th_attrs={}, td_attrs={})
149
+ @current = @div_middle.add_element("table", table_attrs)
150
+
151
+ for i in 0..table_data.length-1 do
152
+ row = @current.add_element("tr", tr_attrs)
153
+ for j in 0..table_data[i].length-1 do
154
+ if j == 0
155
+ col = row.add_element("th", th_attrs)
156
+ col.add_text(table_data[i][j])
157
+ else
158
+ col = row.add_element("td", td_attrs)
159
+ col.add_text(table_data[i][j])
160
+ end
161
+ end
162
+ end
163
+
136
164
  end
137
165
 
138
- # Appends a new heading element to body
139
- # @param type [String] specifiy "h1", "h2", "h3" for the heading
166
+ # Appends a new heading element to body, and sets current to this new heading
140
167
  # @param text [String] the heading text
168
+ # @param type [String] specifiy "h1", "h2", "h3" for the heading
141
169
  # @param toc [symbol] one of :ltoc, :rtoc, :btoc depending on in which toc you want to display the heading
142
170
  # @return the added element
143
- def heading(type, text, toc=:ltoc)
171
+ def heading(text, type, toc=:ltoc)
144
172
  case toc
145
173
  when :rtoc
146
174
  opts = {"class" => "onlyrtoc"}
@@ -150,13 +178,16 @@ module Custom
150
178
  opts = {}
151
179
  end
152
180
 
153
- @current = @div_middle.add_element(type, opts)
181
+ temp = REXML::Element.new(type)
182
+ temp.add_attributes(opts)
183
+
184
+ @div_middle.insert_after(@current, temp)
185
+ @current = temp
154
186
  @current.text = text
155
-
156
187
  return @current
157
188
  end
158
189
 
159
- #
190
+
160
191
  # @param element [REXML::Element] the element in whose text tags will be added at the specified indices of @index_length_array
161
192
  # @param parent [REXML::Element] the parent to which @element should be attached after parsing
162
193
  # @param tagname [String] the tag that will be introduced as <tagname> at the indices specified
@@ -1,5 +1,5 @@
1
1
  module XhtmlReportGenerator
2
- VERSION = '0.0.2'
2
+ VERSION = '1.0.0'
3
3
  end
4
4
 
5
5
  puts XhtmlReportGenerator::VERSION
metadata CHANGED
@@ -1,25 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xhtml_report_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Widmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2014-12-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Here is an example usage:
15
- gen1 = XhtmlReportGenerator::Generator.new
16
- gen1.createLayout
17
- gen1.setTitle("Example Report")
18
- gen1.heading("h1", "titel", :btoc)
19
- gen1.heading("h2", "subtitel", :ltoc)
20
- gen1.heading("h3", "section")
21
- gen1.content("content function: Hallo welt <br /> html test <span class="r" >red span test</span>",{"class"=>"bold"})
22
- gen1.html("html function: Hallo welt <br /> html test <span class="r" >red span test</span>",{"class"=>"italic"})
15
+ @example Basic Testreport
16
+ gen1 = XhtmlReportGenerator::Generator.new
17
+ gen1.createLayout
18
+ gen1.setTitle("Example Report")
19
+ gen1.heading("titel", "h1", :btoc)
20
+ gen1.heading("subtitel", "h2", :ltoc)
21
+ gen1.heading("section", "h3")
22
+ gen1.content("content function: Hallo welt <br /> html test <span class="r" >red span test</span>", {"class"=>"bold"})
23
+ gen1.html("<p class="italic">html function: Hallo welt <br /> html test <span class="r" >red span test</span></p>")
23
24
 
24
25
  The javascript to render the table of contents, the custom generator functions and style sheet all can be
25
26
  supplied by your own, if needed.
@@ -61,3 +62,4 @@ signing_key:
61
62
  specification_version: 4
62
63
  summary: A simple and quick xhtml report generator
63
64
  test_files: []
65
+ has_rdoc: