tagz 9.7.0 → 9.9.0

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 +39 -39
  2. data/tagz.gemspec +1 -1
  3. metadata +2 -2
@@ -7,7 +7,7 @@ unless defined? Tagz
7
7
  require 'cgi'
8
8
 
9
9
  def Tagz.version()
10
- '9.7.0'
10
+ '9.9.0'
11
11
  end
12
12
 
13
13
  def Tagz.description
@@ -218,28 +218,18 @@ unless defined? Tagz
218
218
  \A compact \Z
219
219
  ]iomx
220
220
 
221
- class HtmlSafe < ::String
222
- def html_safe() @html_safe ||= true end
223
- def html_safe?() html_safe end
224
- def html_safe=(value) @html_safe = !!value end
225
- end
226
-
227
- def Tagz.html_safe(*args, &block)
228
- if args.size == 1 and args.first.respond_to?(:html_safe?)
229
- return args.first
221
+ class HTMLSafe < ::String
222
+ def html_safe
223
+ self
230
224
  end
231
225
 
232
- if args.empty? and block.nil?
233
- Tagz.namespace(:HtmlSafe)
234
- else
235
- string = args.join
236
- string += block.call.to_s if block
237
- HtmlSafe.new(string)
226
+ def html_safe?
227
+ true
238
228
  end
239
229
  end
240
230
 
241
- class Document < ::String
242
- def Document.for other
231
+ class Document < HTMLSafe
232
+ def Document.for(other)
243
233
  Document === other ? other : Document.new(other.to_s)
244
234
  end
245
235
 
@@ -251,26 +241,21 @@ unless defined? Tagz
251
241
  alias_method 'write', 'concat'
252
242
  alias_method 'push', 'concat'
253
243
 
254
- def << string
255
- case string
256
- when Document
257
- super string.to_s
258
- else
259
- if string.respond_to?(:html_safe)
260
- super string.to_s
261
- else
262
- super Tagz.escape_content(string)
263
- end
244
+ def << obj
245
+ if obj.respond_to?(:html_safe?) and obj.html_safe?
246
+ super obj.to_s
247
+ else
248
+ super Tagz.escape_content(obj)
264
249
  end
250
+
265
251
  self
266
252
  end
267
253
 
268
- def concat(string)
269
- self << string
254
+ def concat(obj)
255
+ self << obj
270
256
  end
271
257
 
272
258
  def escape(string)
273
- return string if string.respond_to?(:html_safe)
274
259
  Tagz.escape(string)
275
260
  end
276
261
  alias_method 'h', 'escape'
@@ -299,14 +284,6 @@ unless defined? Tagz
299
284
  def to_str
300
285
  self
301
286
  end
302
-
303
- def html_safe
304
- self
305
- end
306
-
307
- def html_safe?
308
- true
309
- end
310
287
  end
311
288
  Tagz.singleton_class{ define_method(:document){ Tagz.namespace(:Document) } }
312
289
 
@@ -397,6 +374,29 @@ unless defined? Tagz
397
374
 
398
375
  # raw utils
399
376
  #
377
+ def Tagz.html_safe(*args, &block)
378
+ html_safe = namespace(:HTMLSafe)
379
+
380
+ if args.empty? and block.nil?
381
+ return html_safe
382
+ end
383
+
384
+ first = args.first
385
+
386
+ case
387
+ when first.is_a?(html_safe)
388
+ return first
389
+
390
+ when args.size == 1
391
+ string = first
392
+ html_safe.new(string)
393
+
394
+ else
395
+ string = [args, (block ? block.call : nil)].flatten.compact.join(' ')
396
+ html_safe.new(string)
397
+ end
398
+ end
399
+
400
400
  def Tagz.raw(*args, &block)
401
401
  Tagz.html_safe(*args, &block)
402
402
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "tagz"
6
- spec.version = "9.7.0"
6
+ spec.version = "9.9.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "tagz"
9
9
  spec.description = "\n 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\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: 9.7.0
4
+ version: 9.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-09 00:00:00.000000000 Z
12
+ date: 2013-07-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "\n tagz.rb is generates html, xml, or any sgml variant like
15
15
  a small ninja\n running across the backs of a herd of giraffes swatting of