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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0a6519a54a39e28ff553a4c91ed323bc1ea26cb
4
- data.tar.gz: 2fc5bc899ed4347d5010b98224f9eb28d6895df8
3
+ metadata.gz: 41cf688387503bb0c1f49447b808e8bdec45b9c4
4
+ data.tar.gz: 10002b13a02821e187fc333fd0d500a3e5764f34
5
5
  SHA512:
6
- metadata.gz: c62b71197742c0b0e4d99890e7e695daaa4b22b3a91dc575c085fe4ab4309d731d3e03539e0995bc15201ebf90c75c925a3cd84f60cb0ff8e48fc67bb6c4d88a
7
- data.tar.gz: 11b95b6db274135ea696380bca9d0b35e939cca6182fcf368b1b10b56d91886d5fc30a3b5ab06c03c60676fff348d9a66b2fe3a04cde0603ad6a22a661b2965b
6
+ metadata.gz: 7cb62c5b99200c4c6960b4154de58251f5b4b407cf28f9c130d4752f6119c4193c0bba9017f80822225e4c165030b004f615e7c5faabde6cc507e143442b78be
7
+ data.tar.gz: 797ea713f1a703172a571ff977c1351dbe3a11911eec2c25f8b818ca9bd93c4cf57127c1cd6539ad05e160d167b16b8f1c8c23bc393e40203f5a17792972b1b2
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - 1.8.7
5
- - jruby-18mode
6
4
  - 2.0.0
5
+ - 2.1.0
7
6
  # - jruby-19mode
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
@@ -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
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Workbook
3
- VERSION = '0.4.5'
3
+ VERSION = '0.4.5.1'
4
4
  end
@@ -22,24 +22,7 @@ module Workbook
22
22
  doc.h2 {
23
23
  doc.text table.name
24
24
  }
25
- doc.table {
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Brouwers