webget_ruby_html 1.0.8

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.
data/LICENSE.txt ADDED
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+
3
+ You may choose any of these licenses:
4
+
5
+ - CreativeCommons License, Non-commercial Share Alike
6
+ - LGPL, GNU Lesser General Public License
7
+ - MIT License
8
+ - Ruby License
9
+
10
+ THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
data/README.rdoc ADDED
@@ -0,0 +1,15 @@
1
+
2
+ = WebGet Ruby Gem: HTML helpers for tables, lists, etc.
3
+
4
+ Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
5
+ Copyright:: Copyright (c) 2006-2010 Joel Parker Henderson
6
+ License:: CreativeCommons License, Non-commercial Share Alike
7
+ License:: LGPL, GNU Lesser General Public License
8
+
9
+ ==Changes
10
+
11
+ 1.0.6 add to gemcutter
12
+ 1.0.5 comment & wrap
13
+ 1.0.4 tables
14
+ 1.0.0 lists
15
+
@@ -0,0 +1,342 @@
1
+ =begin rdoc
2
+
3
+ = WebGet Ruby Gem: HTML helpers for tables, lists, etc.
4
+
5
+ Author:: Joel Parker Henderson, joelparkerhenderson@gmail.com
6
+ Copyright:: Copyright (c) 2006-2010 Joel Parker Henderson
7
+ License:: CreativeCommons License, Non-commercial Share Alike
8
+ License:: LGPL, GNU Lesser General Public License
9
+
10
+ ==Changes
11
+
12
+ 1.0.6 add to gemcutter
13
+ 1.0.5 comment & wrap
14
+ 1.0.4 tables
15
+ 1.0.0 lists
16
+
17
+ =end
18
+
19
+ module HTML
20
+
21
+ # Return the text wrapped in a comment.
22
+ #
23
+ # ==Example
24
+ # comment('foo') => "<!--foo-->"
25
+
26
+ def comment(text)
27
+ "<!--#{text}-->"
28
+ end
29
+
30
+ # Return the text wrapped in a tag pair.
31
+ #
32
+ # ==Example
33
+ # wrap('foo','<bar>') => "<bar>foo</bar>"
34
+ #
35
+ # ==Example: you can omit the tag angle brackets
36
+ # wrap('foo','bar') => "<bar>foo</bar>"
37
+ #
38
+ # ==Example: you can use arbitrary tag attributes
39
+ # wrap('foo','<bar x="1" y="2">') => "<bar x=1 y=2>foo</bar>"
40
+ #
41
+
42
+ def wrap(text,tag)
43
+ t=tag
44
+ t.sub!(/^</,'')
45
+ t.sub!(/>$/,'')
46
+ open=t
47
+ shut=t.split.first
48
+ "<#{open}>#{text}</#{shut}>"
49
+ end
50
+
51
+
52
+ # Options:
53
+ # :text : the complete text of the table, e.g. <table>text</table>
54
+ # :headers
55
+ # :footers
56
+ # :rows
57
+ # :class is the table's css class, e.g. :class=>'sortable'
58
+ # :id is the table's css id, e.g. :id=>'mytable'
59
+ #
60
+ # ==Example
61
+ # headers = ['a','b','c']
62
+ # footers = ['x','y','z']
63
+ # rows=[['d','e,'f'],['g','h,'i'],['j','k','l']
64
+ # table(:id=>'foo', :class=>'bar', :headers=>headers, :footers=>footers, :rows=>rows
65
+ #
66
+ # ==Return HTML
67
+ # <table id="foo" class="bar">
68
+ # <thead>
69
+ # <tr>
70
+ # <th>a</th>
71
+ # <th>b</th>
72
+ # <th>c</th>
73
+ # </tr>
74
+ # </thead>
75
+ # <tbody>
76
+ # <tr>
77
+ # <td>d</td>
78
+ # <td>e</td>
79
+ # <td>f</td>
80
+ # </tr>
81
+ # <tr>
82
+ # <td>g</td>
83
+ # <td>h</td>
84
+ # <td>i</td>
85
+ # </tr>
86
+ # <tr>
87
+ # <td>j</td>
88
+ # <td>k</td>
89
+ # <td>l</td>
90
+ # </tr>
91
+ # </tbody>
92
+ # <tfoot>
93
+ # <tr>
94
+ # <th>
95
+ # <th>x</th>
96
+ # <th>y</th>
97
+ # <th>z</th>
98
+ # </tr>
99
+ # </tfoot>
100
+ # </table>
101
+ #
102
+ # ==Special cases
103
+ #
104
+ # If headers or row or footers are nil, then this skips them.
105
+ #
106
+ # If footers==[] then this method will use a footers array
107
+ # with blanks that is the same length as the headers array.
108
+
109
+ def table(ops={})
110
+ text=ops[:text]
111
+ if !text
112
+ headers=ops[:headers]
113
+ footers=(defined?(ops[:footers]) ? ((ops[:footers]==true) ? Array.new(headers.size,'') : ops[:footers]) : false)
114
+ rows=ops[:rows]
115
+ text=((headers ? thead(headers) : '') + (rows ? tbody(rows) : '') + (footers ? tfoot(footers) : ''))
116
+ end
117
+ return "<table#{attrs_to_string(ops,[:id,:class])}>\n" + text + "</table>\n"
118
+ end
119
+
120
+
121
+ # Options:
122
+ # :texts
123
+ #
124
+ # Return:
125
+ # <table>
126
+ # texts[0]
127
+ # </table>
128
+ # <table>
129
+ # texts[0]
130
+ # </table>
131
+ # ...
132
+
133
+ def tables(ops={})
134
+ ops[:texts].map{|text| table(ops.merge(:text=>text))}.join
135
+ end
136
+
137
+
138
+ # Return:
139
+ # <thead>
140
+ # <th>header[0]</th>
141
+ # <th>header[1]</th>
142
+ # <th>header[2]</th>
143
+ # </thead>
144
+
145
+ def thead(headers)
146
+ "<thead>\n" + tr(ths(headers)) + "</thead>\n"
147
+ end
148
+
149
+
150
+ # Return:
151
+ # <th>header</th>
152
+
153
+ def th(header)
154
+ "<th>" + header.to_s + "</th>\n"
155
+ end
156
+
157
+
158
+ # Return:
159
+ # <th>header[0]</th>
160
+ # <th>header[1]</th>
161
+ # <th>header[2]</th>
162
+
163
+ def ths(headers)
164
+ headers.map{|x| th(x)}.join
165
+ end
166
+
167
+
168
+ # Return:
169
+ # <tbody>
170
+ # <tr>
171
+ # <td>row[0][0]</td>
172
+ # <td>row[0][1]</td>
173
+ # <td>row[0][2]</td>
174
+ # </tr>
175
+ # <tr>
176
+ # <td>row[1][0]</td>
177
+ # <td>row[1][1]</td>
178
+ # <td>row[1][2]</td>
179
+ # </tr>
180
+ # <tr>
181
+ # <td>row[2][0]</td>
182
+ # <td>row[2][1]</td>
183
+ # <td>row[2][2]</td>
184
+ # </tr>
185
+ # </tbody>
186
+
187
+ def tbody(rows)
188
+ "<tbody>\n" + trs(rows) + "</tbody>\n"
189
+ end
190
+
191
+
192
+ # Return:
193
+ # <tr>
194
+ # row
195
+ # </tr>
196
+ #
197
+ # Return when row is enumerable:
198
+ # <tr>
199
+ # <td>row[0]</td>
200
+ # <td>row[1]</td>
201
+ # <td>row[2]</td>
202
+ # </tr>
203
+
204
+ def tr(row)
205
+ "<tr>\n" + (row.is_a?(String) ? row : row.is_a?(Enumerable) ? tds(row) : row.to_s) + "</tr>\n"
206
+ end
207
+
208
+
209
+ # Return:
210
+ # <tr>
211
+ # <td>row[0][0]</td>
212
+ # <td>row[0][1]</td>
213
+ # <td>row[0][2]</td>
214
+ # </tr>
215
+ # <tr>
216
+ # <td>row[1][0]</td>
217
+ # <td>row[1][1]</td>
218
+ # <td>row[1][2]</td>
219
+ # </tr>
220
+ # <tr>
221
+ # <td>row[2][0]</td>
222
+ # <td>row[2][1]</td>
223
+ # <td>row[2][2]</td>
224
+ # </tr>
225
+
226
+ def trs(rows)
227
+ rows.map{|x| tr(x)}.join
228
+ end
229
+
230
+
231
+ # Return:
232
+ # <td>cell</td>
233
+
234
+ def td(cell)
235
+ "<td>" + cell.to_s + "</td>\n"
236
+ end
237
+
238
+
239
+ # Return:
240
+ # <td>cells[0]</td>
241
+ # <td>cells[1]</td>
242
+ # <td>cells[2]</td>
243
+
244
+ def tds(cells)
245
+ cells.map{|x| td(x)}.join
246
+ end
247
+
248
+
249
+ # Return:
250
+ # <tfoot>
251
+ # <th>
252
+ # <th>footer[0]</th>
253
+ # <th>footer[1]</th>
254
+ # <th>footer[2]</th>
255
+ # </tfoot>
256
+
257
+ def tfoot(footers)
258
+ "<tfoot>\n" + tr(ths(footers)) + "</tfoot>\n"
259
+ end
260
+
261
+
262
+ # Return:
263
+ # <ul>
264
+ # list
265
+ # </ul>
266
+ #
267
+ # Return when list is enumerable:
268
+ # <ul>
269
+ # <li>list[1]</li>
270
+ # <li>list[2]</li>
271
+ # <li>list[3]</li>
272
+ # </ul>
273
+
274
+ def ul(list)
275
+ "<ul>\n" + (list.is_a?(String) ? list : list.is_a?(Enumerable) ? lis(list) : list.to_s) + "</ul>\n"
276
+ end
277
+
278
+
279
+ # Return:
280
+ # <ul>
281
+ # <li>list[0][1]</li>
282
+ # <li>list[0][2]</li>
283
+ # <li>list[0][3]</li>
284
+ # </ul>
285
+ # <ul>
286
+ # <li>list[1][1]</li>
287
+ # <li>list[1][2]</li>
288
+ # <li>list[1][3]</li>
289
+ # </ul>
290
+ # <ul>
291
+ # <li>list[2][1]</li>
292
+ # <li>list[2][2]</li>
293
+ # <li>list[2][3]</li>
294
+ # </ul>
295
+
296
+ def uls(lists)
297
+ lists.map{|x| ul(x)}.join
298
+ end
299
+
300
+
301
+ # Return:
302
+ # <li>item</li>
303
+
304
+ def li(item)
305
+ "<li>" + item.to_s + "</li>\n"
306
+ end
307
+
308
+
309
+ # Return:
310
+ # <li>item[0]</li>
311
+ # <li>item[1]</li>
312
+ # <li>item[2]</li>
313
+
314
+ def lis(items)
315
+ items.map{|x| li(x)}.join
316
+ end
317
+
318
+
319
+
320
+ protected
321
+
322
+ # There's likely a better more-standard way to do this.
323
+ #
324
+ # This method is only used by the #table method.
325
+ #
326
+ # Return a string of the attributes suitable for HTML
327
+ #
328
+ # ==Example
329
+ # hash={:foo'=>'bar',:goo'=>'car',;hoo=>'dar'}
330
+ # attrs(hash) => ' foo="bar" goo="car" hoo="dar"'
331
+ #
332
+ # ==Example with selected keys
333
+ # hash={:foo'=>'bar',:goo'=>'car',;hoo=>'dar'}
334
+ # attrs(hash,[:foo,:hoo]) => ' foo="bar" hoo="dar"'
335
+
336
+ def attrs_to_string(ops,keys=nil)
337
+ return '' if !ops or ops=={}
338
+ keys||=ops.keys
339
+ return keys.inject(''){|s,k| s = (ops[k] ? s+=" #{k}=\"#{ops[k]}\"" : s)}
340
+ end
341
+
342
+ end
@@ -0,0 +1,97 @@
1
+ require 'test/unit'
2
+ require 'webget_ruby_html'
3
+
4
+ class Testing < Test::Unit::TestCase
5
+
6
+ include HTML
7
+
8
+ # Mock Inputs
9
+ CELLS=['a','b','c']
10
+ ITEMS=['a','b','c']
11
+ ROWS=[['a','b','c'],['d','e','f'],['g','h','i']]
12
+
13
+ def test_comment
14
+ assert_equal("<!--a-->",comment('a'))
15
+ end
16
+
17
+ def test_wrap
18
+ assert_equal("<b>a</b>",wrap('a','<b>'))
19
+ assert_equal("<b>a</b>",wrap('a','b'))
20
+ assert_equal("<b c d e>a</b>",wrap('a','b c d e'))
21
+ end
22
+
23
+ def test_li
24
+ assert_equal("<li>a</li>\n",li('a'))
25
+ end
26
+
27
+ def test_lis
28
+ assert_equal("<li>a</li>\n<li>b</li>\n<li>c</li>\n",lis(ITEMS))
29
+ end
30
+
31
+ def test_ul
32
+ assert_equal("<ul>\n<li>a</li>\n<li>b</li>\n<li>c</li>\n</ul>\n",ul(ITEMS))
33
+ end
34
+
35
+ def test_uls
36
+ assert_equal("<ul>\n<li>a</li>\n<li>b</li>\n<li>c</li>\n</ul>\n<ul>\n<li>a</li>\n<li>b</li>\n<li>c</li>\n</ul>\n",uls([ITEMS,ITEMS]))
37
+ end
38
+
39
+ def test_td
40
+ assert_equal("<td>a</td>\n",td('a'))
41
+ end
42
+
43
+ def test_tds
44
+ assert_equal("<td>a</td>\n<td>b</td>\n<td>c</td>\n",tds(CELLS))
45
+ end
46
+
47
+ def test_tr
48
+ assert_equal("<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n</tr>\n",tr(CELLS))
49
+ end
50
+
51
+ def test_trs
52
+ assert_equal("<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n</tr>\n<tr>\n<td>d</td>\n<td>e</td>\n<td>f</td>\n</tr>\n<tr>\n<td>g</td>\n<td>h</td>\n<td>i</td>\n</tr>\n",trs(ROWS))
53
+ end
54
+
55
+ def test_tbody
56
+ assert_equal("<tbody>\n<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n</tr>\n<tr>\n<td>d</td>\n<td>e</td>\n<td>f</td>\n</tr>\n<tr>\n<td>g</td>\n<td>h</td>\n<td>i</td>\n</tr>\n</tbody>\n",tbody(ROWS))
57
+ end
58
+
59
+ def test_ths
60
+ assert_equal("<th>a</th>\n<th>b</th>\n<th>c</th>\n",ths(CELLS))
61
+ end
62
+
63
+ def test_thead(headers)
64
+ assert_equal("<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>",thead(CELLS))
65
+ end
66
+
67
+ def test_tfoot
68
+ assert_equal("<tfoot>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</tfoot>\n",tfoot(CELLS))
69
+ end
70
+
71
+ def test_table_text
72
+ assert_equal("<table>\nfoo</table>\n",table(:text=>'foo'))
73
+ end
74
+
75
+ def test_table_text_and_attrs
76
+ assert_equal("<table id=\"foo\" class=\"bar\">\nfoo</table>\n",table(:id=>'foo',:class=>'bar',:text=>'foo'))
77
+ end
78
+
79
+ def test_tables
80
+ assert_equal("<table>\nfoo</table>\n<table>\nbar</table>\n",tables(:texts=>['foo','bar']))
81
+ end
82
+
83
+ def test_table_headers_body_footers
84
+ assert_equal(
85
+ "<table>\n"+
86
+ "<thead>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</thead>\n"+
87
+ "<tbody>\n<tr>\n<td>a</td>\n<td>b</td>\n<td>c</td>\n</tr>\n<tr>\n<td>d</td>\n<td>e</td>\n<td>f</td>\n</tr>\n<tr>\n<td>g</td>\n<td>h</td>\n<td>i</td>\n</tr>\n</tbody>\n"+
88
+ "<tfoot>\n<tr>\n<th>a</th>\n<th>b</th>\n<th>c</th>\n</tr>\n</tfoot>\n"+
89
+ "</table>\n",
90
+ table(:headers=>CELLS,:rows=>ROWS,:footers=>CELLS)
91
+ )
92
+ end
93
+
94
+ end
95
+
96
+
97
+
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ 5^�Zw�vR�
2
+ #u�Tt��Kp7G}r�.���!���o{=Z���e���UGJx��&fj�GCpk��]H��LY��8�HdWwM��g�q��Z�&/D A,��pZ��~pÎ��z�ϡ@�S`������
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webget_ruby_html
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.8
5
+ platform: ruby
6
+ authors:
7
+ - WebGet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDvDCCAyWgAwIBAgIJAIlSqEkDQaZIMA0GCSqGSIb3DQEBBQUAMIGbMQswCQYD
14
+ VQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5j
15
+ aXNjbzETMBEGA1UEChMKV2ViR2V0LmNvbTETMBEGA1UECxMKV2ViR2V0LmNvbTET
16
+ MBEGA1UEAxMKV2ViR2V0LmNvbTEgMB4GCSqGSIb3DQEJARYRd2ViZ2V0QHdlYmdl
17
+ dC5jb20wHhcNMDkwMjI2MTk0NDU4WhcNMTExMTIzMTk0NDU4WjCBmzELMAkGA1UE
18
+ BhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lz
19
+ Y28xEzARBgNVBAoTCldlYkdldC5jb20xEzARBgNVBAsTCldlYkdldC5jb20xEzAR
20
+ BgNVBAMTCldlYkdldC5jb20xIDAeBgkqhkiG9w0BCQEWEXdlYmdldEB3ZWJnZXQu
21
+ Y29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXCFYfW6hCQl0ToNjaMIXG
22
+ ZfPF6OoR20BO/Tg6V37qPi7gDSZ6vIC6Mxcs8LtEcju85cD9lnKKl/lo4S5/w9Ha
23
+ hGD2ZFFfbF8420X5Za5G2KuriS3GzRz7F5dKCTjb1NH9TPlgOc71bcrDmCwwtFJl
24
+ T+tdfBju0YxLSBiMXf4y5QIDAQABo4IBBDCCAQAwHQYDVR0OBBYEFHB1kXO/Xd4g
25
+ G+AJ2/wwh6JOWXzNMIHQBgNVHSMEgcgwgcWAFHB1kXO/Xd4gG+AJ2/wwh6JOWXzN
26
+ oYGhpIGeMIGbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQG
27
+ A1UEBxMNU2FuIEZyYW5jaXNjbzETMBEGA1UEChMKV2ViR2V0LmNvbTETMBEGA1UE
28
+ CxMKV2ViR2V0LmNvbTETMBEGA1UEAxMKV2ViR2V0LmNvbTEgMB4GCSqGSIb3DQEJ
29
+ ARYRd2ViZ2V0QHdlYmdldC5jb22CCQCJUqhJA0GmSDAMBgNVHRMEBTADAQH/MA0G
30
+ CSqGSIb3DQEBBQUAA4GBADzVXlwuff0/w3yK4LflGKKhtC3oChIrwmSyP6tk628N
31
+ BHokpc4Kz63xSXqzYTnBS7rFBwlYThtNalQeWmoUjGh3Z0ZR0JlhU0ln8899LuJ3
32
+ DXnLFY0cVuBnNDMOOFl8vk1qIcZjcTovhzgcixpG6Uk5qmUsKHRLQf4oQJx7TfLK
33
+ -----END CERTIFICATE-----
34
+
35
+ date: 2010-02-19 00:00:00 -08:00
36
+ default_executable:
37
+ dependencies: []
38
+
39
+ description:
40
+ email: webget@webget.com
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - README.rdoc
49
+ - LICENSE.txt
50
+ - lib/webget_ruby_html.rb
51
+ has_rdoc: true
52
+ homepage: http://webget.com/
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: "WebGet Ruby Gem: HTML helpers for tables, headers, rows, cells, lists, etc."
79
+ test_files:
80
+ - test/webget_ruby_html_test.rb
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ *�n�����S���SB�� w3��� ��x�ذ��v��{�-Jkzj%'a�_A?[�e�m��c��|i�d�d� ���������a�_>��2���žt�I�#�±C�?k��?�R��R�z���8u��G�