xhtml_report_generator 1.0.1 → 1.0.2
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 +4 -4
- data/lib/xhtml_report_generator.rb +13 -2
- data/lib/xhtml_report_generator/custom.rb +42 -7
- data/lib/xhtml_report_generator/version.rb +2 -2
- metadata +13 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a56e14ff278000689e7206f3460278519a0f71d5
|
4
|
+
data.tar.gz: 4b8f3ab22cc07c789e38649fbab38e59554fa303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 309ea3a329355afce991bda4007b957df24fd48793c3451067b9210510c7bdd4de7a35f8302cac2b3d153b35626c3624c574f7b36d04298c046808b6909933b2
|
7
|
+
data.tar.gz: 9845ac4ffd8ebb70e244d039cb8dc54ee6712e7801b25cec58964971e2c7609548483df22d4b2b022bf0b1040172694b6e756b7355a4c844af82c66bde231295
|
@@ -5,6 +5,9 @@
|
|
5
5
|
require 'rexml/document'
|
6
6
|
|
7
7
|
module XhtmlReportGenerator
|
8
|
+
|
9
|
+
# This is the main generator class. It can be instanced with custom javascript, css, and ruby files to allow
|
10
|
+
# generation of arbitrary reports.
|
8
11
|
class Generator
|
9
12
|
attr_accessor :document
|
10
13
|
# @param opts [Hash] See the example for an explanation of the valid symbols
|
@@ -62,13 +65,21 @@ module XhtmlReportGenerator
|
|
62
65
|
return doc
|
63
66
|
end
|
64
67
|
|
68
|
+
# returns the string representation of the xml document
|
69
|
+
# @param indent [Number] indent for child elements. defaults to 0.
|
65
70
|
def to_s(indent = 0)
|
66
71
|
output = ""
|
67
72
|
# note transitive is needed to preserve newlines in <pre> tags
|
68
|
-
|
73
|
+
# note2: the hash options syntax is supported only from ruby version >= 2.0.0 we need the old style
|
74
|
+
# for compatibility with 1.9.3
|
75
|
+
#@document.write({:output=>output, :indent=>indent, :transitive=>true})
|
76
|
+
@document.write(output, indent, true)
|
69
77
|
return output
|
70
78
|
end
|
71
|
-
|
79
|
+
|
80
|
+
# saves the xml document as a file
|
81
|
+
# @param file [String] absolute or relative path to the file to which will be written.
|
82
|
+
# @param mode [String] defaults to 'w', one of the file open modes that allows writing ['r+','w','w+','a','a+']
|
72
83
|
def writeToFile(file, mode='w')
|
73
84
|
File.open(file, "#{mode}:UTF-8") {|f| f.write(self.to_s)}
|
74
85
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# The module
|
1
|
+
# The module name doesn't matter, just make sure at the end to 'extend' it
|
2
|
+
# because it will be 'eval'ed by the initialize method of the XhtmlReportGenerator::Generator class.
|
2
3
|
module Custom
|
3
|
-
|
4
|
-
#puts Module.nesting
|
4
|
+
|
5
5
|
# creates the basic page layout and sets the current Element to the main content area (middle div)
|
6
6
|
# @example The middle div is matched by the following xPath
|
7
7
|
# //body/div[@class='middle']
|
@@ -18,22 +18,33 @@ module Custom
|
|
18
18
|
@current = @document.elements["//body/div[@class='middle']"]
|
19
19
|
end
|
20
20
|
|
21
|
+
# sets the title of the document in the header section as well as in the layout.
|
22
|
+
# createLayout must be called before!
|
21
23
|
def setTitle(title)
|
24
|
+
if !@layout
|
25
|
+
raise "call createLayout first"
|
26
|
+
end
|
22
27
|
pagetitle = @document.elements["//head/title"]
|
23
28
|
pagetitle.text = title
|
24
29
|
div = @document.elements["//body/div[@class='head']"]
|
25
30
|
div.text = title
|
26
31
|
end
|
27
32
|
|
33
|
+
# returns the title text of the report
|
28
34
|
def getTitle()
|
29
35
|
pagetitle = @document.elements["//head/title"]
|
30
36
|
return pagetitle.text
|
31
37
|
end
|
32
38
|
|
33
|
-
# set the current element to the first element matched by the xpath expression.
|
34
|
-
# The current element is the one which
|
39
|
+
# set the current element to the element or first element matched by the xpath expression.
|
40
|
+
# The current element is the one which can be modified through highlighting.
|
41
|
+
# @param xpath [REXML::Element|String] the element or a string
|
35
42
|
def setCurrent!(xpath)
|
36
|
-
|
43
|
+
if xpath.is_a?(REXML::Element)
|
44
|
+
@current = xpath
|
45
|
+
else
|
46
|
+
@current = @document.elements[xpath]
|
47
|
+
end
|
37
48
|
end
|
38
49
|
|
39
50
|
# returns the current xml element
|
@@ -173,7 +184,7 @@ module Custom
|
|
173
184
|
# @param type [String] specifiy "h1", "h2", "h3" for the heading
|
174
185
|
# @param toc [symbol] one of :ltoc, :rtoc, :btoc depending on in which toc you want to display the heading
|
175
186
|
# @return the added element
|
176
|
-
def heading(text, type, toc=:ltoc)
|
187
|
+
def heading(text, type="h1", toc=:ltoc)
|
177
188
|
case toc
|
178
189
|
when :rtoc
|
179
190
|
opts = {"class" => "onlyrtoc"}
|
@@ -191,6 +202,30 @@ module Custom
|
|
191
202
|
@current.text = text
|
192
203
|
return @current
|
193
204
|
end
|
205
|
+
|
206
|
+
# Inserts a new heading element at the very beginning of the middle div section, and points @current to this heading
|
207
|
+
# @param text [String] the heading text
|
208
|
+
# @param type [String] specifiy "h1", "h2", "h3" for the heading
|
209
|
+
# @param toc [symbol] one of :ltoc, :rtoc, :btoc depending on in which toc you want to display the heading
|
210
|
+
# @return the added element
|
211
|
+
def headingTop(text, type="h1", toc=:ltoc)
|
212
|
+
case toc
|
213
|
+
when :rtoc
|
214
|
+
opts = {"class" => "onlyrtoc"}
|
215
|
+
when :btoc
|
216
|
+
opts = {"class" => "bothtoc"}
|
217
|
+
else
|
218
|
+
opts = {}
|
219
|
+
end
|
220
|
+
|
221
|
+
temp = REXML::Element.new(type)
|
222
|
+
temp.add_attributes(opts)
|
223
|
+
# insert before the first child of div middle
|
224
|
+
@div_middle.insert_before("//div[@class='middle']/*[1]", temp)
|
225
|
+
@current = temp
|
226
|
+
@current.text = text
|
227
|
+
return @current
|
228
|
+
end
|
194
229
|
|
195
230
|
# @param element [REXML::Element] the element in whose text tags will be added at the specified indices of @index_length_array
|
196
231
|
# @param parent [REXML::Element] the parent to which @element should be attached after parsing
|
metadata
CHANGED
@@ -1,29 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xhtml_report_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
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-
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
Here is an example usage
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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>")
|
24
|
-
|
25
|
-
The javascript to render the table of contents, the custom generator functions and style sheet all can be
|
26
|
-
supplied by your own, if needed.
|
13
|
+
description: "The generator can be used to create xhtml files. It comes with some
|
14
|
+
default utility functions.\n== Here is an example usage\n gen1 = XhtmlReportGenerator::Generator.new\n
|
15
|
+
\ gen1.createLayout\n gen1.setTitle(\"Example Report\")\n gen1.heading(\"titel\",
|
16
|
+
\"h1\", :btoc)\n gen1.heading(\"subtitel\", \"h2\", :ltoc)\n gen1.heading(\"section\",
|
17
|
+
\"h3\")\n gen1.content(\"content function: Hallo welt <br /> html test <span class=\"r\"
|
18
|
+
>red span test</span>\", {\"class\"=>\"bold\"})\n gen1.html(\"<p class=\"italic\">html
|
19
|
+
function: Hallo welt <br /> html test <span class=\"r\" >red span test</span></p>\")\n\nThe
|
20
|
+
javascript to render the table of contents, the custom generator functions and style
|
21
|
+
sheet all can be\nsupplied by your own, if necessary. \n"
|
27
22
|
email: m-widmer@gmx.ch
|
28
23
|
executables: []
|
29
24
|
extensions: []
|
@@ -37,7 +32,7 @@ files:
|
|
37
32
|
- lib/xhtml_report_generator/style_template.css
|
38
33
|
- lib/xhtml_report_generator/toc.js
|
39
34
|
- lib/xhtml_report_generator/version.rb
|
40
|
-
homepage:
|
35
|
+
homepage: https://rubygems.org/gems/xhtml_report_generator
|
41
36
|
licenses:
|
42
37
|
- MIT
|
43
38
|
metadata: {}
|
@@ -49,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
44
|
requirements:
|
50
45
|
- - '>='
|
51
46
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
47
|
+
version: 1.8.7
|
53
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
49
|
requirements:
|
55
50
|
- - '>='
|