Sha256: edacb09151f6d44083f78934b97407526cfe4e38670c1be79f0124836f6664c7
Contents?: true
Size: 1.5 KB
Versions: 2
Compression:
Stored size: 1.5 KB
Contents
module Nineteen module Eighty module Two module Formats class HTMLTable def self.format text lines = Spectrum[text] t = File.read File.open File.join templates_dir, 'table.eruby' context = { title: text, blanks: blanks(lines.first), rows: lines.map { |l| row(l) }.join("\n") } Erubis::Eruby.new(t).evaluate(context).strip end def self.blanks lines t = File.read File.open File.join templates_dir, 'row.eruby' context = { cells: lines.map { |b| cell Span.new(0, 1) }.join } Erubis::Eruby.new(t).evaluate(context).strip end def self.cell span t = File.read File.open File.join templates_dir, 'cell.eruby' context = { style: span.type == 1 ? 'on' : 'off', } context[:colspan] = span.width if span.width > 1 Erubis::Eruby.new(t).evaluate(context).strip end def self.row list t = File.read File.open File.join templates_dir, 'row.eruby' context = { cells: Decorators::RunLengthEncoder.encode(list).map { |i| cell i }.join } Erubis::Eruby.new(t).evaluate(context).strip end def self.templates_dir File.join File.dirname(__FILE__),'..', 'templates', 'html', 'table' end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nineteen-eighty-two-0.1.2 | lib/nineteen/eighty/two/formatters/html_table_formatter.rb |
nineteen-eighty-two-0.1.1 | lib/nineteen/eighty/two/formatters/html_table_formatter.rb |