Module: Workbook::Writers::HtmlTableWriter
- Included in:
- Table
- Defined in:
- lib/workbook/writers/html_writer.rb
Instance Method Summary collapse
- #build_cell_options(cell, options = {}) ⇒ Object
-
#to_html(options = {}) ⇒ String
Generates an HTML table ().
Instance Method Details
#build_cell_options(cell, options = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/workbook/writers/html_writer.rb', line 92 def cell, ={} classnames = cell.format.all_names classnames = classnames + [:classnames] if [:classnames] classnames = classnames.join(" ").strip = classnames != "" ? {:class=>classnames} : {} if [:data] [:data].each do |key, value| = .merge({("data-#{key}".to_sym) => value}) end end = .merge({:style=>cell.format.to_css}) if [:style_with_inline_css] and cell.format.to_css != "" = .merge({:colspan=>cell.colspan}) if cell.colspan = .merge({:rowspan=>cell.rowspan}) if cell.rowspan return end |
#to_html(options = {}) ⇒ String
Generates an HTML table ()
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/workbook/writers/html_writer.rb', line 53 def to_html ={} = {:style_with_inline_css=>false}.merge() builder = Nokogiri::XML::Builder.new do |doc| doc.table do doc.thead do if header doc.tr do header.each do |cell| = cell, .merge(classnames: [cell.to_sym], data: {key: cell.to_sym}) unless cell.value.class == Workbook::NilValue doc.th() do doc.text cell.value end end end end end end doc.tbody do self.each do |row| unless row.header? doc.tr do row.each do |cell| = cell, unless cell.value.class == Workbook::NilValue doc.td() do doc.text cell.value end end end end end end end end end return builder.doc.to_xhtml end |