Spreadsheet-HTML 0.0.10 → 0.0.11

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: 69280b7ae0534329c562340c5d86a9bc3753ca49
4
- data.tar.gz: 86a46dc59fb742b0115aaf5d1f3feeb72d476934
3
+ metadata.gz: 193027f607dd3ef04e4265fd03be81f3bdf75d86
4
+ data.tar.gz: a519f019fc77f3fca13384e64acb69d9b9231d99
5
5
  SHA512:
6
- metadata.gz: 4aa64fa4375b280792b55d1a517598f9218be78ada368e1bef986dc1fbe42a6eb18c512341cdf9d456de727b6b0ab4e4da829f888217ea978f3fed58c48f84af
7
- data.tar.gz: 67f8dc2ad38cd2544597471c28812e3ede9b21acd6e075e4f57b46470a9bf98966000685443f1da139160be298ef6f8f865883ebae837897e50b6a46eefd2751
6
+ metadata.gz: e1712621904d70a3938d4d257e3839bc2b085df25d0aeb9d20d9bc6b7ec903892005b509b873d1c17da7658c35286721ae52c67b879b19a77fe399d2c5b6b87f
7
+ data.tar.gz: 2c2035633f4d03f4cdbfbba0d23d515de0adc751f1d53c89fb6def0521766b02450e360db17a769fd7a451cf4402da8eae9236c688fea2cc83ba8500ea3cf49f
data/Changes CHANGED
@@ -1,5 +1,9 @@
1
1
  Revision history for html-autotag-ruby
2
2
 
3
+ 0.0.11
4
+ - added col and colgroup params
5
+ - added caption param
6
+
3
7
  0.0.10
4
8
  - implemented lambda/proc for dynamic and tag params
5
9
 
data/README CHANGED
@@ -140,6 +140,14 @@ fill
140
140
 
141
141
  'fill' => '8x12' # 8 rows, 12 columns
142
142
 
143
+ caption
144
+ Caption is special in that you can either pass a string to be used as CDATA or a hash whose only
145
+ key is the string to be used as CDATA.
146
+
147
+ 'caption' => 'Just Another Title'
148
+
149
+ 'caption' => { 'A Title With Attributes' => { 'align' => 'bottom' } }
150
+
143
151
  == Dynamic Parameters
144
152
  Dynamic parameters provide a means to control the micro elements of the table,
145
153
  such as modifying headings by their name and rows and columns by their indices.
@@ -14,33 +14,15 @@ end
14
14
  module Spreadsheet
15
15
  class HTML
16
16
 
17
- def self.gen( *args )
18
- self.new.generate( *args )
19
- end
20
-
21
- def north( *args )
22
- generate( *args, 'theta' => 0 )
23
- end
17
+ def self.gen ( *args ) self.new.generate( *args ) end
24
18
 
25
- def portrait( *args )
26
- generate( *args, 'theta' => 0 )
27
- end
19
+ def portrait ( *args ) generate( *args, 'theta' => 0 ) end
20
+ def landscape ( *args ) generate( *args, 'theta' => -270, 'tgroups' => 0 ) end
28
21
 
29
- def west( *args )
30
- generate( *args, 'theta' => -270, 'tgroups' => 0 )
31
- end
32
-
33
- def landscape( *args )
34
- generate( *args, 'theta' => -270, 'tgroups' => 0 )
35
- end
36
-
37
- def east( *args )
38
- generate( *args, 'theta' => 90, 'tgroups' => 0, 'pinhead' => 1 )
39
- end
40
-
41
- def south( *args )
42
- generate( *args, 'theta' => -180, 'tgroups' => 0, 'pinhead' => 1 )
43
- end
22
+ def north ( *args ) generate( *args, 'theta' => 0 ) end
23
+ def west ( *args ) generate( *args, 'theta' => -270, 'tgroups' => 0 ) end
24
+ def east ( *args ) generate( *args, 'theta' => 90, 'tgroups' => 0, 'pinhead' => 1 ) end
25
+ def south ( *args ) generate( *args, 'theta' => -180, 'tgroups' => 0, 'pinhead' => 1 ) end
44
26
 
45
27
  def generate( *args )
46
28
  params = _process( args )
@@ -101,7 +83,15 @@ module Spreadsheet
101
83
  end
102
84
 
103
85
  def _make_table( params )
104
- cdata = [] # TODO: insert caption and colgroup
86
+ cdata = Array[]
87
+
88
+ if params.has_key?( 'caption' )
89
+ cdata.push( _tag( 'caption', params['caption'] ) )
90
+ end
91
+
92
+ if params.has_key?( 'colgroup' ) or params.has_key?( 'col' )
93
+ cdata.concat( _colgroup( params ) )
94
+ end
105
95
 
106
96
  if params['tgroups'] && params['tgroups'] > 0
107
97
 
@@ -118,7 +108,7 @@ module Spreadsheet
118
108
  cdata.push({ 'tag' => 'tbody', 'attr' => params['tbody'], 'cdata' => body_rows })
119
109
 
120
110
  else
121
- cdata.push( params['data'].map { |c| { 'tag' => 'tr', 'attr' => params['tr'], 'cdata' => c } } )
111
+ cdata.concat( params['data'].map { |c| { 'tag' => 'tr', 'attr' => params['tr'], 'cdata' => c } } )
122
112
  end
123
113
 
124
114
  return params['auto'].tag( 'tag' => 'table', 'attr' => params['table'], 'cdata' => cdata )
@@ -260,6 +250,46 @@ module Spreadsheet
260
250
  return [ cdata, attr ]
261
251
  end
262
252
 
253
+ def _colgroup( params )
254
+ colgroup = Array[]
255
+ params['col'] = Array[ params['col'] ] if params['col'].kind_of?(Hash)
256
+
257
+ if params['col'].kind_of?(Array)
258
+ if params['colgroup'].kind_of?(Array)
259
+ colgroup = params['colgroup'].map{ |cg|
260
+ {
261
+ 'tag' => 'colgroup',
262
+ 'attr' => cg,
263
+ 'cdata' => params['col'].map{ |attr| { 'tag' => 'col', 'attr' => attr } }
264
+ }
265
+ }
266
+ else
267
+ colgroup = {
268
+ 'tag' => 'colgroup',
269
+ 'attr' => params['colgroup'],
270
+ 'cdata' => params['col'].map{ |attr| { 'tag' => 'col', 'attr' => attr } }
271
+ }
272
+ end
273
+ else
274
+ params['colgroup'] = Array[ params['colgroup'] ] if params['colgroup'].kind_of?(Hash)
275
+ if params['colgroup'].kind_of?(Array)
276
+ colgroup = params['colgroup'].map{ |attr| { 'tag' => 'colgroup', 'attr' => attr } }
277
+ end
278
+ end
279
+
280
+ colgroup = Array[colgroup] if colgroup.kind_of?(Hash)
281
+ return colgroup
282
+ end
283
+
284
+ def _tag( tag, cdata )
285
+ tag = { 'tag' => tag, 'cdata' => cdata }
286
+ if cdata.kind_of?( Hash )
287
+ tag['cdata'] = cdata.keys[0]
288
+ tag['attr'] = cdata.values[0]
289
+ end
290
+ return tag
291
+ end
292
+
263
293
  end
264
294
 
265
295
  end
@@ -1,5 +1,5 @@
1
1
  module Spreadsheet
2
2
  class HTML
3
- VERSION = "0.0.10"
3
+ VERSION = "0.0.11"
4
4
  end
5
5
  end
data/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  Spreadsheet-HTML (ruby)
2
2
  =======================
3
- Just another HTML table generator for ruby.
3
+ Just another HTML table generator for ruby. [![Gem Version](https://badge.fury.io/rb/Spreadsheet-HTML.svg)](https://badge.fury.io/rb/Spreadsheet-HTML)
4
4
 
5
5
  Description
6
6
  -----------
data/t/13-caption.rb ADDED
@@ -0,0 +1,44 @@
1
+ require "test/unit"
2
+ require "Spreadsheet/HTML"
3
+
4
+ class Test_Caption < Test::Unit::TestCase
5
+
6
+ def test_caption
7
+
8
+ data = Array[
9
+ %w( a b c ),
10
+ %w( 1 2 3 ),
11
+ %w( 4 5 6 ),
12
+ ]
13
+
14
+ gen = Spreadsheet::HTML.new( 'data' => data, 'caption' => "My Table" )
15
+
16
+ assert_equal(
17
+ '<table><caption>My Table</caption><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
18
+ gen.generate(),
19
+ "caption present from generate()"
20
+ )
21
+
22
+ gen = Spreadsheet::HTML.new( 'data' => data, 'caption' => { "My Table" => { 'key' => 'value' } } )
23
+
24
+ assert_equal(
25
+ '<table><caption key="value">My Table</caption><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
26
+ gen.generate(),
27
+ "caption present from generate()"
28
+ )
29
+
30
+ assert_equal(
31
+ '<table><caption key="value">My Table</caption><thead><tr><th>a</th><th>b</th><th>c</th></tr></thead><tfoot><tr><td>4</td><td>5</td><td>6</td></tr></tfoot><tbody><tr><td>1</td><td>2</td><td>3</td></tr></tbody></table>',
32
+ gen.generate( 'tgroups' => 2 ),
33
+ "caption present from generate() with tgroups"
34
+ )
35
+
36
+ assert_equal(
37
+ '<table><caption>0</caption><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
38
+ gen.generate( 'caption' => 0 ),
39
+ "caption can be overriden"
40
+ )
41
+
42
+ end
43
+
44
+ end
data/t/14-colgroup.rb ADDED
@@ -0,0 +1,99 @@
1
+ require "test/unit"
2
+ require "Spreadsheet/HTML"
3
+
4
+ class Test_Colgroup < Test::Unit::TestCase
5
+
6
+ def test_colgroup
7
+
8
+ data = Array[
9
+ %w( a b c ),
10
+ %w( 1 2 3 ),
11
+ %w( 4 5 6 ),
12
+ ]
13
+
14
+ gen = Spreadsheet::HTML.new( 'data' => data, 'colgroup' => { 'span' => '3', 'width' => '100' }, 'attr_sort' => 1 );
15
+
16
+ assert_equal(
17
+ '<table><colgroup span="3" width="100" /><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
18
+ gen.generate,
19
+ "colgroup present from generate()"
20
+ )
21
+
22
+ assert_equal(
23
+ '<table><colgroup span="3" width="100" /><thead><tr><th>a</th><th>b</th><th>c</th></tr></thead><tfoot><tr><td>4</td><td>5</td><td>6</td></tr></tfoot><tbody><tr><td>1</td><td>2</td><td>3</td></tr></tbody></table>',
24
+ gen.generate( 'tgroups' => 2 ),
25
+ "colgroup present from generate() with tgroups"
26
+ )
27
+
28
+ assert_equal(
29
+ '<table><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
30
+ gen.generate( 'colgroup' => nil ),
31
+ "colgroup can be overriden"
32
+ )
33
+
34
+ assert_equal(
35
+ '<table><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
36
+ gen.generate( 'colgroup' => 1 ),
37
+ "colgroup yields no-op if scalar"
38
+ )
39
+
40
+ assert_equal(
41
+ '<table><colgroup color="red" span="1" /><colgroup color="blue" span="2" /><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
42
+ gen.generate( 'colgroup' => [ { 'span' => '1', 'color' => 'red' }, { 'span' => '2', 'color' => 'blue' } ] ),
43
+ "can specify multiple colgroups"
44
+ )
45
+
46
+ end
47
+
48
+ def test_col
49
+
50
+ data = Array[
51
+ %w( a b c ),
52
+ %w( 1 2 3 ),
53
+ %w( 4 5 6 ),
54
+ ]
55
+
56
+ gen = Spreadsheet::HTML.new( 'data' => data, 'colgroup' => { 'span' => '3', 'width' => '100' }, 'attr_sort' => 1 );
57
+
58
+ assert_equal(
59
+ '<table><colgroup span="3" width="100"><col /></colgroup><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
60
+ gen.generate( 'col' => {} ),
61
+ "colgroup wraps col"
62
+ )
63
+
64
+ assert_equal(
65
+ '<table><colgroup span="3" width="100"><col /><col /><col /></colgroup><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
66
+ gen.generate( 'col' => [{},{},{}] ),
67
+ "colgroup wraps multiple cols"
68
+ )
69
+
70
+ assert_equal(
71
+ '<table><colgroup><col /></colgroup><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
72
+ gen.generate( 'colgroup' => nil, 'col' => {} ),
73
+ "colgroup can be overriden when col is present too"
74
+ )
75
+
76
+
77
+ gen = Spreadsheet::HTML.new( 'data' => data, 'col' => Array[{},{},{}] );
78
+
79
+ assert_equal(
80
+ '<table><colgroup><col /><col /><col /></colgroup><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
81
+ gen.generate( 'colgroup' => {} ),
82
+ "multiple cols against single colgroup"
83
+ )
84
+
85
+ assert_equal(
86
+ '<table><colgroup /><colgroup /><colgroup /><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
87
+ gen.generate( 'col' => nil, 'colgroup' => Array[{},{},{}] ),
88
+ "no cols against multiple colgroups"
89
+ )
90
+
91
+ assert_equal(
92
+ '<table><colgroup><col /><col /><col /></colgroup><colgroup><col /><col /><col /></colgroup><colgroup><col /><col /><col /></colgroup><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>',
93
+ gen.generate( 'colgroup' => Array[{},{},{}] ),
94
+ "multiple cols against multiple colgroups"
95
+ )
96
+
97
+ end
98
+
99
+ end
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.10
4
+ version: 0.0.11
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-20 00:00:00.000000000 Z
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,6 +83,8 @@ files:
83
83
  - t/10-indent.rb
84
84
  - t/11-empty.rb
85
85
  - t/12-encodes.rb
86
+ - t/13-caption.rb
87
+ - t/14-colgroup.rb
86
88
  homepage: https://github.com/jeffa/spreadsheet-html-ruby
87
89
  licenses:
88
90
  - MIT