thamble 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +6 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -1
- data/Rakefile +1 -1
- data/lib/thamble.rb +22 -5
- data/spec/thamble_spec.rb +6 -1
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be087dbd34683e86222c190ef4249057adfe43faad8e372cea1e498d8a62a5cf
|
4
|
+
data.tar.gz: 3bf1c710554f51d5573063d8814791b99257f554215eb53303df1f0a7096d82f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ea505f39ff8901cd49c1d65627ae0be026cb564dbca373b68e41028ec629dd629794bb4b7d9e52212fbd1efd72e6eaa4facd58a3697cea7b10b80534f450bd1
|
7
|
+
data.tar.gz: f38d8910459727b2b8c90f6bbd7aa6c6a7e656e7606c4c7a5cf196534c3af7620651336aa4c58b6f91465b3ccba5459b22cab0bd074b3da1aa0defa30ed0b2c8
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 1.1.0 (2019-11-20)
|
2
|
+
|
3
|
+
* Support :column_th option for using th instead of td for first cell in each row (jeremyevans)
|
4
|
+
|
5
|
+
* Use cgi/escape if available for faster escaping (jeremyevans)
|
6
|
+
|
1
7
|
=== 1.0.2 (2016-01-28)
|
2
8
|
|
3
9
|
* Add support for running with --enable-frozen-string-literal on ruby 2.3 (jeremyevans)
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@ tables from enumerable objects.
|
|
5
5
|
|
6
6
|
= Installation
|
7
7
|
|
8
|
-
|
8
|
+
gem install thamble
|
9
9
|
|
10
10
|
= Source Code
|
11
11
|
|
@@ -71,6 +71,7 @@ You can use the :headers option to set custom headers:
|
|
71
71
|
Other options supported are:
|
72
72
|
|
73
73
|
:caption :: A caption for the table
|
74
|
+
:column_th :: Use th instead of td for first cell in each row
|
74
75
|
:table :: HTML attribute hash for the table itself
|
75
76
|
:td :: HTML attribute hash for the table data cells, can be a proc called
|
76
77
|
with the data value, row position, and row that returns a hash
|
data/Rakefile
CHANGED
data/lib/thamble.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
|
-
require 'rack/utils'
|
4
|
-
|
5
3
|
# Thamble exposes a single method named table to make it easy to generate
|
6
4
|
# an HTML table from an enumerable.
|
7
5
|
module Thamble
|
@@ -15,9 +13,11 @@ module Thamble
|
|
15
13
|
#
|
16
14
|
# Options:
|
17
15
|
#
|
16
|
+
# :caption :: A caption for the table
|
17
|
+
# :column_th :: Use th instead of td for the first cell in each row in the
|
18
|
+
# body.
|
18
19
|
# :headers :: The headers to use for the table, as an array of strings or a
|
19
20
|
# single string using commas as the separtor.
|
20
|
-
# :caption :: A caption for the table
|
21
21
|
# :table :: HTML attribute hash for the table itself
|
22
22
|
# :td :: HTML attribute hash for the table data cells, can be a proc called
|
23
23
|
# with the data value, row position, and row that returns a hash
|
@@ -61,6 +61,7 @@ module Thamble
|
|
61
61
|
tr_attr = @opts[:tr]
|
62
62
|
th_attr = @opts[:th]
|
63
63
|
td_attr = @opts[:td]
|
64
|
+
col_th = @opts[:column_th]
|
64
65
|
|
65
66
|
t = tag('table', empty, @opts[:table])
|
66
67
|
s = t.open.dup
|
@@ -97,7 +98,7 @@ module Thamble
|
|
97
98
|
s << trh.open
|
98
99
|
s << nl
|
99
100
|
row.each_with_index do |col, i|
|
100
|
-
s << tag(td, col, handle_proc(td_attr, col, i, row)).to_s
|
101
|
+
s << tag((col_th && i == 0 ? th : td), col, handle_proc(td_attr, col, i, row)).to_s
|
101
102
|
end
|
102
103
|
s << trh.close
|
103
104
|
end
|
@@ -194,6 +195,22 @@ module Thamble
|
|
194
195
|
@attr.map{|k,v| "#{k}=\"#{h v}\""}.sort.join(' ')
|
195
196
|
end
|
196
197
|
|
198
|
+
begin
|
199
|
+
require 'cgi/escape'
|
200
|
+
unless CGI.respond_to?(:escapeHTML) # work around for JRuby 9.1
|
201
|
+
CGI = Object.new
|
202
|
+
CGI.extend(defined?(::CGI::Escape) ? ::CGI::Escape : ::CGI::Util)
|
203
|
+
end
|
204
|
+
def escape_html(value)
|
205
|
+
CGI.escapeHTML(value.to_s)
|
206
|
+
end
|
207
|
+
rescue LoadError
|
208
|
+
require 'rack/utils'
|
209
|
+
def escape_html(value)
|
210
|
+
Rack::Utils.escape_html(value.to_s)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
197
214
|
# A HTML-escaped version of the given argument.
|
198
215
|
def h(s)
|
199
216
|
case s
|
@@ -202,7 +219,7 @@ module Thamble
|
|
202
219
|
when Tag
|
203
220
|
s.to_s
|
204
221
|
else
|
205
|
-
|
222
|
+
escape_html(s)
|
206
223
|
end
|
207
224
|
end
|
208
225
|
end
|
data/spec/thamble_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require File.join(File.dirname(File.expand_path(__FILE__)), '../lib/thamble')
|
3
|
-
|
3
|
+
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
|
4
|
+
require 'minitest/global_expectations/autorun'
|
4
5
|
|
5
6
|
describe "Thamble.table" do
|
6
7
|
def table(*a, &block)
|
@@ -11,6 +12,10 @@ describe "Thamble.table" do
|
|
11
12
|
table([[1, 2]]).must_equal '<table><tbody><tr><td>1</td><td>2</td></tr></tbody></table>'
|
12
13
|
end
|
13
14
|
|
15
|
+
it 'should :support :column_th option for first column being th' do
|
16
|
+
table([[1, 2]], :column_th=>true).must_equal '<table><tbody><tr><th>1</th><td>2</td></tr></tbody></table>'
|
17
|
+
end
|
18
|
+
|
14
19
|
it 'should support :headers option for the headers' do
|
15
20
|
table([[1, 2]], :headers=>%w'a b').must_equal '<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2</td></tr></tbody></table>'
|
16
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thamble
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-global_expectations
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: |
|
42
56
|
Thamble exposes a single method, table, for easily creating HTML
|
43
57
|
tables from enumerable objects.
|
@@ -82,8 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '0'
|
84
98
|
requirements: []
|
85
|
-
|
86
|
-
rubygems_version: 2.5.1
|
99
|
+
rubygems_version: 3.0.3
|
87
100
|
signing_key:
|
88
101
|
specification_version: 4
|
89
102
|
summary: Create HTML Tables from Enumerables
|