tablesmith 0.3.1 → 0.4.0
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/.rubocop.yml +7 -1
- data/lib/tablesmith.rb +1 -0
- data/lib/tablesmith/html_formatter.rb +63 -0
- data/lib/tablesmith/table.rb +8 -0
- data/lib/tablesmith/version.rb +1 -1
- data/spec/table_spec.rb +23 -0
- metadata +3 -3
- data/Gemfile.lock +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96ab0a18c776e80aa103908884db53eb98cf7a89
|
4
|
+
data.tar.gz: a645ccf65e779cd8b5311b7bd6429d3a48ea752d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e1d90632da2e260c393346d9a4a230dc747bdf1820ab3a95243efd612ad14f6578ba0ae6062300d1685f3dc811617d5c65eaa0e93caca67c37ad7739570985f
|
7
|
+
data.tar.gz: 5162cfc4edc75df6c4019333a87ecd3b867f57f923b9b13cd96b7c6952880cd4202c01cce5a2e145e697eaaec5e3a94c9e31aa5f49ab774dcac8bd64149e781d
|
data/.rubocop.yml
CHANGED
data/lib/tablesmith.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class HtmlFormatter
|
4
|
+
attr_reader :indent
|
5
|
+
|
6
|
+
def initialize(table)
|
7
|
+
@table = table
|
8
|
+
@indent = ' '
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_html
|
12
|
+
@lines = []
|
13
|
+
@lines << '<table>'
|
14
|
+
append_table_head
|
15
|
+
append_table_body
|
16
|
+
@lines << '</table>'
|
17
|
+
@lines.join("\n") + "\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def append_table_head
|
23
|
+
@lines << "#{indent}<thead>"
|
24
|
+
@lines << "#{indent}<tr>"
|
25
|
+
unless @table.empty?
|
26
|
+
rows = @table.text_table.rows[0..0]
|
27
|
+
append_rows(rows, 'th')
|
28
|
+
end
|
29
|
+
@lines << "#{indent}</tr>"
|
30
|
+
@lines << "#{indent}</thead>"
|
31
|
+
end
|
32
|
+
|
33
|
+
def append_table_body
|
34
|
+
@lines << "#{indent}<tbody>"
|
35
|
+
@lines << "#{indent}<tr>"
|
36
|
+
|
37
|
+
unless @table.empty?
|
38
|
+
rows = @table.text_table.rows[2..-1]
|
39
|
+
append_rows(rows, 'td')
|
40
|
+
end
|
41
|
+
@lines << "#{indent}</tr>"
|
42
|
+
@lines << "#{indent}</tbody>"
|
43
|
+
end
|
44
|
+
|
45
|
+
def append_rows(rows, tag)
|
46
|
+
rows.each do |row|
|
47
|
+
next if row == :separator
|
48
|
+
row.map do |cell|
|
49
|
+
value = cell_value(cell)
|
50
|
+
@lines << "#{indent}#{indent}<#{tag}>#{value}</#{tag}>"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def cell_value(cell)
|
56
|
+
case cell
|
57
|
+
when Hash
|
58
|
+
cell[:value]
|
59
|
+
else
|
60
|
+
cell
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/tablesmith/table.rb
CHANGED
@@ -12,6 +12,10 @@ module Tablesmith
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def respond_to_missing?
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
15
19
|
# irb
|
16
20
|
def inspect
|
17
21
|
pretty_inspect
|
@@ -56,6 +60,10 @@ module Tablesmith
|
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
63
|
+
def to_html
|
64
|
+
HtmlFormatter.new(self).to_html
|
65
|
+
end
|
66
|
+
|
59
67
|
# override in subclass or mixin
|
60
68
|
def row_values(row)
|
61
69
|
row
|
data/lib/tablesmith/version.rb
CHANGED
data/spec/table_spec.rb
CHANGED
@@ -52,4 +52,27 @@ describe Table do
|
|
52
52
|
TABLE
|
53
53
|
actual.to_table.to_csv.should == expected
|
54
54
|
end
|
55
|
+
|
56
|
+
it 'should output html' do
|
57
|
+
actual = [%w[a b c], %w[d e f]]
|
58
|
+
expected = <<~TABLE
|
59
|
+
<table>
|
60
|
+
<thead>
|
61
|
+
<tr>
|
62
|
+
<th>a</th>
|
63
|
+
<th>b</th>
|
64
|
+
<th>c</th>
|
65
|
+
</tr>
|
66
|
+
</thead>
|
67
|
+
<tbody>
|
68
|
+
<tr>
|
69
|
+
<td>d</td>
|
70
|
+
<td>e</td>
|
71
|
+
<td>f</td>
|
72
|
+
</tr>
|
73
|
+
</tbody>
|
74
|
+
</table>
|
75
|
+
TABLE
|
76
|
+
actual.to_table.to_html.should == expected
|
77
|
+
end
|
55
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablesmith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrismo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: text-table
|
@@ -121,7 +121,6 @@ files:
|
|
121
121
|
- ".ruby-version"
|
122
122
|
- ".travis.yml"
|
123
123
|
- Gemfile
|
124
|
-
- Gemfile.lock
|
125
124
|
- LICENSE
|
126
125
|
- README.md
|
127
126
|
- Rakefile
|
@@ -130,6 +129,7 @@ files:
|
|
130
129
|
- lib/tablesmith/array_rows_source.rb
|
131
130
|
- lib/tablesmith/hash_rows_base.rb
|
132
131
|
- lib/tablesmith/hash_rows_source.rb
|
132
|
+
- lib/tablesmith/html_formatter.rb
|
133
133
|
- lib/tablesmith/table.rb
|
134
134
|
- lib/tablesmith/version.rb
|
135
135
|
- spec/active_record_table_spec.rb
|
data/Gemfile.lock
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
tablesmith (0.3.1)
|
5
|
-
text-table
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activemodel (3.2.22.5)
|
11
|
-
activesupport (= 3.2.22.5)
|
12
|
-
builder (~> 3.0.0)
|
13
|
-
activerecord (3.2.22.5)
|
14
|
-
activemodel (= 3.2.22.5)
|
15
|
-
activesupport (= 3.2.22.5)
|
16
|
-
arel (~> 3.0.2)
|
17
|
-
tzinfo (~> 0.3.29)
|
18
|
-
activesupport (3.2.22.5)
|
19
|
-
i18n (~> 0.6, >= 0.6.4)
|
20
|
-
multi_json (~> 1.0)
|
21
|
-
arel (3.0.3)
|
22
|
-
builder (3.0.4)
|
23
|
-
coderay (1.1.1)
|
24
|
-
diff-lcs (1.3)
|
25
|
-
docile (1.1.5)
|
26
|
-
i18n (0.8.6)
|
27
|
-
json (2.1.0)
|
28
|
-
method_source (0.8.2)
|
29
|
-
multi_json (1.12.1)
|
30
|
-
pry (0.10.4)
|
31
|
-
coderay (~> 1.1.0)
|
32
|
-
method_source (~> 0.8.1)
|
33
|
-
slop (~> 3.4)
|
34
|
-
rake (10.5.0)
|
35
|
-
rspec (2.99.0)
|
36
|
-
rspec-core (~> 2.99.0)
|
37
|
-
rspec-expectations (~> 2.99.0)
|
38
|
-
rspec-mocks (~> 2.99.0)
|
39
|
-
rspec-core (2.99.2)
|
40
|
-
rspec-expectations (2.99.2)
|
41
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
42
|
-
rspec-mocks (2.99.4)
|
43
|
-
simplecov (0.14.1)
|
44
|
-
docile (~> 1.1.0)
|
45
|
-
json (>= 1.8, < 3)
|
46
|
-
simplecov-html (~> 0.10.0)
|
47
|
-
simplecov-html (0.10.1)
|
48
|
-
slop (3.6.0)
|
49
|
-
sqlite3 (1.3.13)
|
50
|
-
text-table (1.2.4)
|
51
|
-
tzinfo (0.3.53)
|
52
|
-
|
53
|
-
PLATFORMS
|
54
|
-
ruby
|
55
|
-
|
56
|
-
DEPENDENCIES
|
57
|
-
activerecord (~> 3.0)
|
58
|
-
pry
|
59
|
-
rake (~> 10.0)
|
60
|
-
rspec (~> 2.0)
|
61
|
-
simplecov
|
62
|
-
sqlite3
|
63
|
-
tablesmith!
|
64
|
-
|
65
|
-
BUNDLED WITH
|
66
|
-
1.16.0.pre.2
|