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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7a2fd83722900bb09ea99100682d44f292daa222
4
- data.tar.gz: b553cf68c0e2e739e214679686de413fe94a341e
2
+ SHA256:
3
+ metadata.gz: be087dbd34683e86222c190ef4249057adfe43faad8e372cea1e498d8a62a5cf
4
+ data.tar.gz: 3bf1c710554f51d5573063d8814791b99257f554215eb53303df1f0a7096d82f
5
5
  SHA512:
6
- metadata.gz: 65df2f5381247e83eacdc4232fca2bca9c49f2b8f1008370099e93e7016403a7a10b24879ab08bc0cd385fd1f566090d44360db8e30b2ef95cb5dd259570b87c
7
- data.tar.gz: e74e10005826799250ffafdb3039abaa7fc350267727a1ccececc6b439d20d9d349a5615d009b47be2862c8c7a0663515836f8fb89636b1a7d3ab80f051b191a
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)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2016 Jeremy Evans
1
+ Copyright (c) 2013-2019 Jeremy Evans
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to
@@ -5,7 +5,7 @@ tables from enumerable objects.
5
5
 
6
6
  = Installation
7
7
 
8
- sudo gem install thamble
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
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  desc "Run specs"
14
14
  task :spec do
15
- sh "#{FileUtils::RUBY} -rubygems -I lib spec/thamble_spec.rb"
15
+ sh "#{FileUtils::RUBY} -I lib spec/thamble_spec.rb"
16
16
  end
17
17
 
18
18
  task :default => :spec
@@ -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
- Rack::Utils.escape_html(s.to_s)
222
+ escape_html(s)
206
223
  end
207
224
  end
208
225
  end
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require File.join(File.dirname(File.expand_path(__FILE__)), '../lib/thamble')
3
- require 'minitest/autorun'
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.2
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: 2016-01-28 00:00:00.000000000 Z
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
- rubyforge_project:
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