tagz 6.0.0 → 7.0.0

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.
Files changed (6) hide show
  1. data/README +22 -0
  2. data/lib/tagz.rb +41 -32
  3. data/readme.erb +22 -0
  4. data/tagz.gemspec +1 -1
  5. data/test/tagz.rb +9 -10
  6. metadata +2 -2
data/README CHANGED
@@ -97,6 +97,28 @@ URIS
97
97
  http://rubyforge.org/projects/codeforpeople
98
98
 
99
99
  HISTORY
100
+ 7.0.0
101
+ - * IMPORTANT * NOT BACKWARD COMPATIBLE (thus version bump)
102
+ the tagz functionality itself has not changed, but the defaults for
103
+ excaping have! now tagz will escape attributes, but NOT content, in the
104
+ default mode. you can easily configure something else with
105
+
106
+ Tagz.escape!(:content => true, :attributes => true)
107
+
108
+ which would be like saying
109
+
110
+ Tagz.xml_mode!
111
+
112
+ or
113
+
114
+ Tagz.escape!(:content => false, :attributes => true)
115
+
116
+ which would be like saying
117
+
118
+ Tagz.html_mode!
119
+
120
+ to repeat, the default is 'Tagz.html_mode!'
121
+
100
122
  6.0.0
101
123
  - reorganize lib to avoid dumping a few constants into the includee - aka
102
124
  don't absolutely minimize namespace pollution. there is now reason to
@@ -1,7 +1,7 @@
1
1
  unless defined? Tagz
2
2
 
3
3
  module Tagz
4
- def Tagz.version() '6.0.0' end
4
+ def Tagz.version() '7.0.0' end
5
5
 
6
6
  private
7
7
 
@@ -134,12 +134,11 @@ unless defined? Tagz
134
134
  end
135
135
  end
136
136
 
137
- # escape support
137
+ # escape utils
138
138
  #
139
139
  def Tagz.escapeHTML(*strings)
140
140
  XChar.escape(strings.join)
141
141
  end
142
-
143
142
  def Tagz.escape(*strings)
144
143
  XChar.escape(strings.join)
145
144
  end
@@ -150,66 +149,75 @@ unless defined? Tagz
150
149
  previous = @escape_attribute if defined?(@escape_attribute)
151
150
  unless args.empty? and block.nil?
152
151
  value = block ? block : args.shift
153
- @escape_attribute = value ? value.to_proc : NoEscape
152
+ value = Escape if value==true
153
+ value = NoEscape if(value==false or value==nil)
154
+ @escape_attribute = value.to_proc
154
155
  return previous
155
156
  end
156
157
  @escape_attribute
157
158
  end
158
-
159
159
  def Tagz.escape_attributes!(*args, &block)
160
160
  Tagz.escape_attribute!(*args, &block)
161
161
  end
162
-
163
162
  def Tagz.escape_attribute(value)
164
163
  @escape_attribute.call(value.to_s)
165
164
  end
166
165
 
167
- # default escape
168
- #
169
- escape_attribute!{|value| XChar.escape(value)}
170
-
171
166
  # support for configuring content escaping
172
167
  #
173
168
  def Tagz.escape_content!(*args, &block)
174
169
  previous = @escape_content if defined?(@escape_content)
175
170
  unless args.empty? and block.nil?
176
171
  value = block ? block : args.shift
177
- @escape_content = value ? value.to_proc : NoEscape
172
+ value = Escape if value==true
173
+ value = NoEscape if(value==false or value==nil)
174
+ @escape_content = value.to_proc
178
175
  return previous
179
176
  end
180
177
  @escape_content
181
178
  end
182
-
183
179
  def Tagz.escape_contents!(*args, &block)
184
180
  Tagz.escape_content!(*args, &block)
185
181
  end
186
-
187
182
  def Tagz.escape_content(value)
188
183
  @escape_content.call(value.to_s)
189
184
  end
190
185
 
191
- # default escape
192
- #
193
- escape_content!{|value| XChar.escape(value)}
194
-
195
- # make tagz escape nothing
186
+ # configure tagz escaping
196
187
  #
188
+ def Tagz.escape!(options = {})
189
+ options = {:attributes => options, :content => options} unless options.is_a?(Hash)
190
+ escape_attributes = options[:attributes]||options['attributes']
191
+ escape_content = options[:content]||options['content']
192
+ Tagz.escape_attributes!(!!escape_attributes)
193
+ Tagz.escape_content!(!!escape_content)
194
+ end
197
195
  def Tagz.i_know_what_the_hell_i_am_doing!
198
- Tagz.escape_attributes! false
199
- Tagz.escape_content! false
196
+ escape!(false)
200
197
  end
201
-
202
- # make tagz escape everything
203
- #
204
198
  def Tagz.i_do_not_know_what_the_hell_i_am_doing!
205
- escape_attribute!{|value| XChar.escape(value)}
206
- escape_content!{|value| XChar.escape(value)}
199
+ escape!(true)
200
+ end
201
+ def Tagz.xml_mode!
202
+ Tagz.escape!(
203
+ :attributes => true,
204
+ :content => true
205
+ )
207
206
  end
207
+ def Tagz.html_mode!
208
+ Tagz.escape!(
209
+ :attributes => true,
210
+ :content => false
211
+ )
212
+ end
213
+
208
214
 
215
+
216
+ # module shortcuts - namespace preserving
217
+ #
209
218
  def Tagz.globally
210
219
  Globally
211
220
  end
212
-
213
221
  def Tagz.privately
214
222
  Privately
215
223
  end
@@ -378,7 +386,8 @@ unless defined? Tagz
378
386
  end
379
387
  end
380
388
 
381
- NoEscape = lambda{|v|v}
389
+ NoEscape = lambda{|*values| values.join}
390
+ Escape = lambda{|*values| XChar.escape(values.join)}
382
391
 
383
392
  module Globally; include ::Tagz; end
384
393
  module Privately; include ::Tagz; end
@@ -391,20 +400,20 @@ unless defined? Tagz
391
400
  TagzConstants.const_get(const)
392
401
  end
393
402
 
403
+ # allow access to instance methods via module handle
404
+ #
394
405
  %w( tagz tagz__ __tagz method_missing ).each{|m| module_function(m)}
395
406
  end
396
407
 
397
408
  def Tagz *argv, &block
398
- if argv.empty? and block.nil?
399
- ::Tagz
400
- else
401
- Tagz.tagz(*argv, &block)
402
- end
409
+ (argv.empty? and block.nil?) ? ::Tagz : Tagz.tagz(*argv, &block)
403
410
  end
404
411
 
405
412
  if defined?(Rails)
413
+ _=ActionView,ActionView::Base,ActionController,ActionController::Base
406
414
  ActionView::Base.send(:include, Tagz.globally)
407
415
  ActionController::Base.send(:include, Tagz)
408
416
  end
409
417
 
418
+ Tagz.html_mode!
410
419
  end
data/readme.erb CHANGED
@@ -97,6 +97,28 @@ URIS
97
97
  http://rubyforge.org/projects/codeforpeople
98
98
 
99
99
  HISTORY
100
+ 7.0.0
101
+ - * IMPORTANT * NOT BACKWARD COMPATIBLE (thus version bump)
102
+ the tagz functionality itself has not changed, but the defaults for
103
+ excaping have! now tagz will escape attributes, but NOT content, in the
104
+ default mode. you can easily configure something else with
105
+
106
+ Tagz.escape!(:content => true, :attributes => true)
107
+
108
+ which would be like saying
109
+
110
+ Tagz.xml_mode!
111
+
112
+ or
113
+
114
+ Tagz.escape!(:content => false, :attributes => true)
115
+
116
+ which would be like saying
117
+
118
+ Tagz.html_mode!
119
+
120
+ to repeat, the default is 'Tagz.html_mode!'
121
+
100
122
  6.0.0
101
123
  - reorganize lib to avoid dumping a few constants into the includee - aka
102
124
  don't absolutely minimize namespace pollution. there is now reason to
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "tagz"
6
- spec.version = "6.0.0"
6
+ spec.version = "7.0.0"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "tagz"
9
9
 
@@ -474,8 +474,7 @@ class TagzTest < Test::Unit::TestCase
474
474
  end
475
475
 
476
476
  def test_390
477
- expected = '<div class="bar&amp;foo&gt;">foo&amp;bar&gt;</div>'
478
- # actual = tagz{ div_(:class => 'bar&foo>'){|t| t.h('foo&bar>') } }
477
+ expected = '<div class="bar&amp;foo&gt;">foo&bar></div>'
479
478
  actual = tagz{ div_(:class => 'bar&foo>'){ 'foo&bar>' } }
480
479
  assert_equal expected, actual
481
480
 
@@ -485,7 +484,7 @@ class TagzTest < Test::Unit::TestCase
485
484
  end
486
485
 
487
486
  def test_400
488
- expected = '<div><span>foo&amp;bar</span></div>'
487
+ expected = '<div><span>foo&bar</span></div>'
489
488
  actual = tagz{ div_{ span_{ 'foo&bar' } } }
490
489
  assert_equal expected, actual
491
490
  end
@@ -603,27 +602,27 @@ class TagzTest < Test::Unit::TestCase
603
602
 
604
603
  actual = nil
605
604
  assert_nothing_raised{ actual=c.a}
606
- expected = %(<div>a&gt;b</div>)
605
+ expected = %(<div>a>b</div>)
607
606
  assert_equal expected, actual
608
607
 
609
- original = Tagz.escape_content! false
608
+ original = Tagz.escape_content!(true)
610
609
  assert original
611
610
  actual = nil
612
611
  assert_nothing_raised{ actual=c.a}
613
- expected = %(<div>a>b</div>)
612
+ expected = %(<div>a&gt;b</div>)
614
613
  assert_equal expected, actual
615
614
 
616
- upcased = Tagz.escape_content! lambda{|value| original.call(value).upcase}
615
+ upcased = Tagz.escape_content!(lambda{|value| original.call(value).upcase})
617
616
  assert upcased
618
617
  actual = nil
619
618
  assert_nothing_raised{ actual=c.a}
620
- expected = %(<div>A&GT;B</div>)
619
+ expected = %(<div>A>B</div>)
621
620
  assert_equal expected, actual
622
621
 
623
- Tagz.escape_content! original
622
+ Tagz.escape_content!(original)
624
623
  actual = nil
625
624
  assert_nothing_raised{ actual=c.a}
626
- expected = %(<div>a&gt;b</div>)
625
+ expected = %(<div>a>b</div>)
627
626
  assert_equal expected, actual
628
627
  ensure
629
628
  Tagz.escape_content!(original)
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: 6.0.0
4
+ version: 7.0.0
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-07-25 00:00:00 -06:00
12
+ date: 2009-07-26 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15