workbook 0.4.5 → 0.4.5.1
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/.travis.yml +1 -2
- data/lib/workbook/book.rb +1 -1
- data/lib/workbook/table.rb +6 -0
- data/lib/workbook/version.rb +1 -1
- data/lib/workbook/writers/html_writer.rb +32 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41cf688387503bb0c1f49447b808e8bdec45b9c4
|
4
|
+
data.tar.gz: 10002b13a02821e187fc333fd0d500a3e5764f34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cb62c5b99200c4c6960b4154de58251f5b4b407cf28f9c130d4752f6119c4193c0bba9017f80822225e4c165030b004f615e7c5faabde6cc507e143442b78be
|
7
|
+
data.tar.gz: 797ea713f1a703172a571ff977c1351dbe3a11911eec2c25f8b818ca9bd93c4cf57127c1cd6539ad05e160d167b16b8f1c8c23bc393e40203f5a17792972b1b2
|
data/.travis.yml
CHANGED
data/lib/workbook/book.rb
CHANGED
@@ -117,7 +117,7 @@ module Workbook
|
|
117
117
|
#
|
118
118
|
# @param [String] filename a string with a reference to the file to be written to
|
119
119
|
# @param [Hash] options depends on the writer chosen by the file's filetype
|
120
|
-
def write filename, options
|
120
|
+
def write filename, options={}
|
121
121
|
extension = file_extension(filename)
|
122
122
|
send("write_to_#{extension}".to_sym, filename, options)
|
123
123
|
end
|
data/lib/workbook/table.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'workbook/modules/table_diff_sort'
|
3
3
|
require 'workbook/writers/csv_table_writer'
|
4
4
|
require 'workbook/writers/json_table_writer'
|
5
|
+
require 'workbook/writers/html_writer'
|
5
6
|
|
6
7
|
|
7
8
|
module Workbook
|
@@ -10,6 +11,8 @@ module Workbook
|
|
10
11
|
include Workbook::Modules::TableDiffSort
|
11
12
|
include Workbook::Writers::CsvTableWriter
|
12
13
|
include Workbook::Writers::JsonTableWriter
|
14
|
+
include Workbook::Writers::HtmlTableWriter
|
15
|
+
|
13
16
|
attr_accessor :sheet
|
14
17
|
attr_accessor :name
|
15
18
|
|
@@ -59,6 +62,9 @@ module Workbook
|
|
59
62
|
r
|
60
63
|
end
|
61
64
|
|
65
|
+
# Removes all empty lines. This function is particularly useful if you typically add lines to the end of a template-table, which sometimes has unremovable empty lines.
|
66
|
+
#
|
67
|
+
# @return [Workbook::Table] self
|
62
68
|
def remove_empty_lines!
|
63
69
|
self.delete_if{|r| r.nil? or r.compact.empty?}
|
64
70
|
self
|
data/lib/workbook/version.rb
CHANGED
@@ -22,24 +22,7 @@ module Workbook
|
|
22
22
|
doc.h2 {
|
23
23
|
doc.text table.name
|
24
24
|
}
|
25
|
-
doc.
|
26
|
-
table.each{|row|
|
27
|
-
doc.tr {
|
28
|
-
row.each {|cell|
|
29
|
-
classnames = cell.format.all_names.join(" ").strip
|
30
|
-
td_options = classnames != "" ? {:class=>classnames} : {}
|
31
|
-
td_options = td_options.merge({:style=>cell.format.to_css}) if options[:style_with_inline_css] and cell.format.to_css != ""
|
32
|
-
td_options = td_options.merge({:colspan=>cell.colspan}) if cell.colspan
|
33
|
-
td_options = td_options.merge({:rowspan=>cell.rowspan}) if cell.rowspan
|
34
|
-
unless cell.value.class == Workbook::NilValue
|
35
|
-
doc.td(td_options) {
|
36
|
-
doc.text cell.value
|
37
|
-
}
|
38
|
-
end
|
39
|
-
}
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
25
|
+
doc << table.to_html(options)
|
43
26
|
}
|
44
27
|
}
|
45
28
|
}
|
@@ -48,8 +31,6 @@ module Workbook
|
|
48
31
|
return builder.doc.to_xhtml
|
49
32
|
end
|
50
33
|
|
51
|
-
|
52
|
-
|
53
34
|
# Write the current workbook to HTML format
|
54
35
|
#
|
55
36
|
# @param [String] filename
|
@@ -61,5 +42,36 @@ module Workbook
|
|
61
42
|
return filename
|
62
43
|
end
|
63
44
|
end
|
45
|
+
|
46
|
+
module HtmlTableWriter
|
47
|
+
# Generates an HTML table ()
|
48
|
+
#
|
49
|
+
# @param [Hash] options A hash with options
|
50
|
+
# @return [String] A String containing the HTML code
|
51
|
+
def to_html options={}
|
52
|
+
options = {:style_with_inline_css=>false}.merge(options)
|
53
|
+
builder = Nokogiri::XML::Builder.new do |doc|
|
54
|
+
doc.table {
|
55
|
+
self.each{|row|
|
56
|
+
doc.tr {
|
57
|
+
row.each {|cell|
|
58
|
+
classnames = cell.format.all_names.join(" ").strip
|
59
|
+
td_options = classnames != "" ? {:class=>classnames} : {}
|
60
|
+
td_options = td_options.merge({:style=>cell.format.to_css}) if options[:style_with_inline_css] and cell.format.to_css != ""
|
61
|
+
td_options = td_options.merge({:colspan=>cell.colspan}) if cell.colspan
|
62
|
+
td_options = td_options.merge({:rowspan=>cell.rowspan}) if cell.rowspan
|
63
|
+
unless cell.value.class == Workbook::NilValue
|
64
|
+
doc.td(td_options) {
|
65
|
+
doc.text cell.value
|
66
|
+
}
|
67
|
+
end
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
end
|
73
|
+
return builder.doc.to_xhtml
|
74
|
+
end
|
75
|
+
end
|
64
76
|
end
|
65
77
|
end
|