xhtml_report_generator 3.1.1 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/xhtml_report_generator/custom.rb +50 -45
- data/lib/xhtml_report_generator/version.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71becd9cbcd9bbc0470db37fbbe6c57c78983eb6
|
4
|
+
data.tar.gz: 2771bacf4522614f803f186280723810e2b9a224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae44b1c93a03773a5e76b3cceee8a6498a8ffb51ed26d6a64eff77d641cb312711fc80827e30d56c2764a4d643d9ca3c400ec268b37c9ed4c6c853d2474f3812
|
7
|
+
data.tar.gz: f47caa45144a60e750d7cff960051f92f5f18f97e4234982ac8ea9c6a035e751f5ff0e38c9dec0776a180750fcf3881f2b4377dec0eee540fdb256b284194c09
|
data/README.md
CHANGED
@@ -27,7 +27,12 @@ require 'xhtml_report_generator'
|
|
27
27
|
gen1 = XhtmlReportGenerator::Generator.new
|
28
28
|
gen1.create_layout("Title")
|
29
29
|
gen1.heading("h1", {"class" => "bothtoc"}) {"titel"}
|
30
|
-
gen1.
|
30
|
+
gen1.heading("h2") {"subtitel"}
|
31
|
+
gen1.heading("h3") {"section"}
|
32
|
+
gen1.content({"class"=>"bold"}) {"content function: Hallo welt <br /> html test <span class=\"r\" >red span test</span>"}
|
33
|
+
gen1.html("<p class=\"italic\">html function: Hallo welt <br /> html test <span class=\"r\" >red span test</span></p>")
|
34
|
+
gen1.highlight(/Ha.*lt/)
|
35
|
+
gen1.link("https://rubygems.org/gems/xhtml_report_generator/") {"download the gem"}
|
31
36
|
# browser will parse this as html (based on file extension)
|
32
37
|
gen1.write("myreport.html")
|
33
38
|
# browser will parse this as xhtml (based on file extension)
|
@@ -229,4 +234,3 @@ heading -> heading(tag_type="h1", attrs={}, &block)
|
|
229
234
|
headingTop -> heading\_top(tag_type="h1", attrs={}, &block)
|
230
235
|
|
231
236
|
</pre>
|
232
|
-
|
@@ -3,7 +3,7 @@ require 'base64'
|
|
3
3
|
# The module name doesn't matter, just make sure at the end to 'extend' it
|
4
4
|
# because it will be 'eval'ed by the initialize method of the XhtmlReportGenerator::Generator class.
|
5
5
|
module Custom
|
6
|
-
|
6
|
+
|
7
7
|
# creates the basic page layout and sets the current Element to the main content area (middle div)
|
8
8
|
# @example The middle div is matched by the following xPath
|
9
9
|
# //body/div[@id='middle']
|
@@ -12,21 +12,21 @@ module Custom
|
|
12
12
|
# 1 means only left toc, 2 means only right toc, and 3 means full layout with left and right toc.
|
13
13
|
def create_layout(title, layout=3)
|
14
14
|
raise "invalid layout selector, choose from 0..3" if (layout < 0) || (layout > 3)
|
15
|
-
|
15
|
+
|
16
16
|
@body = @document.elements["//body"]
|
17
17
|
# only add the layout if it is not already there
|
18
18
|
if !@layout
|
19
19
|
head = @body.add_element("div", {"class" => "head", "id" => "head"})
|
20
20
|
head.add_element("button", {"id" => "pre_toggle_linewrap"}).add_text("Toggle Linewrap")
|
21
|
-
|
21
|
+
|
22
22
|
if (layout & 0x1) != 0
|
23
23
|
div = @body.add_element("div", {"class" => "lefttoc split split-horizontal", "id" => "ltoc"})
|
24
24
|
div.add_text("Table of Contents")
|
25
25
|
div.add_element("br")
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
@div_middle = @body.add_element("div", {"class" => "middle split split-horizontal", "id" => "middle"})
|
29
|
-
|
29
|
+
|
30
30
|
if (layout & 0x2) != 0
|
31
31
|
div = @body.add_element("div", {"class" => "righttoc split split-horizontal", "id" => "rtoc"})
|
32
32
|
div.add_text("Quick Links")
|
@@ -34,14 +34,14 @@ module Custom
|
|
34
34
|
end
|
35
35
|
|
36
36
|
@body.add_element("p", {"class" => "#{layout}", "id" => "layout"}).add_text("this text should be hidden")
|
37
|
-
|
37
|
+
|
38
38
|
@layout = true
|
39
39
|
end
|
40
40
|
@current = @document.elements["//body/div[@id='middle']"]
|
41
41
|
set_title(title)
|
42
42
|
end
|
43
43
|
|
44
|
-
# sets the title of the document in the <head> section as well as in the layout header div
|
44
|
+
# sets the title of the document in the <head> section as well as in the layout header div
|
45
45
|
# create_layout must be called before!
|
46
46
|
# @param title [String] the text which will be insertead
|
47
47
|
def set_title(title)
|
@@ -69,7 +69,7 @@ module Custom
|
|
69
69
|
@current = xpath
|
70
70
|
elsif xpath.is_a?(String)
|
71
71
|
@current = @document.elements[xpath]
|
72
|
-
else
|
72
|
+
else
|
73
73
|
raise "xpath is neither a String nor a REXML::Element"
|
74
74
|
end
|
75
75
|
end
|
@@ -79,7 +79,7 @@ module Custom
|
|
79
79
|
def get_current()
|
80
80
|
return @current
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
# returns the plain text without any xml tags of the specified element and all its children
|
84
84
|
# @param el [REXML::Element] The element from which to fetch the text children. Defaults to @current
|
85
85
|
# @param recursive [Boolean] whether or not to recurse into the children of the given "el"
|
@@ -91,7 +91,7 @@ module Custom
|
|
91
91
|
out << child.value()
|
92
92
|
else
|
93
93
|
if recursive
|
94
|
-
out << get_element_text(child, true)
|
94
|
+
out << get_element_text(child, true)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
}
|
@@ -106,7 +106,7 @@ module Custom
|
|
106
106
|
f.write(elem, out)
|
107
107
|
return out
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
# @see #code
|
111
111
|
# Instead of adding content to the report, this method returns the produced html code as a string.
|
112
112
|
# This can be used to insert code into #custom_table (with the option data_is_xhtml: true)
|
@@ -119,10 +119,10 @@ module Custom
|
|
119
119
|
temp.add_text(text)
|
120
120
|
element_to_string(temp)
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
# Appends a <pre> node after the @current node
|
124
124
|
# @param attrs [Hash] attributes for the <pre> element. The following classes can be passed as attributes and are predefined with a different
|
125
|
-
# background for your convenience !{"class" => "code0"} (light-blue), !{"class" => "code1"} (red-brown),
|
125
|
+
# background for your convenience !{"class" => "code0"} (light-blue), !{"class" => "code1"} (red-brown),
|
126
126
|
# !{"class" => "code2"} (light-green), !{"class" => "code3"} (light-yellow). You may also specify your own background
|
127
127
|
# as follows: !{"style" => "background: #FF00FF;"}.
|
128
128
|
# @yieldreturn [String] the text to be added to the <pre> element
|
@@ -150,7 +150,7 @@ module Custom
|
|
150
150
|
temp.add_text(text)
|
151
151
|
element_to_string(temp)
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
# Appends a <p> node after the @current node
|
155
155
|
# @param attrs [Hash] attributes for the <p> element
|
156
156
|
# @yieldreturn [String] the text to be added to the <p> element
|
@@ -168,9 +168,9 @@ module Custom
|
|
168
168
|
|
169
169
|
# insert arbitrary xml code after the @current element in the content pane (div middle)
|
170
170
|
# @param text [String] valid xhtml code which is included into the document
|
171
|
-
# @return [REXML::Element] the Element which was just added
|
171
|
+
# @return [REXML::Element] the Element which was just added
|
172
172
|
def html(text)
|
173
|
-
# we need to create a new document with a pseudo root becaus having multiple nodes at top
|
173
|
+
# we need to create a new document with a pseudo root becaus having multiple nodes at top
|
174
174
|
# level is not valid xml
|
175
175
|
doc = REXML::Document.new("<root>"+text+"</root>")
|
176
176
|
# then we move all children of root to the actual div middle element and insert after current
|
@@ -180,7 +180,7 @@ module Custom
|
|
180
180
|
end
|
181
181
|
return @current
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
# @see #link
|
185
185
|
# Instead of adding content to the report, this method returns the produced html code as a string.
|
186
186
|
# This can be used to insert code into #custom_table (with the option data_is_xhtml: true)
|
@@ -194,13 +194,13 @@ module Custom
|
|
194
194
|
temp.add_text(text)
|
195
195
|
element_to_string(temp)
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
# Appends a <a href = > node after the @current nodes
|
199
199
|
# @param href [String] this is the
|
200
200
|
# @param attrs [Hash] attributes for the <a> element
|
201
201
|
# @yieldreturn [String] the text to be added to the <a> element
|
202
202
|
# @return [REXML::Element] the Element which was just added
|
203
|
-
def link(href, attrs={}, &block)
|
203
|
+
def link(href, attrs={}, &block)
|
204
204
|
temp = REXML::Element.new("a")
|
205
205
|
attrs.merge!({"href" => href})
|
206
206
|
temp.add_attributes(attrs)
|
@@ -211,7 +211,7 @@ module Custom
|
|
211
211
|
@current.add_text(text)
|
212
212
|
return @current
|
213
213
|
end
|
214
|
-
|
214
|
+
|
215
215
|
# @see #image
|
216
216
|
# Instead of adding content to the report, this method returns the produced html code as a string.
|
217
217
|
# This can be used to insert code into #custom_table (with the option data_is_xhtml: true)
|
@@ -227,7 +227,7 @@ module Custom
|
|
227
227
|
temp.add_attributes(attributes)
|
228
228
|
element_to_string(temp)
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
# @param path [String] absolute or relative path to the image that should be inserted into the report
|
232
232
|
# @param attributes [Hash] attributes for the <img> element, any valid html attributes can be specified
|
233
233
|
# you may specify attributes such "alt", "height", "width"
|
@@ -246,10 +246,10 @@ module Custom
|
|
246
246
|
@current = temp
|
247
247
|
return @current
|
248
248
|
end
|
249
|
-
|
249
|
+
|
250
250
|
# Scans all REXML::Text children of an REXML::Element for any occurrences of regex.
|
251
251
|
# The text will be matched as one, not line by line as you might think.
|
252
|
-
# If you want to write a regexp matching multiple lines keep in mind that the dot "." by default doesn't
|
252
|
+
# If you want to write a regexp matching multiple lines keep in mind that the dot "." by default doesn't
|
253
253
|
# match newline characters. Consider using the "m" option (e.g. /regex/m ) which makes dot match newlines
|
254
254
|
# or match newlines explicitly.
|
255
255
|
# highlight_captures then puts a <span> </span> tag around all captures of the regex
|
@@ -301,7 +301,7 @@ module Custom
|
|
301
301
|
|
302
302
|
# Scans all REXML::Text children of an REXML::Element for any occurrences of regex.
|
303
303
|
# The text will be matched as one, not line by line as you might think.
|
304
|
-
# If you want to write a regexp matching multiple lines keep in mind that the dot "." by default doesn't
|
304
|
+
# If you want to write a regexp matching multiple lines keep in mind that the dot "." by default doesn't
|
305
305
|
# match newline characters. Consider using the "m" option (e.g. /regex/m ) which makes dot match newlines
|
306
306
|
# or match newlines explicitly.
|
307
307
|
# highlight then puts a <span> </span> tag around all matches of regex
|
@@ -348,11 +348,11 @@ module Custom
|
|
348
348
|
end
|
349
349
|
|
350
350
|
# creates a html table from two dimensional array of the form Array [row] [col]
|
351
|
-
# @param table_data [Array<Array>] of the form Array [row] [col] containing all data, the '.to_s' method will be called on each element,
|
351
|
+
# @param table_data [Array<Array>] of the form Array [row] [col] containing all data, the '.to_s' method will be called on each element,
|
352
352
|
# @param headers [Number] either of 0, 1, 2, 3. Where 0 is no headers (<th>) at all, 1 is only the first row,
|
353
353
|
# 2 is only the first column and 3 is both, first row and first column as <th> elements. Every other number
|
354
354
|
# is equivalent to the bitwise AND of the two least significant bits with 1, 2 or 3
|
355
|
-
# @return [REXML::Element] the Element which was just added
|
355
|
+
# @return [REXML::Element] the Element which was just added
|
356
356
|
def table(table_data, headers=0, table_attrs={}, tr_attrs={}, th_attrs={}, td_attrs={})
|
357
357
|
opts = {
|
358
358
|
headers: headers,
|
@@ -364,9 +364,9 @@ module Custom
|
|
364
364
|
}
|
365
365
|
custom_table(table_data, opts)
|
366
366
|
end
|
367
|
-
|
367
|
+
|
368
368
|
# creates a html table from two dimensional array of the form Array [row] [col]
|
369
|
-
# @param table_data [Array<Array>] of the form Array [row] [col] containing all data, the '.to_s' method will be called on each element,
|
369
|
+
# @param table_data [Array<Array>] of the form Array [row] [col] containing all data, the '.to_s' method will be called on each element,
|
370
370
|
# @option opts [Number] :headers either of 0, 1, 2, 3. Where 0 is no headers (<th>) at all, 1 is only the first row,
|
371
371
|
# 2 is only the first column and 3 is both, first row and first column as <th> elements. Every other number
|
372
372
|
# is equivalent to the bitwise AND of the two least significant bits with 1, 2 or 3
|
@@ -376,19 +376,19 @@ module Custom
|
|
376
376
|
# @option opts [Hash] :th_attrs html attributes for the <th> tag
|
377
377
|
# @option opts [Hash] :tr_attrs html attributes for the <tr> tag
|
378
378
|
# @option opts [Hash] :td_attrs html attributes for the <td> tag
|
379
|
-
# @option opts [Array<Hash>] :special Array of hashes for custom attributes on specific cells (<td> only) of the table
|
379
|
+
# @option opts [Array<Hash>] :special Array of hashes for custom attributes on specific cells (<td> only) of the table
|
380
380
|
# @example Example of the :special attributes
|
381
381
|
# opts[:special] = [
|
382
382
|
# {
|
383
383
|
# col_title: 'rx_DroppedFrameCount', # string or regexp or nil # if neither title nor index are present, the condition is evaluated for all <td> cells
|
384
384
|
# col_index: 5..7, # Fixnum, Range or nil # index has precedence over title
|
385
385
|
# row_title: 'D_0_BE_iMix', # string or regexp or nil
|
386
|
-
# row_index: 6, # Fixnum, Range or nil
|
386
|
+
# row_index: 6, # Fixnum, Range or nil
|
387
387
|
# condition: Proc.new { |e| Integer(e) != 0 }, # a proc
|
388
388
|
# attributes: {"style" => "background-color: #DB7093;"},
|
389
389
|
# },
|
390
390
|
# ]
|
391
|
-
# @return [REXML::Element] the Element which was just added
|
391
|
+
# @return [REXML::Element] the Element which was just added
|
392
392
|
def custom_table(table_data, opts = {})
|
393
393
|
defaults = {
|
394
394
|
headers: 0,
|
@@ -400,7 +400,7 @@ module Custom
|
|
400
400
|
special: [],
|
401
401
|
}
|
402
402
|
o = defaults.merge(opts)
|
403
|
-
|
403
|
+
|
404
404
|
temp = REXML::Element.new("table")
|
405
405
|
temp.add_attributes(o[:table_attrs])
|
406
406
|
row_titles = table_data.collect{|row| row[0].to_s}
|
@@ -441,7 +441,7 @@ module Custom
|
|
441
441
|
elsif !h[:row_title].nil?
|
442
442
|
next if !row_titles[i].match(h[:row_title])
|
443
443
|
end
|
444
|
-
|
444
|
+
|
445
445
|
# here we are a candidate for special, so we check if we meet the condition
|
446
446
|
# puts h[:attributes].inspect
|
447
447
|
# puts "cell value row #{i} col #{j}: #{table_data[i][j]}"
|
@@ -460,28 +460,33 @@ module Custom
|
|
460
460
|
}
|
461
461
|
end
|
462
462
|
end
|
463
|
-
|
463
|
+
|
464
464
|
col = row.add_element("td", _td_attrs)
|
465
465
|
end
|
466
466
|
if o[:data_is_xhtml]
|
467
|
-
# we need to create a new document with a pseudo root because having multiple nodes at top
|
467
|
+
# we need to create a new document with a pseudo root because having multiple nodes at top
|
468
468
|
# level is not valid xml
|
469
469
|
doc = REXML::Document.new("<root>" + table_data[i][j].to_s + "</root>")
|
470
470
|
# then we move all children of root to the actual div middle element and insert after current
|
471
471
|
for elem in doc.root.to_a do
|
472
|
-
|
472
|
+
if elem.is_a?(REXML::Text)
|
473
|
+
# due to reasons unclear to me, text needs special treatment
|
474
|
+
col.add_text(elem)
|
475
|
+
else
|
476
|
+
col.add_element(elem) # add the td element
|
477
|
+
end
|
473
478
|
end
|
474
479
|
else
|
475
480
|
col.add_text(table_data[i][j].to_s)
|
476
481
|
end
|
477
|
-
end
|
478
|
-
end
|
482
|
+
end # for j in 0..table_data[i].length-1 do # column
|
483
|
+
end # for i in 0..table_data.length-1 do # row
|
479
484
|
|
480
485
|
@div_middle.insert_after(@current, temp)
|
481
486
|
@current = temp
|
482
487
|
return @current
|
483
488
|
end
|
484
|
-
|
489
|
+
|
485
490
|
|
486
491
|
# Appends a new heading element to body, and sets current to this new heading
|
487
492
|
# @param tag_type [String] specifiy "h1", "h2", "h3" for the heading, defaults to "h1"
|
@@ -512,8 +517,8 @@ module Custom
|
|
512
517
|
def heading_top(tag_type="h1", attrs={}, &block)
|
513
518
|
temp = REXML::Element.new(tag_type)
|
514
519
|
temp.add_attributes(attrs)
|
515
|
-
|
516
|
-
# check if there are any child elements
|
520
|
+
|
521
|
+
# check if there are any child elements
|
517
522
|
if @div_middle.has_elements?()
|
518
523
|
# insert before the first child of div middle
|
519
524
|
@div_middle.insert_before("//div[@id='middle']/*[1]", temp)
|
@@ -521,7 +526,7 @@ module Custom
|
|
521
526
|
# middle is empty, just insert the heading
|
522
527
|
@div_middle.insert_after(@current, temp)
|
523
528
|
end
|
524
|
-
|
529
|
+
|
525
530
|
@current = temp
|
526
531
|
raise "Block argument is mandatory" unless block_given?
|
527
532
|
text = encoding_fixer(block.call())
|
@@ -536,7 +541,7 @@ module Custom
|
|
536
541
|
# some arbitrary
|
537
542
|
# text child content
|
538
543
|
# </test>
|
539
|
-
# now we call replace_text_with_elements to place <span> around the word "arbitrary"
|
544
|
+
# now we call replace_text_with_elements to place <span> around the word "arbitrary"
|
540
545
|
# =>
|
541
546
|
# <test>
|
542
547
|
# some <span>arbitrary</span>
|
@@ -559,7 +564,7 @@ module Custom
|
|
559
564
|
# text = REXML::Text.new(element.value()[ last_end, j[0] - last_end ])
|
560
565
|
# parent.add_text(text)
|
561
566
|
# add text without creating a textnode, textnode screws up formatting (e.g. all whitespace are condensed into one)
|
562
|
-
parent.add_text( element.value()[ last_end, j[0] - last_end ] )
|
567
|
+
parent.add_text( element.value()[ last_end, j[0] - last_end ] )
|
563
568
|
end
|
564
569
|
#create the tag node with attributes and add the text to it
|
565
570
|
tag = parent.add_element(REXML::Element.new(tagname), attribs)
|
@@ -594,4 +599,4 @@ extend Custom
|
|
594
599
|
# include XhtmlReportGenerator::Custom
|
595
600
|
#
|
596
601
|
#end
|
597
|
-
#puts Test.new.header()
|
602
|
+
#puts Test.new.header()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xhtml_report_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.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:
|
11
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "The generator can be used to create html or xhtml files. It comes with
|
14
14
|
many utility functions.\n \nThe javascript to render the table of contents, the
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
53
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.
|
54
|
+
rubygems_version: 2.6.10
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: A simple html or xhtml generator or logger to create human readable reports
|