tagz 7.2.1 → 7.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tagz.rb +162 -161
- data/tagz.gemspec +1 -1
- 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.
|
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
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
186
|
+
class Document < ::String
|
187
|
+
def Document.for other
|
188
|
+
Document === other ? other : Document.new(other.to_s)
|
189
|
+
end
|
189
190
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
191
|
+
def element
|
192
|
+
Tagz.element.new(*a, &b)
|
193
|
+
end
|
194
|
+
alias_method 'e', 'element'
|
194
195
|
|
195
|
-
|
196
|
-
|
196
|
+
alias_method 'write', 'concat'
|
197
|
+
alias_method 'push', 'concat'
|
197
198
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
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
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
end
|
210
|
-
#alias_method 'concat', '<<'
|
208
|
+
def concat string
|
209
|
+
self << string
|
210
|
+
end
|
211
|
+
#alias_method 'concat', '<<'
|
211
212
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
213
|
+
def escape(*strings)
|
214
|
+
Tagz.xchar.escape(strings.join)
|
215
|
+
end
|
216
|
+
alias_method 'h', 'escape'
|
216
217
|
|
217
|
-
|
218
|
-
|
219
|
-
|
218
|
+
def puts string
|
219
|
+
write "#{ string }\n"
|
220
|
+
end
|
220
221
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
222
|
+
def document
|
223
|
+
self
|
224
|
+
end
|
225
|
+
alias_method 'doc', 'document'
|
225
226
|
|
226
|
-
|
227
|
-
|
228
|
-
|
227
|
+
def + other
|
228
|
+
self.dup << other
|
229
|
+
end
|
229
230
|
|
230
|
-
|
231
|
-
|
232
|
-
|
231
|
+
def to_s
|
232
|
+
self
|
233
|
+
end
|
233
234
|
|
234
|
-
|
235
|
-
|
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
|
-
|
262
|
+
attr 'name'
|
262
263
|
|
263
|
-
|
264
|
-
|
265
|
-
|
264
|
+
def initialize name, *argv, &block
|
265
|
+
options = {}
|
266
|
+
content = []
|
266
267
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
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
|
-
|
277
|
-
|
277
|
+
content.push block.call if block
|
278
|
+
content.compact!
|
278
279
|
|
279
|
-
|
280
|
+
@name = name.to_s
|
280
281
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
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
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
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 => '&', # ampersand
|
327
|
+
60 => '<', # left angle bracket
|
328
|
+
62 => '>'} # 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
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
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
|
-
|
347
|
-
Tagz.singleton_class{ define_method(:xchar){ Tagz.namespace(:XChar) } }
|
348
|
+
Tagz.singleton_class{ define_method(:xchar){ Tagz.namespace(:XChar) } }
|
348
349
|
|
349
|
-
|
350
|
-
|
350
|
+
NoEscapeProc = lambda{|*values| values.join}
|
351
|
+
Tagz.singleton_class{ define_method(:no_escape_proc){ Tagz.namespace(:NoEscapeProc) } }
|
351
352
|
|
352
|
-
|
353
|
-
|
353
|
+
EscapeProc = lambda{|*values| Tagz.xchar.escape(values.join)}
|
354
|
+
Tagz.singleton_class{ define_method(:escape_proc){ Tagz.namespace(:EscapeProc) } }
|
354
355
|
|
355
|
-
|
356
|
-
|
356
|
+
module Globally; include Tagz; end
|
357
|
+
Tagz.singleton_class{ define_method(:globally){ Tagz.namespace(:Globally) } }
|
357
358
|
|
358
|
-
|
359
|
-
|
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.
|
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.
|
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-
|
12
|
+
date: 2009-11-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|