HTML-AutoTag 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0caa4fef9425233c5a1a220bd50232abfb982264
4
- data.tar.gz: 864955619111973f765e34217ac008de48e09afc
3
+ metadata.gz: eb544073abbb385cff430f587626b78727639715
4
+ data.tar.gz: 80d246a1d403ab03fabc9faa9e4c3f695c5f2060
5
5
  SHA512:
6
- metadata.gz: edd4ad4e0173a37124a390b69b35ad1d82377914a4d160b4cd8727d5a322de7e6e4c8bcfbedb48434aba65d07b2c14255e29ecf35cbf745a8b08220576e77e93
7
- data.tar.gz: 742447f30494ba9a30a7136f69b51a1b6a9cf301f0243a59f59ca5a13f6a4e3967285658ae7818209bf15b75e6566c53dbf1dadc3cbb248963401e9e3ee66340
6
+ metadata.gz: ed6c857557fa1eddfc4b13325d8ab19ba6d21591fb146058389a775d8893c0ed56c7d671ac292bf157c27f3471ae2400edeca6974349f245d736949705111f80
7
+ data.tar.gz: a7ed0a77eeabb55cf54ea827471b4dd69aab8bc5ed1812b250ba9a5a65e7b82818e4f21e96632db9b7cb9bf30a8a6b266f3a407aeb6d23bb42ac67510020ee15
data/.travis.yml CHANGED
@@ -1,8 +1,7 @@
1
1
  language: ruby
2
- install: gem install htmlentities
3
2
  rvm:
4
3
  - 2.1.0
5
4
  - jruby-19mode
6
5
  - 1.9.3
7
- # - jruby-18mode
8
- # - 1.8.7
6
+ - jruby-18mode
7
+ - 1.8.7
data/Changes CHANGED
@@ -1,5 +1,8 @@
1
1
  Revision history for html-autotag-ruby
2
2
 
3
+ 1.0.3
4
+ - replaced htmlentities dependency with HTML::Encoder
5
+
3
6
  1.0.2
4
7
  - added README for rubydoc.info
5
8
 
data/HTML-AutoTag.gemspec CHANGED
@@ -21,5 +21,4 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.3"
23
23
  spec.add_development_dependency "rake"
24
- spec.add_dependency "htmlentities"
25
24
  end
data/README CHANGED
@@ -1,14 +1,14 @@
1
- h1. HTML::AutoTag
2
- p. Just another HTML tag and attribute generator for ruby.
1
+ == HTML::AutoTag
2
+ Just another HTML tag and attribute generator for ruby.
3
3
 
4
- h1. Description
5
- p. Generate HTML tags and attributes with ease (HTML4, XHTML and HTML5). Handles rotating attributes.
4
+ == Description
5
+ Generate HTML tags and attributes with ease (HTML4, XHTML and HTML5). Handles rotating attributes.
6
6
 
7
- h1. Installation
8
- bc. gem install HTML-AutoTag
7
+ == Installation
8
+ gem install HTML-AutoTag
9
9
 
10
- h1. Synopsis
11
- bc. require 'HTML/AutoTag'
10
+ == Synopsis
11
+ require 'HTML/AutoTag'
12
12
  auto = HTML::AutoTag.new
13
13
 
14
14
  puts auto.tag( 'tag' => 'hr' )
@@ -21,19 +21,18 @@ bc. require 'HTML/AutoTag'
21
21
  'attr' => { 'reversed' => 'reversed' },
22
22
  'cdata' => %w{ 1 2 3 4 5 }.map{ |d| { 'tag' => 'li', 'attr' => attr, 'cdata' => d } }
23
23
  )
24
- end
25
24
 
26
- p. Also includes HTML::AutoAttr which provides rotating attributes:
27
- bc. require 'HTML/AutoAttr'
25
+ Also includes HTML::AutoAttr which provides rotating attributes:
26
+
27
+ require 'HTML/AutoAttr'
28
28
  attr = HTML::AutoAttr.new( { 'foo' => ['bar','baz','qux'] } )
29
29
  4.times { puts attr.to_s }
30
- end
31
30
 
32
- h1. Dependencies
31
+ == Dependencies
33
32
  * htmlentities
34
33
 
35
- h1. Methods
36
- p. With the exception of new, all methods return an HTML table as a string.
34
+ == Methods
35
+ With the exception of new, all methods return an HTML table as a string.
37
36
 
38
37
  * new( params )
39
38
  * encodes=(boolean)
@@ -52,14 +51,14 @@ p. With the exception of new, all methods return an HTML table as a string.
52
51
  Attribute names and values for the tag.
53
52
  * cdata=(string,hash,array)
54
53
  The value wrapped by the tag.
55
- * scalar - the string to be wrapped by the tag
56
- * hash - another tag with its own cdata and attributes
57
- * array - list of scalars or list of more hashes
54
+ * scalar - the string to be wrapped by the tag
55
+ * hash - another tag with its own cdata and attributes
56
+ * array - list of scalars or list of more hashes
58
57
 
59
- h1. More Complex Example
60
- p. The follow will render an HTML table with row that have alternating class names and cells that have alternating background colors:
58
+ == More Complex Example
59
+ The follow will render an HTML table with row that have alternating class names and cells that have alternating background colors:
61
60
 
62
- bc. require 'HTML/AutoTag'
61
+ require 'HTML/AutoTag'
63
62
  auto = HTML::AutoTag.new
64
63
 
65
64
  tr_attr = { 'class' => %w{ odd even } }
@@ -96,17 +95,17 @@ bc. require 'HTML/AutoTag'
96
95
  },
97
96
  ]
98
97
  )
99
- end
100
- p. See Spreadsheet-HTML for generating HTML tables.
101
98
 
102
- h1. License
103
- p. MIT
99
+ See Spreadsheet-HTML for generating HTML tables.
100
+
101
+ == License
102
+ MIT
104
103
 
105
- h1. Copyright
106
- p. (C) 2015 Jeff Anderson -- All Rights Reserved
104
+ == Copyright
105
+ (C) 2015 Jeff Anderson -- All Rights Reserved
107
106
 
108
- h1. Warranty
109
- p. This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
107
+ == Warranty
108
+ This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
110
109
 
111
- h1. Author
112
- p. Jeff Anderson jeffa@cpan.org
110
+ == Author
111
+ Jeff Anderson jeffa@cpan.org
data/lib/HTML/AutoTag.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "HTML/AutoTag/version"
2
2
  require "HTML/AutoAttr"
3
- require "htmlentities"
3
+ require "HTML/Encoder"
4
4
 
5
5
  module HTML
6
6
 
@@ -8,13 +8,15 @@ module HTML
8
8
 
9
9
  attr_accessor 'encodes', 'indent', 'level', 'sorted', 'newline'
10
10
 
11
+ # Defaults to empty string which produces no encoding.
12
+
11
13
  def initialize( params = {} )
12
- @encodes = params['encodes'] ? 1 : 0
14
+ @encodes = params.has_key?('encodes') ? params['encodes'] : ''
13
15
  @indent = params['indent'] || ''
14
16
  @level = params['level'] || 0
15
17
  @sorted = params['sorted'] ? 1 : 0
16
18
  @newline = params['indent'] ? "\n" : ''
17
- @encoder = HTMLEntities.new
19
+ @encoder = HTML::Encoder.new
18
20
  end
19
21
 
20
22
  def tag( params )
@@ -60,8 +62,7 @@ module HTML
60
62
  @level -= 1
61
63
 
62
64
  else
63
- rendered = cdata
64
- rendered = @encoder.encode( rendered ) if @encodes == 1
65
+ rendered = @encoder.encode( cdata, @encodes )
65
66
  no_post_indent = 1
66
67
  end
67
68
 
@@ -1,5 +1,5 @@
1
1
  module HTML
2
2
  class AutoTag
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
@@ -0,0 +1,319 @@
1
+ module HTML
2
+
3
+ class Encoder
4
+
5
+ def initialize()
6
+
7
+ @entity2char = {
8
+ 'amp' => '&', # ampersand
9
+ 'gt' => '>', # greater than
10
+ 'lt' => '<', # less than
11
+ 'quot' => '"', # double quote
12
+ 'apos' => "'", # single quote
13
+
14
+ # PUBLIC ISO 8879-1986//ENTITIES Added Latin 1//EN//HTML
15
+ 'AElig' => 198.chr, # capital AE diphthong (ligature)
16
+ 'Aacute' => 193.chr, # capital A, acute accent
17
+ 'Acirc' => 194.chr, # capital A, circumflex accent
18
+ 'Agrave' => 192.chr, # capital A, grave accent
19
+ 'Aring' => 197.chr, # capital A, ring
20
+ 'Atilde' => 195.chr, # capital A, tilde
21
+ 'Auml' => 196.chr, # capital A, dieresis or umlaut mark
22
+ 'Ccedil' => 199.chr, # capital C, cedilla
23
+ 'ETH' => 208.chr, # capital Eth, Icelandic
24
+ 'Eacute' => 201.chr, # capital E, acute accent
25
+ 'Ecirc' => 202.chr, # capital E, circumflex accent
26
+ 'Egrave' => 200.chr, # capital E, grave accent
27
+ 'Euml' => 203.chr, # capital E, dieresis or umlaut mark
28
+ 'Iacute' => 205.chr, # capital I, acute accent
29
+ 'Icirc' => 206.chr, # capital I, circumflex accent
30
+ 'Igrave' => 204.chr, # capital I, grave accent
31
+ 'Iuml' => 207.chr, # capital I, dieresis or umlaut mark
32
+ 'Ntilde' => 209.chr, # capital N, tilde
33
+ 'Oacute' => 211.chr, # capital O, acute accent
34
+ 'Ocirc' => 212.chr, # capital O, circumflex accent
35
+ 'Ograve' => 210.chr, # capital O, grave accent
36
+ 'Oslash' => 216.chr, # capital O, slash
37
+ 'Otilde' => 213.chr, # capital O, tilde
38
+ 'Ouml' => 214.chr, # capital O, dieresis or umlaut mark
39
+ 'THORN' => 222.chr, # capital THORN, Icelandic
40
+ 'Uacute' => 218.chr, # capital U, acute accent
41
+ 'Ucirc' => 219.chr, # capital U, circumflex accent
42
+ 'Ugrave' => 217.chr, # capital U, grave accent
43
+ 'Uuml' => 220.chr, # capital U, dieresis or umlaut mark
44
+ 'Yacute' => 221.chr, # capital Y, acute accent
45
+ 'aacute' => 225.chr, # small a, acute accent
46
+ 'acirc' => 226.chr, # small a, circumflex accent
47
+ 'aelig' => 230.chr, # small ae diphthong (ligature)
48
+ 'agrave' => 224.chr, # small a, grave accent
49
+ 'aring' => 229.chr, # small a, ring
50
+ 'atilde' => 227.chr, # small a, tilde
51
+ 'auml' => 228.chr, # small a, dieresis or umlaut mark
52
+ 'ccedil' => 231.chr, # small c, cedilla
53
+ 'eacute' => 233.chr, # small e, acute accent
54
+ 'ecirc' => 234.chr, # small e, circumflex accent
55
+ 'egrave' => 232.chr, # small e, grave accent
56
+ 'eth' => 240.chr, # small eth, Icelandic
57
+ 'euml' => 235.chr, # small e, dieresis or umlaut mark
58
+ 'iacute' => 237.chr, # small i, acute accent
59
+ 'icirc' => 238.chr, # small i, circumflex accent
60
+ 'igrave' => 236.chr, # small i, grave accent
61
+ 'iuml' => 239.chr, # small i, dieresis or umlaut mark
62
+ 'ntilde' => 241.chr, # small n, tilde
63
+ 'oacute' => 243.chr, # small o, acute accent
64
+ 'ocirc' => 244.chr, # small o, circumflex accent
65
+ 'ograve' => 242.chr, # small o, grave accent
66
+ 'oslash' => 248.chr, # small o, slash
67
+ 'otilde' => 245.chr, # small o, tilde
68
+ 'ouml' => 246.chr, # small o, dieresis or umlaut mark
69
+ 'szlig' => 223.chr, # small sharp s, German (sz ligature)
70
+ 'thorn' => 254.chr, # small thorn, Icelandic
71
+ 'uacute' => 250.chr, # small u, acute accent
72
+ 'ucirc' => 251.chr, # small u, circumflex accent
73
+ 'ugrave' => 249.chr, # small u, grave accent
74
+ 'uuml' => 252.chr, # small u, dieresis or umlaut mark
75
+ 'yacute' => 253.chr, # small y, acute accent
76
+ 'yuml' => 255.chr, # small y, dieresis or umlaut mark
77
+
78
+ # Some extra Latin 1 chars that are listed in the HTML3.2 draft (21-May-96)
79
+ 'copy' => 169.chr, # copyright sign
80
+ 'reg' => 174.chr, # registered sign
81
+ 'nbsp' => 160.chr, # non breaking space
82
+
83
+ # Additional ISO-8859/1 entities listed in rfc1866 (section 14)
84
+ 'iexcl' => 161.chr,
85
+ 'cent' => 162.chr,
86
+ 'pound' => 163.chr,
87
+ 'curren' => 164.chr,
88
+ 'yen' => 165.chr,
89
+ 'brvbar' => 166.chr,
90
+ 'sect' => 167.chr,
91
+ 'uml' => 168.chr,
92
+ 'ordf' => 170.chr,
93
+ 'laquo' => 171.chr,
94
+ 'not' => 172.chr, # not is a keyword in perl
95
+ 'shy' => 173.chr,
96
+ 'macr' => 175.chr,
97
+ 'deg' => 176.chr,
98
+ 'plusmn' => 177.chr,
99
+ 'sup1' => 185.chr,
100
+ 'sup2' => 178.chr,
101
+ 'sup3' => 179.chr,
102
+ 'acute' => 180.chr,
103
+ 'micro' => 181.chr,
104
+ 'para' => 182.chr,
105
+ 'middot' => 183.chr,
106
+ 'cedil' => 184.chr,
107
+ 'ordm' => 186.chr,
108
+ 'raquo' => 187.chr,
109
+ 'frac14' => 188.chr,
110
+ 'frac12' => 189.chr,
111
+ 'frac34' => 190.chr,
112
+ 'iquest' => 191.chr,
113
+ 'times' => 215.chr, # times is a keyword in perl
114
+ 'divide' => 247.chr,
115
+
116
+ =begin comment
117
+ 'OElig' => 338.chr,
118
+ 'oelig' => 339.chr,
119
+ 'Scaron' => 352.chr,
120
+ 'scaron' => 353.chr,
121
+ 'Yuml' => 376.chr,
122
+ 'fnof' => 402.chr,
123
+ 'circ' => 710.chr,
124
+ 'tilde' => 732.chr,
125
+ 'Alpha' => 913.chr,
126
+ 'Beta' => 914.chr,
127
+ 'Gamma' => 915.chr,
128
+ 'Delta' => 916.chr,
129
+ 'Epsilon' => 917.chr,
130
+ 'Zeta' => 918.chr,
131
+ 'Eta' => 919.chr,
132
+ 'Theta' => 920.chr,
133
+ 'Iota' => 921.chr,
134
+ 'Kappa' => 922.chr,
135
+ 'Lambda' => 923.chr,
136
+ 'Mu' => 924.chr,
137
+ 'Nu' => 925.chr,
138
+ 'Xi' => 926.chr,
139
+ 'Omicron' => 927.chr,
140
+ 'Pi' => 928.chr,
141
+ 'Rho' => 929.chr,
142
+ 'Sigma' => 931.chr,
143
+ 'Tau' => 932.chr,
144
+ 'Upsilon' => 933.chr,
145
+ 'Phi' => 934.chr,
146
+ 'Chi' => 935.chr,
147
+ 'Psi' => 936.chr,
148
+ 'Omega' => 937.chr,
149
+ 'alpha' => 945.chr,
150
+ 'beta' => 946.chr,
151
+ 'gamma' => 947.chr,
152
+ 'delta' => 948.chr,
153
+ 'epsilon' => 949.chr,
154
+ 'zeta' => 950.chr,
155
+ 'eta' => 951.chr,
156
+ 'theta' => 952.chr,
157
+ 'iota' => 953.chr,
158
+ 'kappa' => 954.chr,
159
+ 'lambda' => 955.chr,
160
+ 'mu' => 956.chr,
161
+ 'nu' => 957.chr,
162
+ 'xi' => 958.chr,
163
+ 'omicron' => 959.chr,
164
+ 'pi' => 960.chr,
165
+ 'rho' => 961.chr,
166
+ 'sigmaf' => 962.chr,
167
+ 'sigma' => 963.chr,
168
+ 'tau' => 964.chr,
169
+ 'upsilon' => 965.chr,
170
+ 'phi' => 966.chr,
171
+ 'chi' => 967.chr,
172
+ 'psi' => 968.chr,
173
+ 'omega' => 969.chr,
174
+ 'thetasym' => 977.chr,
175
+ 'upsih' => 978.chr,
176
+ 'piv' => 982.chr,
177
+ 'ensp' => 8194.chr,
178
+ 'emsp' => 8195.chr,
179
+ 'thinsp' => 8201.chr,
180
+ 'zwnj' => 8204.chr,
181
+ 'zwj' => 8205.chr,
182
+ 'lrm' => 8206.chr,
183
+ 'rlm' => 8207.chr,
184
+ 'ndash' => 8211.chr,
185
+ 'mdash' => 8212.chr,
186
+ 'lsquo' => 8216.chr,
187
+ 'rsquo' => 8217.chr,
188
+ 'sbquo' => 8218.chr,
189
+ 'ldquo' => 8220.chr,
190
+ 'rdquo' => 8221.chr,
191
+ 'bdquo' => 8222.chr,
192
+ 'dagger' => 8224.chr,
193
+ 'Dagger' => 8225.chr,
194
+ 'bull' => 8226.chr,
195
+ 'hellip' => 8230.chr,
196
+ 'permil' => 8240.chr,
197
+ 'prime' => 8242.chr,
198
+ 'Prime' => 8243.chr,
199
+ 'lsaquo' => 8249.chr,
200
+ 'rsaquo' => 8250.chr,
201
+ 'oline' => 8254.chr,
202
+ 'frasl' => 8260.chr,
203
+ 'euro' => 8364.chr,
204
+ 'image' => 8465.chr,
205
+ 'weierp' => 8472.chr,
206
+ 'real' => 8476.chr,
207
+ 'trade' => 8482.chr,
208
+ 'alefsym' => 8501.chr,
209
+ 'larr' => 8592.chr,
210
+ 'uarr' => 8593.chr,
211
+ 'rarr' => 8594.chr,
212
+ 'darr' => 8595.chr,
213
+ 'harr' => 8596.chr,
214
+ 'crarr' => 8629.chr,
215
+ 'lArr' => 8656.chr,
216
+ 'uArr' => 8657.chr,
217
+ 'rArr' => 8658.chr,
218
+ 'dArr' => 8659.chr,
219
+ 'hArr' => 8660.chr,
220
+ 'forall' => 8704.chr,
221
+ 'part' => 8706.chr,
222
+ 'exist' => 8707.chr,
223
+ 'empty' => 8709.chr,
224
+ 'nabla' => 8711.chr,
225
+ 'isin' => 8712.chr,
226
+ 'notin' => 8713.chr,
227
+ 'ni' => 8715.chr,
228
+ 'prod' => 8719.chr,
229
+ 'sum' => 8721.chr,
230
+ 'minus' => 8722.chr,
231
+ 'lowast' => 8727.chr,
232
+ 'radic' => 8730.chr,
233
+ 'prop' => 8733.chr,
234
+ 'infin' => 8734.chr,
235
+ 'ang' => 8736.chr,
236
+ 'and' => 8743.chr,
237
+ 'or' => 8744.chr,
238
+ 'cap' => 8745.chr,
239
+ 'cup' => 8746.chr,
240
+ 'int' => 8747.chr,
241
+ 'there4' => 8756.chr,
242
+ 'sim' => 8764.chr,
243
+ 'cong' => 8773.chr,
244
+ 'asymp' => 8776.chr,
245
+ 'ne' => 8800.chr,
246
+ 'equiv' => 8801.chr,
247
+ 'le' => 8804.chr,
248
+ 'ge' => 8805.chr,
249
+ 'sub' => 8834.chr,
250
+ 'sup' => 8835.chr,
251
+ 'nsub' => 8836.chr,
252
+ 'sube' => 8838.chr,
253
+ 'supe' => 8839.chr,
254
+ 'oplus' => 8853.chr,
255
+ 'otimes' => 8855.chr,
256
+ 'perp' => 8869.chr,
257
+ 'sdot' => 8901.chr,
258
+ 'lceil' => 8968.chr,
259
+ 'rceil' => 8969.chr,
260
+ 'lfloor' => 8970.chr,
261
+ 'rfloor' => 8971.chr,
262
+ 'lang' => 9001.chr,
263
+ 'rang' => 9002.chr,
264
+ 'loz' => 9674.chr,
265
+ 'spades' => 9824.chr,
266
+ 'clubs' => 9827.chr,
267
+ 'hearts' => 9829.chr,
268
+ 'diams' => 9830.chr,
269
+ =end
270
+ }
271
+
272
+ @char2entity = Hash[@entity2char.map { |k, v| [v, "&#{k};"] }]
273
+
274
+ for i in 0..255
275
+ unless @char2entity.has_key?( i.chr )
276
+ @char2entity[i.chr] = "&##{i};";
277
+ end
278
+ end
279
+
280
+ end
281
+
282
+ def encode( *args )
283
+
284
+ string = args[0]
285
+ chars = args[1].nil? ? '&<>"\'' : args[1]
286
+
287
+ #$chars =~ s,(?<!\\)([]/]),\\$1,g;
288
+ #$chars =~ s,(?<!\\)\\\z,\\\\,;
289
+ chars.to_s.each_char { |c|
290
+ string = string.to_s.gsub( c, @char2entity[c] )
291
+ }
292
+
293
+ return string
294
+
295
+ end
296
+
297
+ def decode()
298
+
299
+ end
300
+
301
+ end
302
+
303
+ end
304
+
305
+ =begin rdoc
306
+
307
+ == INSPIRATION
308
+
309
+ This code is heavily borrowed from Gisle Aas's CPAN module HTML::Entities.
310
+
311
+ == AUTHOR
312
+
313
+ Jeff Anderson, <jeffa at cpan.org>
314
+
315
+ == LICENSE AND COPYRIGHT
316
+
317
+ Copyright 2015 Jeff Anderson. (See License.md shipped with distro)
318
+
319
+ =end
data/t/01-load.rb CHANGED
@@ -5,6 +5,7 @@ class TestLoad < Test::Unit::TestCase
5
5
  def test_load
6
6
  assert_nothing_raised { require "HTML/AutoTag.rb" }
7
7
  assert_nothing_raised { require "HTML/AutoAttr.rb" }
8
+ assert_nothing_raised { require "HTML/Encoder.rb" }
8
9
  end
9
10
 
10
11
  end
data/t/02-tag.rb CHANGED
@@ -5,14 +5,14 @@ class TestTag < Test::Unit::TestCase
5
5
 
6
6
  def test_init
7
7
  auto = HTML::AutoTag.new
8
- assert_equal( 0, auto.encodes, "no args encodes correct" )
8
+ assert_equal( '', auto.encodes, "no args encodes correct" )
9
9
  assert_equal( '', auto.indent, "no args indent correct" )
10
10
  assert_equal( 0, auto.level, "no args level correct" )
11
11
  assert_equal( 0, auto.sorted, "no args sorted correct" )
12
12
  assert_equal( '', auto.newline, "no args newline correct" )
13
13
 
14
- auto = HTML::AutoTag.new( 'encodes' => 1, 'indent' => ' ' )
15
- assert_equal( 1, auto.encodes, "encodes set correct" )
14
+ auto = HTML::AutoTag.new( 'encodes' => nil, 'indent' => ' ' )
15
+ assert_equal( nil, auto.encodes, "encodes set correct" )
16
16
  assert_equal( ' ', auto.indent, "indent set correct" )
17
17
  assert_equal( "\n", auto.newline, "newline set correct" )
18
18
  end
@@ -44,7 +44,16 @@ class TestTag < Test::Unit::TestCase
44
44
  end
45
45
 
46
46
  def test_encodes
47
- auto = HTML::AutoTag.new( 'encodes' => 1 )
48
- assert_equal( '<p>&lt;0&gt;</p>', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "paragraph tag correct" )
47
+ auto = HTML::AutoTag.new( 'encodes' => '<>' )
48
+ assert_equal( '<p>&lt;0&gt;</p>', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "specific encodes work" )
49
+
50
+ auto = HTML::AutoTag.new( 'encodes' => nil )
51
+ assert_equal( '<p>&lt;&quot;0&apos;&amp;&gt;</p>', auto.tag( 'tag' => 'p', 'cdata' => '<"0\'&>' ), "default encodes work" )
52
+
53
+ auto = HTML::AutoTag.new( 'encodes' => 0 )
54
+ assert_equal( '<p><&#48;></p>', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "zero only encode work" )
55
+
56
+ auto = HTML::AutoTag.new
57
+ assert_equal( '<p><0></p>', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "no encoding works" )
49
58
  end
50
59
  end
data/t/05-encode.rb ADDED
@@ -0,0 +1,71 @@
1
+ require "test/unit"
2
+ require "HTML/Encoder"
3
+
4
+ class TestHTML_Encoder < Test::Unit::TestCase
5
+
6
+ def test_lower
7
+
8
+ encoder = HTML::Encoder.new()
9
+
10
+ assert_equal(
11
+ '&amp;&lt;&gt;&quot;&apos;',
12
+ encoder.encode( '&<>"\'' ),
13
+ 'default chars encoded correctly'
14
+ )
15
+
16
+ assert_equal(
17
+ '&<>"\'',
18
+ encoder.encode( '&<>"\'', '' ),
19
+ 'no encodes when chars is empty'
20
+ )
21
+ assert_equal(
22
+ 'h&#101;llo',
23
+ encoder.encode( 'hello', 'e' ),
24
+ 'requested chars encoded correctly'
25
+ )
26
+
27
+ assert_equal(
28
+ 'hello',
29
+ encoder.encode( 'hello' ),
30
+ 'no encodes when default chars requested'
31
+ )
32
+
33
+ assert_equal(
34
+ 'hello',
35
+ encoder.encode( 'hello', '' ),
36
+ 'no chars encoded when no chars requested'
37
+ )
38
+
39
+ deadbeef = 222.chr + 173.chr + 190.chr + 239.chr
40
+
41
+ assert_equal(
42
+ '&THORN;&shy;&frac34;&iuml;',
43
+ encoder.encode( deadbeef, deadbeef ),
44
+ 'hex codes encoded correctly'
45
+ )
46
+
47
+ assert_equal(
48
+ deadbeef,
49
+ encoder.encode( deadbeef ),
50
+ 'no encodes when default chars requested'
51
+ )
52
+
53
+ assert_equal(
54
+ deadbeef,
55
+ encoder.encode( deadbeef, '' ),
56
+ 'no encodes when no chars requested'
57
+ )
58
+
59
+ end
60
+
61
+ def test_container
62
+
63
+
64
+ end
65
+
66
+ def container( params = {} )
67
+ encoder = HTML::Encoder.new()
68
+ return encoder.encode( params['rendered'], params['encodes'] )
69
+ end
70
+
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HTML-AutoTag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeffa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-29 00:00:00.000000000 Z
11
+ date: 2015-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: htmlentities
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  description: Just another HTML tag generator for ruby.
56
42
  email:
57
43
  - jeffa@cpan.org
@@ -71,11 +57,13 @@ files:
71
57
  - lib/HTML/AutoAttr.rb
72
58
  - lib/HTML/AutoTag.rb
73
59
  - lib/HTML/AutoTag/version.rb
60
+ - lib/HTML/Encoder.rb
74
61
  - readme.md
75
62
  - t/01-load.rb
76
63
  - t/02-tag.rb
77
64
  - t/03-attrs.rb
78
65
  - t/04-tag-attrs.rb
66
+ - t/05-encode.rb
79
67
  homepage: https://github.com/jeffa/html-autotag-ruby
80
68
  licenses:
81
69
  - MIT