Spreadsheet-HTML 0.0.7 → 0.0.8

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
2
  SHA1:
3
- metadata.gz: 4f558c4bcf25e70a61bbdc29d284f17e5afb8c59
4
- data.tar.gz: 0a6712cf86da45d7a362b1b940edd8be94617f61
3
+ metadata.gz: 536fbb8dbff6d3a46e7c42fa8be4345067abfd6d
4
+ data.tar.gz: 3c1e0820a66d5147d27b872a59fb78de7e2e6a1c
5
5
  SHA512:
6
- metadata.gz: 0885ae9d8f60181e5cee408afa3c76aef07c99efb2abad894d6bd59c66ee3eb03e8865f9727b391e425b6de6b17bdc89df13f41e109a5ccb3a967e3fdb6727b2
7
- data.tar.gz: 0a66a9626171da040c3af986e76e4c3ef20497ad8d57bf2bae2a4eec050bc72c2bdddfa57b3c7c64bd08b864c949336450e4c115ff2b09c11a6785393e4ea429
6
+ metadata.gz: 7fd20c220637862ce21c526c43ec3ef196679ced8120188de92b974d5401a4da2966a62676ea178d99d2fe18cac0420259a99608e1ab7ceb4f8d9afb8fd9da40
7
+ data.tar.gz: 8c81843c873153648487b1880fbcd55ef3240dc9364be9fea7fc307f8bd0c5cd010b03b3c393f78cf4631e0784caac0ee0f3d71e37a276fece9897c3e0ba3ae5
data/Changes CHANGED
@@ -1,5 +1,11 @@
1
1
  Revision history for html-autotag-ruby
2
2
 
3
+ 0.0.8
4
+ - implemented fill param
5
+ - "defactored" HTML Encoding into this module
6
+ - refactored out default {} for attrs (HTML::AutoAttr handles them)
7
+ - require HTML::AutoTag v1.0.6
8
+
3
9
  0.0.7
4
10
  - fix Ruby dependecy
5
11
 
data/README CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  generator = Spreadsheet::HTML.new( 'data' => data )
19
19
  puts generator.portrait( 'indent' => "\t" )
20
- puts generator.landscape( 'encodes' => 1 )
20
+ puts generator.landscape( 'encode' => 1 )
21
21
 
22
22
  puts generator.generate( 'tgroups' => 1 )
23
23
  puts generator.generate( 'tgroups' => 2 )
@@ -77,9 +77,12 @@ level
77
77
  empty
78
78
  String. Render any empty cells with this value. Defaults to &nbps;
79
79
 
80
+ encode
81
+ Boolean. Whether or not to Encode entities.
82
+
80
83
  encodes
81
- Boolean. Uses htmlentities rubygem to encode any HTML entities found in a cell's data.
82
- (TODO: this value will be a string containing the characters to HTML encode.)
84
+ String. Encode these HTML entities. Pass string with chars you want encoded
85
+ or leave blank for default control and high bit chars and <>!'"
83
86
 
84
87
  matrix
85
88
  Boolean. Render the headings row with only <td> tags, no <th> tags.
@@ -100,6 +103,11 @@ pinhead
100
103
  Works in conjunction with theta to ensure reporting readability. Without it, south() and east()
101
104
  would have data cells arranged in reverse order.
102
105
 
106
+ fill
107
+ Can be used instead of data to create a "blank" table or with data to pad rows and cells.
108
+
109
+ fill => '8x12' # 8 rows, 12 columns
110
+
103
111
  == Dynamic Parameters
104
112
  There currently are no Dynamic Parameters, but they will be implemented soon enough.
105
113
  They will allow the client to modify headings by name and row/columns by their indices.
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency 'rake'
25
- spec.add_runtime_dependency 'HTML-AutoTag', '>= 1.0.5'
25
+ spec.add_runtime_dependency 'HTML-AutoTag', '>= 1.0.6'
26
26
  end
@@ -1,11 +1,15 @@
1
1
  require "Spreadsheet/HTML/version"
2
2
  require "HTML/AutoTag"
3
3
 
4
- # i cannot hasa instantiate HTML::AutoTag inside Spreadsheet::HTML?!?
4
+ # i cannot instantiate any HTML::foo inside any bar::HTML?!?
5
5
  module Auto
6
6
  class Tag < HTML::AutoTag
7
7
  end
8
8
  end
9
+ module Enco
10
+ class Der < HTML::Encoder
11
+ end
12
+ end
9
13
 
10
14
  module Spreadsheet
11
15
  class HTML
@@ -105,19 +109,19 @@ module Spreadsheet
105
109
  head = body.shift() unless params['matrix'] && data.size() > 2
106
110
  foot = body.pop() if !params['matrix'] && params['tgroups'] > 1 and data.size() > 2
107
111
 
108
- head_row = { 'tag' => 'tr', 'attr' => params['thead.tr'] || {}, 'cdata' => head }
109
- foot_row = { 'tag' => 'tr', 'attr' => params['tfoot.tr'] || {}, 'cdata' => foot }
110
- body_rows = body.map{ |r| { 'tag' => 'tr', 'attr' => params['tr'] || {}, 'cdata' => r } }
112
+ head_row = { 'tag' => 'tr', 'attr' => params['thead.tr'], 'cdata' => head }
113
+ foot_row = { 'tag' => 'tr', 'attr' => params['tfoot.tr'], 'cdata' => foot }
114
+ body_rows = body.map{ |r| { 'tag' => 'tr', 'attr' => params['tr'], 'cdata' => r } }
111
115
 
112
- cdata.push({ 'tag' => 'thead', 'attr' => params['thead'] || {}, 'cdata' => head_row }) if head
113
- cdata.push({ 'tag' => 'tfoot', 'attr' => params['tfoot'] || {}, 'cdata' => foot_row }) if foot
114
- cdata.push({ 'tag' => 'tbody', 'attr' => params['tbody'] || {}, 'cdata' => body_rows })
116
+ cdata.push({ 'tag' => 'thead', 'attr' => params['thead'], 'cdata' => head_row }) if head
117
+ cdata.push({ 'tag' => 'tfoot', 'attr' => params['tfoot'], 'cdata' => foot_row }) if foot
118
+ cdata.push({ 'tag' => 'tbody', 'attr' => params['tbody'], 'cdata' => body_rows })
115
119
 
116
120
  else
117
- cdata.push( params['data'].map { |c| { 'tag' => 'tr', 'attr' => params['tr'] || {}, 'cdata' => c } } )
121
+ cdata.push( params['data'].map { |c| { 'tag' => 'tr', 'attr' => params['tr'], 'cdata' => c } } )
118
122
  end
119
123
 
120
- return params['auto'].tag( 'tag' => 'table', 'attr' => params['table'] || {}, 'cdata' => cdata )
124
+ return params['auto'].tag( 'tag' => 'table', 'attr' => params['table'], 'cdata' => cdata )
121
125
  end
122
126
 
123
127
  def _process( args )
@@ -131,24 +135,27 @@ module Spreadsheet
131
135
  # implement index mapping
132
136
  end
133
137
 
134
- data = []
138
+ data = params['data']
135
139
  empty = params.has_key?('empty') ? params['empty'] : '&nbsp;'
136
140
  tag = ( params['matrix'] or params['headless'] ) ? 'td' : 'th'
137
141
 
138
- params['data'].each do |row|
142
+ encoder = Enco::Der.new
143
+ for i in 0 .. params['_max_rows'] - 1
139
144
 
145
+ data[i] ||= []
140
146
  unless params['_layout']
141
- (params['_max_cols'] - row.size).times { row.push( nil ) } # pad
142
- (row.size - params['_max_cols']).times { row.pop } # truncate
147
+ (params['_max_cols'] - data[i].size).times { data[i].push( nil ) } # pad
148
+ (data[i].size - params['_max_cols']).times { data[i].pop } # truncate
143
149
  end
144
150
 
145
151
  r = []
146
- row.each do |col|
152
+ data[i].each do |col|
147
153
  col = col.to_s
154
+ col = encoder.encode( col, params['encodes'] ) if params['encode'] or !params['encodes'].to_s.empty?
148
155
  col = col.gsub( /^\s*$/, empty )
149
- r.push( { 'tag' => tag, 'attr' => params[tag] || {}, 'cdata' => col } )
156
+ r.push( { 'tag' => tag, 'attr' => params[tag], 'cdata' => col } )
150
157
  end
151
- data.push( r )
158
+ data[i] = r
152
159
  tag = 'td'
153
160
  end
154
161
 
@@ -191,7 +198,6 @@ module Spreadsheet
191
198
  end
192
199
 
193
200
  params['auto'] = Auto::Tag.new(
194
- 'encodes' => params.has_key?('encodes') ? params['encodes'] : '',
195
201
  'indent' => params['indent'],
196
202
  'level' => params['level'],
197
203
  'sorted' => params['attr_sort'],
@@ -202,10 +208,18 @@ module Spreadsheet
202
208
  params['data'] = data[0]
203
209
  end
204
210
 
205
- params['_max_rows'] = params['data'].size
206
- params['_max_cols'] = params['data'][0].size
211
+ params['data'] = [ [ nil ] ] if params['data'].nil?
212
+
213
+ params['_max_rows'] = params['data'].size || 1
214
+ params['_max_cols'] = params['data'][0].size || 1
207
215
  params['data'] = params['data'].clone
208
216
 
217
+ if params['fill']
218
+ (row,col) = params['fill'].split(/\D/)
219
+ params['_max_rows'] = row.to_i if row.to_i > params['_max_rows']
220
+ params['_max_cols'] = col.to_i if col.to_i > params['_max_cols']
221
+ end
222
+
209
223
  return params
210
224
  end
211
225
 
@@ -1,5 +1,5 @@
1
1
  module Spreadsheet
2
2
  class HTML
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
data/t/09-padding.rb CHANGED
@@ -33,4 +33,42 @@ class Test_Padding < Test::Unit::TestCase
33
33
 
34
34
  end
35
35
 
36
+ def test_fill
37
+
38
+ gen = Spreadsheet::HTML.new
39
+
40
+ data = Array[
41
+ %w(header1 header2),
42
+ Array[ 'foo1', 'bar1' ],
43
+ Array[ 'foo2', 'bar2' ],
44
+ ]
45
+
46
+ assert_equal(
47
+ '<table><tr><th>&nbsp;</th><th>&nbsp;</th><th>&nbsp;</th><th>&nbsp;</th><th>&nbsp;</th></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>',
48
+ gen.generate( 'fill' => '3x5' ),
49
+ "fill works with no data"
50
+ )
51
+
52
+ assert_equal(
53
+ '<table><tr><th>&nbsp;</th></tr></table>',
54
+ gen.generate( 'fill' => '0x0' ),
55
+ "fill defaults to 1x1 with with invalid data (zero)"
56
+ )
57
+
58
+ assert_equal(
59
+ '<table><tr><th>&nbsp;</th></tr></table>',
60
+ gen.generate( 'fill' => 'axb' ),
61
+ "fill defaults to 1x1 with with invalid data (letters)"
62
+ )
63
+
64
+ assert_equal(
65
+ '<table><tr><th>header1</th><th>header2</th><th>&nbsp;</th><th>&nbsp;</th><th>&nbsp;</th></tr><tr><td>foo1</td><td>bar1</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>foo2</td><td>bar2</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>',
66
+ gen.generate( 'fill' => '3x5', 'data' => data ),
67
+ "fill works with valid data"
68
+ )
69
+
70
+
71
+
72
+ end
73
+
36
74
  end
data/t/12-encodes.rb CHANGED
@@ -9,30 +9,37 @@ class Test_Encodes < Test::Unit::TestCase
9
9
  %w(header1 header2 header3),
10
10
  Array[ '<foo1>', '&bar1', '"baz1' ],
11
11
  Array[ '<foo2>', '&bar2', '"baz2' ],
12
+ Array[ '', '0', '' ],
12
13
  ]
13
14
 
14
15
  gen = Spreadsheet::HTML.new( 'data' => data )
15
16
 
16
17
  assert_equal(
17
- '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr></table>',
18
+ '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr><tr><td>&nbsp;</td><td>0</td><td>&nbsp;</td></tr></table>',
18
19
  gen.generate(),
19
20
  "nothing encoded by default"
20
21
  )
21
22
 
22
23
  assert_equal(
23
- '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td>&lt;foo1&gt;</td><td>&amp;bar1</td><td>&quot;baz1</td></tr><tr><td>&lt;foo2&gt;</td><td>&amp;bar2</td><td>&quot;baz2</td></tr></table>',
24
- gen.generate( 'encodes' => nil ),
24
+ '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td>&lt;foo1&gt;</td><td>&amp;bar1</td><td>&quot;baz1</td></tr><tr><td>&lt;foo2&gt;</td><td>&amp;bar2</td><td>&quot;baz2</td></tr><tr><td>&nbsp;</td><td>0</td><td>&nbsp;</td></tr></table>',
25
+ gen.generate( 'encode' => 1 ),
25
26
  "default encoding works"
26
27
  )
27
28
 
28
29
  assert_equal(
29
- '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&amp;bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&amp;bar2</td><td>"baz2</td></tr></table>',
30
+ '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&amp;bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&amp;bar2</td><td>"baz2</td></tr><tr><td>&nbsp;</td><td>0</td><td>&nbsp;</td></tr></table>',
30
31
  gen.generate( 'encodes' => '&' ),
31
32
  "only requested char is encoded"
32
33
  )
33
34
 
34
35
  assert_equal(
35
- '<table><tr><th>he&#97;der1</th><th>he&#97;der2</th><th>he&#97;der3</th></tr><tr><td><foo1></td><td>&amp;b&#97;r1</td><td>&quot;b&#97;z1</td></tr><tr><td><foo2></td><td>&amp;b&#97;r2</td><td>&quot;b&#97;z2</td></tr></table>',
36
+ '<table><tr><th>header1</th><th>header2</th><th>header3</th></tr><tr><td><foo1></td><td>&bar1</td><td>"baz1</td></tr><tr><td><foo2></td><td>&bar2</td><td>"baz2</td></tr><tr><td>&nbsp;</td><td>&#48;</td><td>&nbsp;</td></tr></table>',
37
+ gen.generate( 'encodes' => '0' ),
38
+ "zero as requested char is encoded"
39
+ )
40
+
41
+ assert_equal(
42
+ '<table><tr><th>he&#97;der1</th><th>he&#97;der2</th><th>he&#97;der3</th></tr><tr><td><foo1></td><td>&amp;b&#97;r1</td><td>&quot;b&#97;z1</td></tr><tr><td><foo2></td><td>&amp;b&#97;r2</td><td>&quot;b&#97;z2</td></tr><tr><td>&nbsp;</td><td>0</td><td>&nbsp;</td></tr></table>',
36
43
  gen.generate( 'encodes' => 'a&"' ),
37
44
  "requested chars are encoded"
38
45
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Spreadsheet-HTML
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeffa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-04 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.5
47
+ version: 1.0.6
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.0.5
54
+ version: 1.0.6
55
55
  description: Just another HTML table generator
56
56
  email:
57
57
  - jeffa@cpan.org