tagz 9.2.0 → 9.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/tagz.rb +41 -16
  2. data/tagz.gemspec +1 -1
  3. data/test/tagz_test.rb +10 -0
  4. metadata +2 -2
@@ -5,7 +5,7 @@ unless defined? Tagz
5
5
  #
6
6
  module Tagz
7
7
  def Tagz.version()
8
- '9.2.0'
8
+ '9.3.0'
9
9
  end
10
10
 
11
11
  def Tagz.description
@@ -52,23 +52,33 @@ unless defined? Tagz
52
52
  def tagz__(name, *argv, &block)
53
53
  options = argv.last.is_a?(Hash) ? argv.pop : {}
54
54
  content = argv
55
+ attributes = ''
55
56
 
56
57
  unless options.empty?
57
- attributes = ' ' <<
58
- options.map do |key, value|
59
- key = Tagz.escape_key(key)
60
- value = Tagz.escape_value(value)
61
- if value =~ %r/"/
62
- raise ArgumentError, value if value =~ %r/'/
63
- value = "'#{ value }'"
64
- else
65
- raise ArgumentError, value if value =~ %r/"/
66
- value = "\"#{ value }\""
67
- end
68
- [key, value].join('=')
69
- end.join(' ')
70
- else
71
- attributes = ''
58
+ booleans = []
59
+ options.each do |key, value|
60
+ if key.to_s =~ Tagz.namespace(:Boolean)
61
+ value = value.to_s =~ %r/\Atrue\Z/imox ? nil : "\"#{ key.to_s.downcase.strip }\""
62
+ booleans.push([key, value].compact)
63
+ next
64
+ end
65
+
66
+ key = Tagz.escape_key(key)
67
+ value = Tagz.escape_value(value)
68
+
69
+ if value =~ %r/"/
70
+ raise ArgumentError, value if value =~ %r/'/
71
+ value = "'#{ value }'"
72
+ else
73
+ raise ArgumentError, value if value =~ %r/"/
74
+ value = "\"#{ value }\""
75
+ end
76
+
77
+ attributes << ' ' << [key, value].join('=')
78
+ end
79
+ booleans.each do |kv|
80
+ attributes << ' ' << kv.compact.join('=')
81
+ end
72
82
  end
73
83
 
74
84
  tagz.push "<#{ name }#{ attributes }>"
@@ -190,6 +200,21 @@ unless defined? Tagz
190
200
  }
191
201
  }
192
202
 
203
+ Boolean = %r[
204
+ \A checked \Z |
205
+ \A selected \Z |
206
+ \A disabled \Z |
207
+ \A readonly \Z |
208
+ \A multiple \Z |
209
+ \A ismap \Z |
210
+ \A defer \Z |
211
+ \A declare \Z |
212
+ \A noresize \Z |
213
+ \A nowrap \Z |
214
+ \A noshade \Z |
215
+ \A compact \Z
216
+ ]iomx
217
+
193
218
  module HtmlSafe
194
219
  def html_safe() @html_safe ||= true end
195
220
  def html_safe?() html_safe end
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "tagz"
6
- spec.version = "9.2.0"
6
+ spec.version = "9.3.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"
@@ -713,4 +713,14 @@ class TagzTest < Test::Unit::TestCase
713
713
  end
714
714
  }
715
715
  end
716
+
717
+ def test_540
718
+ expected = '<foo checked><bar selected="selected">foobar</bar></foo>'
719
+ actual = tagz{
720
+ foo_('checked' => true){
721
+ bar_(:selected => :selected){ 'foobar' }
722
+ }
723
+ }
724
+ assert_equal expected, actual
725
+ end
716
726
  end
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.2.0
4
+ version: 9.3.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: 2012-01-16 00:00:00.000000000 Z
12
+ date: 2012-02-21 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