tagz 7.2.1 → 7.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/tagz.rb +162 -161
  2. data/tagz.gemspec +1 -1
  3. metadata +2 -2
data/lib/tagz.rb CHANGED
@@ -4,7 +4,7 @@ unless defined? Tagz
4
4
  #
5
5
  module Tagz
6
6
  def Tagz.version()
7
- '7.2.1'
7
+ '7.2.2'
8
8
  end
9
9
 
10
10
  def Tagz.description()
@@ -169,196 +169,197 @@ unless defined? Tagz
169
169
 
170
170
  # hide away our own shit to minimize namespace pollution
171
171
  #
172
- module Namespace
173
- namespace = self
174
-
175
- Tagz.singleton_class{
176
- define_method(:namespace){ |*args|
177
- if args.empty?
178
- namespace
179
- else
180
- namespace.const_get(args.first.to_sym)
181
- end
172
+ class << Tagz
173
+ module Namespace
174
+ namespace = self
175
+
176
+ Tagz.singleton_class{
177
+ define_method(:namespace){ |*args|
178
+ if args.empty?
179
+ namespace
180
+ else
181
+ namespace.const_get(args.first.to_sym)
182
+ end
183
+ }
182
184
  }
183
- }
184
185
 
185
- class Document < ::String
186
- def Document.for other
187
- Document === other ? other : Document.new(other.to_s)
188
- end
186
+ class Document < ::String
187
+ def Document.for other
188
+ Document === other ? other : Document.new(other.to_s)
189
+ end
189
190
 
190
- def element
191
- Tagz.element.new(*a, &b)
192
- end
193
- alias_method 'e', 'element'
191
+ def element
192
+ Tagz.element.new(*a, &b)
193
+ end
194
+ alias_method 'e', 'element'
194
195
 
195
- alias_method 'write', 'concat'
196
- alias_method 'push', 'concat'
196
+ alias_method 'write', 'concat'
197
+ alias_method 'push', 'concat'
197
198
 
198
- def << string
199
- case string
200
- when Document
201
- super string.to_s
202
- else
203
- super Tagz.escape_content(string)
199
+ def << string
200
+ case string
201
+ when Document
202
+ super string.to_s
203
+ else
204
+ super Tagz.escape_content(string)
205
+ end
206
+ self
204
207
  end
205
- self
206
- end
207
- def concat string
208
- self << string
209
- end
210
- #alias_method 'concat', '<<'
208
+ def concat string
209
+ self << string
210
+ end
211
+ #alias_method 'concat', '<<'
211
212
 
212
- def escape(*strings)
213
- Tagz.xchar.escape(strings.join)
214
- end
215
- alias_method 'h', 'escape'
213
+ def escape(*strings)
214
+ Tagz.xchar.escape(strings.join)
215
+ end
216
+ alias_method 'h', 'escape'
216
217
 
217
- def puts string
218
- write "#{ string }\n"
219
- end
218
+ def puts string
219
+ write "#{ string }\n"
220
+ end
220
221
 
221
- def document
222
- self
223
- end
224
- alias_method 'doc', 'document'
222
+ def document
223
+ self
224
+ end
225
+ alias_method 'doc', 'document'
225
226
 
226
- def + other
227
- self.dup << other
228
- end
227
+ def + other
228
+ self.dup << other
229
+ end
229
230
 
230
- def to_s
231
- self
232
- end
231
+ def to_s
232
+ self
233
+ end
233
234
 
234
- def to_str
235
- self
236
- end
237
- end
238
- Tagz.singleton_class{ define_method(:document){ Tagz.namespace(:Document) } }
239
-
240
- class Element < ::String
241
- def Element.attributes options
242
- unless options.empty?
243
- ' ' <<
244
- options.map do |key, value|
245
- key = Tagz.escape_attribute(key)
246
- value = Tagz.escape_attribute(value)
247
- if value =~ %r/"/
248
- raise ArgumentError, value if value =~ %r/'/
249
- value = "'#{ value }'"
250
- else
251
- raise ArgumentError, value if value =~ %r/"/
252
- value = "\"#{ value }\""
253
- end
254
- [key, value].join('=')
255
- end.join(' ')
256
- else
257
- ''
235
+ def to_str
236
+ self
258
237
  end
259
238
  end
239
+ Tagz.singleton_class{ define_method(:document){ Tagz.namespace(:Document) } }
240
+
241
+ class Element < ::String
242
+ def Element.attributes options
243
+ unless options.empty?
244
+ ' ' <<
245
+ options.map do |key, value|
246
+ key = Tagz.escape_attribute(key)
247
+ value = Tagz.escape_attribute(value)
248
+ if value =~ %r/"/
249
+ raise ArgumentError, value if value =~ %r/'/
250
+ value = "'#{ value }'"
251
+ else
252
+ raise ArgumentError, value if value =~ %r/"/
253
+ value = "\"#{ value }\""
254
+ end
255
+ [key, value].join('=')
256
+ end.join(' ')
257
+ else
258
+ ''
259
+ end
260
+ end
260
261
 
261
- attr 'name'
262
+ attr 'name'
262
263
 
263
- def initialize name, *argv, &block
264
- options = {}
265
- content = []
264
+ def initialize name, *argv, &block
265
+ options = {}
266
+ content = []
266
267
 
267
- argv.each do |arg|
268
- case arg
269
- when Hash
270
- options.update arg
271
- else
272
- content.push arg
268
+ argv.each do |arg|
269
+ case arg
270
+ when Hash
271
+ options.update arg
272
+ else
273
+ content.push arg
274
+ end
273
275
  end
274
- end
275
276
 
276
- content.push block.call if block
277
- content.compact!
277
+ content.push block.call if block
278
+ content.compact!
278
279
 
279
- @name = name.to_s
280
+ @name = name.to_s
280
281
 
281
- if content.empty?
282
- replace "<#{ @name }#{ Element.attributes options }>"
283
- else
284
- replace "<#{ @name }#{ Element.attributes options }>#{ content.join }</#{ name }>"
282
+ if content.empty?
283
+ replace "<#{ @name }#{ Element.attributes options }>"
284
+ else
285
+ replace "<#{ @name }#{ Element.attributes options }>#{ content.join }</#{ name }>"
286
+ end
285
287
  end
286
288
  end
287
- end
288
- Tagz.singleton_class{ define_method(:element){ Tagz.namespace(:Element) } }
289
-
290
- module XChar
291
- # http://intertwingly.net/stories/2004/04/14/i18n.html#CleaningWindows
292
- #
293
- CP1252 = {
294
- 128 => 8364, # euro sign
295
- 130 => 8218, # single low-9 quotation mark
296
- 131 => 402, # latin small letter f with hook
297
- 132 => 8222, # double low-9 quotation mark
298
- 133 => 8230, # horizontal ellipsis
299
- 134 => 8224, # dagger
300
- 135 => 8225, # double dagger
301
- 136 => 710, # modifier letter circumflex accent
302
- 137 => 8240, # per mille sign
303
- 138 => 352, # latin capital letter s with caron
304
- 139 => 8249, # single left-pointing angle quotation mark
305
- 140 => 338, # latin capital ligature oe
306
- 142 => 381, # latin capital letter z with caron
307
- 145 => 8216, # left single quotation mark
308
- 146 => 8217, # right single quotation mark
309
- 147 => 8220, # left double quotation mark
310
- 148 => 8221, # right double quotation mark
311
- 149 => 8226, # bullet
312
- 150 => 8211, # en dash
313
- 151 => 8212, # em dash
314
- 152 => 732, # small tilde
315
- 153 => 8482, # trade mark sign
316
- 154 => 353, # latin small letter s with caron
317
- 155 => 8250, # single right-pointing angle quotation mark
318
- 156 => 339, # latin small ligature oe
319
- 158 => 382, # latin small letter z with caron
320
- 159 => 376} # latin capital letter y with diaeresis
321
-
322
- # http://www.w3.org/TR/REC-xml/#dt-chardata
323
- #
324
- PREDEFINED = {
325
- 38 => '&amp;', # ampersand
326
- 60 => '&lt;', # left angle bracket
327
- 62 => '&gt;'} # right angle bracket
328
-
329
- # http://www.w3.org/TR/REC-xml/#charsets
330
- #
331
- VALID = [[0x9, 0xA, 0xD], (0x20..0xD7FF), (0xE000..0xFFFD), (0x10000..0x10FFFF)]
332
-
333
- def XChar.escape(string)
334
- string.unpack('U*').map{|n| xchr(n)}.join # ASCII, UTF-8
335
- rescue
336
- string.unpack('C*').map{|n| xchr(n)}.join # ISO-8859-1, WIN-1252
337
- end
289
+ Tagz.singleton_class{ define_method(:element){ Tagz.namespace(:Element) } }
290
+
291
+ module XChar
292
+ # http://intertwingly.net/stories/2004/04/14/i18n.html#CleaningWindows
293
+ #
294
+ CP1252 = {
295
+ 128 => 8364, # euro sign
296
+ 130 => 8218, # single low-9 quotation mark
297
+ 131 => 402, # latin small letter f with hook
298
+ 132 => 8222, # double low-9 quotation mark
299
+ 133 => 8230, # horizontal ellipsis
300
+ 134 => 8224, # dagger
301
+ 135 => 8225, # double dagger
302
+ 136 => 710, # modifier letter circumflex accent
303
+ 137 => 8240, # per mille sign
304
+ 138 => 352, # latin capital letter s with caron
305
+ 139 => 8249, # single left-pointing angle quotation mark
306
+ 140 => 338, # latin capital ligature oe
307
+ 142 => 381, # latin capital letter z with caron
308
+ 145 => 8216, # left single quotation mark
309
+ 146 => 8217, # right single quotation mark
310
+ 147 => 8220, # left double quotation mark
311
+ 148 => 8221, # right double quotation mark
312
+ 149 => 8226, # bullet
313
+ 150 => 8211, # en dash
314
+ 151 => 8212, # em dash
315
+ 152 => 732, # small tilde
316
+ 153 => 8482, # trade mark sign
317
+ 154 => 353, # latin small letter s with caron
318
+ 155 => 8250, # single right-pointing angle quotation mark
319
+ 156 => 339, # latin small ligature oe
320
+ 158 => 382, # latin small letter z with caron
321
+ 159 => 376} # latin capital letter y with diaeresis
322
+
323
+ # http://www.w3.org/TR/REC-xml/#dt-chardata
324
+ #
325
+ PREDEFINED = {
326
+ 38 => '&amp;', # ampersand
327
+ 60 => '&lt;', # left angle bracket
328
+ 62 => '&gt;'} # right angle bracket
329
+
330
+ # http://www.w3.org/TR/REC-xml/#charsets
331
+ #
332
+ VALID = [[0x9, 0xA, 0xD], (0x20..0xD7FF), (0xE000..0xFFFD), (0x10000..0x10FFFF)]
333
+
334
+ def XChar.escape(string)
335
+ string.unpack('U*').map{|n| xchr(n)}.join # ASCII, UTF-8
336
+ rescue
337
+ string.unpack('C*').map{|n| xchr(n)}.join # ISO-8859-1, WIN-1252
338
+ end
338
339
 
339
- def XChar.xchr(n)
340
- (@xchr ||= {})[n] ||= ((
341
- n = XChar::CP1252[n] || n
342
- n = 42 unless XChar::VALID.find{|range| range.include? n}
343
- XChar::PREDEFINED[n] or (n<128 ? n.chr : "&##{n};")
344
- ))
340
+ def XChar.xchr(n)
341
+ (@xchr ||= {})[n] ||= ((
342
+ n = XChar::CP1252[n] || n
343
+ n = 42 unless XChar::VALID.find{|range| range.include? n}
344
+ XChar::PREDEFINED[n] or (n<128 ? n.chr : "&##{n};")
345
+ ))
346
+ end
345
347
  end
346
- end
347
- Tagz.singleton_class{ define_method(:xchar){ Tagz.namespace(:XChar) } }
348
+ Tagz.singleton_class{ define_method(:xchar){ Tagz.namespace(:XChar) } }
348
349
 
349
- NoEscapeProc = lambda{|*values| values.join}
350
- Tagz.singleton_class{ define_method(:no_escape_proc){ Tagz.namespace(:NoEscapeProc) } }
350
+ NoEscapeProc = lambda{|*values| values.join}
351
+ Tagz.singleton_class{ define_method(:no_escape_proc){ Tagz.namespace(:NoEscapeProc) } }
351
352
 
352
- EscapeProc = lambda{|*values| Tagz.xchar.escape(values.join)}
353
- Tagz.singleton_class{ define_method(:escape_proc){ Tagz.namespace(:EscapeProc) } }
353
+ EscapeProc = lambda{|*values| Tagz.xchar.escape(values.join)}
354
+ Tagz.singleton_class{ define_method(:escape_proc){ Tagz.namespace(:EscapeProc) } }
354
355
 
355
- module Globally; include Tagz; end
356
- Tagz.singleton_class{ define_method(:globally){ Tagz.namespace(:Globally) } }
356
+ module Globally; include Tagz; end
357
+ Tagz.singleton_class{ define_method(:globally){ Tagz.namespace(:Globally) } }
357
358
 
358
- module Privately; include Tagz; end
359
- Tagz.singleton_class{ define_method(:privately){ Tagz.namespace(:Privately) } }
359
+ module Privately; include Tagz; end
360
+ Tagz.singleton_class{ define_method(:privately){ Tagz.namespace(:Privately) } }
361
+ end
360
362
  end
361
- remove_const(:Namespace)
362
363
 
363
364
  # escape utils
364
365
  #
data/tagz.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "tagz"
6
- spec.version = "7.2.1"
6
+ spec.version = "7.2.2"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "tagz"
9
9
  spec.description = " tagz.rb is generates html, xml, or any sgml variant like a small ninja\n running across the backs of a herd of giraffes swatting of heads like\n a mark-up weedwacker. weighing in at less than 300 lines of code\n tagz.rb adds an html/xml/sgml syntax to ruby that is both unobtrusive,\n safe, and available globally to objects without the need for any\n builder or superfluous objects. tagz.rb is designed for applications\n that generate html to be able to do so easily in any context without\n heavyweight syntax or scoping issues, like a ninja sword through\n butter.\n"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagz
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.1
4
+ version: 7.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-29 00:00:00 -06:00
12
+ date: 2009-11-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15