tagz 5.0.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README +90 -28
  2. data/a.rb +8 -6
  3. data/gemspec.rb +13 -7
  4. data/lib/tagz.rb +9 -3
  5. data/test/tagz.rb +14 -0
  6. metadata +2 -2
data/README CHANGED
@@ -14,13 +14,34 @@ DESCRIPTION
14
14
 
15
15
  tagz.rb is generates html, xml, or any sgml variant like a small ninja
16
16
  running across the backs of a herd of giraffes swatting of heads like a
17
- mark-up weedwacker. weighing in at less than 200 lines of code tagz.rb adds
18
- an html syntax to ruby that is both unobtrusive, safe, and available
17
+ mark-up weedwacker. weighing in at less than 300 lines of code tagz.rb adds
18
+ an html/xml/sgml syntax to ruby that is both unobtrusive, safe, and available
19
19
  globally to objects without the need for any builder or superfluous objects.
20
20
  tagz.rb is designed for applications that generate html to be able to do so
21
21
  easily in any context without heavyweight syntax or scoping issues, like a
22
22
  ninja sword through butter.
23
23
 
24
+ FEATURES
25
+
26
+ - use as a library or mixin
27
+
28
+ - simple, clean and consistent mark-up that is easy to visually
29
+ distinguish from other ruby methods
30
+
31
+ - auto-compatibility with rails/actionview
32
+
33
+ - ability to independently open and close tagz in markup
34
+
35
+ - intelligent auto-escaping of both attributes and content for both html
36
+ and xml
37
+
38
+ - validate your html/xml with 'ruby -c' syntax check
39
+
40
+ - generally bitchin
41
+
42
+ - no lame method_missing approach that prevents tagz like 'type' from being
43
+ generated
44
+
24
45
  RAILS
25
46
 
26
47
  in config/environment.rb
@@ -73,6 +94,14 @@ INSTALL
73
94
  gem install tagz
74
95
 
75
96
  HISTORY
97
+ 5.0.0
98
+ - introduce better escaping for attributes using xchar.rb approach
99
+ - indroduce smart escaping for content
100
+ - make Tagz.globally kick ass more hard
101
+ - note that this version is not backward compatibile if you were relying
102
+ on tagz never escaping any content should be an ok upgrade for most
103
+ applications
104
+
76
105
  4.6.0
77
106
  - fix a bug with self closing tagz that had crept in 1.0.0 -> 4.2.0. thx
78
107
  jeremy hinegardner
@@ -128,7 +157,8 @@ SAMPLES
128
157
  # the need for '<% rows.each do |row| %> ... <% row.each do |cell| %> '
129
158
  # madness and other types of logic to be coded in the templating language,
130
159
  # leaving templating to template engines and logic and looping to ruby -
131
- # unencumbered by extra funky syntax
160
+ # unencumbered by extra funky syntax. in rails tagz will automatically be
161
+ # available in your erb templates.
132
162
  #
133
163
 
134
164
  require 'tagz'
@@ -142,21 +172,15 @@ SAMPLES
142
172
  <html>
143
173
  <body>
144
174
  <%=
145
-
146
- if rows
147
-
148
- table_{
149
- rows.each do |row|
150
- tr_{
151
- row.each do |cell|
152
- td_{ cell }
153
- end
154
- }
155
- end
156
- }
157
-
158
- end
159
-
175
+ table_{
176
+ rows.each do |row|
177
+ tr_{
178
+ row.each do |cell|
179
+ td_{ cell }
180
+ end
181
+ }
182
+ end
183
+ }
160
184
  %>
161
185
  </body>
162
186
  </html>
@@ -217,13 +241,13 @@ SAMPLES
217
241
  html_
218
242
  body_(:class => 'ninja-like', :id => 'giraffe-slayer')
219
243
 
220
- tagz << "\n<!-- this is the header -->\n"
244
+ ___ "<!-- this is the header -->"
221
245
  }
222
246
  end
223
247
 
224
248
  def footer
225
249
  tagz{
226
- tagz << "\n<!-- this is the footer -->\n"
250
+ ___ "<!-- this is the footer -->"
227
251
 
228
252
  body_
229
253
  html_
@@ -282,20 +306,58 @@ SAMPLES
282
306
  # but can sometimes make reading the generated html a bit rough. of course
283
307
  # using tidy or the dom inspector in firebug obviates the issue; nevertheless
284
308
  # it's sometime nice to break things up a little. you can use 'tagz << "\n"'
285
- # or the special shorthand '__' to accomplish this
309
+ # or the special shorthand '__' or '___' to accomplish this
286
310
  #
287
311
 
288
312
  require 'tagz'
289
313
  include Tagz.globally
290
314
 
291
- p div_{
292
- span_{ true }
293
- __
294
- span_{ false } # hey ryan, i fixed this ;-)
295
- __
296
- }
315
+ html =
316
+ div_{
317
+ span_{ true }
318
+ __
319
+ span_{ false } # hey ryan, i fixed this ;-)
320
+ ___
321
+
322
+ ___ 'foo & escaped bar'
323
+ }
324
+
325
+ puts html
297
326
 
298
327
  ~ > ruby samples/f.rb
299
328
 
300
- "<div><span>true</span>\n<span>false</span>\n</div>"
329
+ <div><span>true</span>
330
+ <span>false</span>
331
+
332
+ foo & escaped bar
333
+ </div>
334
+
335
+
336
+ <========< samples/g.rb >========>
337
+
338
+ ~ > cat samples/g.rb
339
+
340
+ # tagz gives you low-level control of the output and makes even dashersized
341
+ # xml tagz easy enough to work with
342
+ #
343
+
344
+ require 'tagz'
345
+ include Tagz.globally
346
+
347
+ xml =
348
+ root_{
349
+ tagz__('foo-bar', :key => 'foo&bar'){ 'content' }
350
+
351
+ tagz__('bar-foo')
352
+ tagz.concat 'content'
353
+ tagz.concat tagz.escape('foo&bar')
354
+ __tagz('bar-foo')
355
+ }
356
+
357
+ puts xml
358
+
359
+
360
+ ~ > ruby samples/g.rb
361
+
362
+ <root><foo-bar key="foo&amp;bar">content</foo-bar><bar-foo>contentfoo&amp;bar</bar-foo></root>
301
363
 
data/a.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require 'tagz'
2
2
 
3
- include Tagz.privately
3
+ include Tagz.globally
4
4
 
5
- def bar
6
- missing
7
- end
5
+ c = Class.new{
6
+ include Tagz.globally
7
+ def a() tagz{ a_{ b(tagz); nil } } end
8
+ def b(doc) tagz(doc){ b_{ 'content' } } end
9
+ }.new
10
+
11
+ puts c.a
8
12
 
9
- puts div_{ 'foobar' }
10
- bar
data/gemspec.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  #! /usr/bin/env gem build
2
2
 
3
- lib, version = File::basename(File::dirname(File::expand_path(__FILE__))).split %r/-/, 2
4
-
5
3
  require 'rubygems'
6
4
 
7
5
  Gem::Specification::new do |spec|
@@ -14,10 +12,10 @@ Gem::Specification::new do |spec|
14
12
  end
15
13
  end
16
14
 
17
- spec.name = lib
18
- spec.version = version
15
+ spec.name = $lib
16
+ spec.version = $version
19
17
  spec.platform = Gem::Platform::RUBY
20
- spec.summary = lib
18
+ spec.summary = $lib
21
19
 
22
20
  spec.files = shiteless[Dir::glob("**/**")]
23
21
  spec.executables = shiteless[Dir::glob("bin/*")].map{|exe| File::basename exe}
@@ -25,7 +23,7 @@ Gem::Specification::new do |spec|
25
23
  spec.require_path = "lib"
26
24
 
27
25
  spec.has_rdoc = true #File::exist? "doc"
28
- spec.test_suite_file = "test/#{ lib }.rb" if File::file?("test/#{ lib }.rb")
26
+ spec.test_suite_file = "test/#{ $lib }.rb" if File::file?("test/#{ $lib }.rb")
29
27
  #spec.add_dependency 'lib', '>= version'
30
28
  #spec.add_dependency 'fattr'
31
29
 
@@ -34,5 +32,13 @@ Gem::Specification::new do |spec|
34
32
  spec.rubyforge_project = 'codeforpeople'
35
33
  spec.author = "Ara T. Howard"
36
34
  spec.email = "ara.t.howard@gmail.com"
37
- spec.homepage = "http://codeforpeople.com/lib/ruby/#{ lib }/"
35
+ spec.homepage = "http://codeforpeople.com/lib/ruby/#{ $lib }/"
38
36
  end
37
+
38
+
39
+ BEGIN{
40
+ Dir.chdir(File.dirname(__FILE__))
41
+ $lib = 'tagz'
42
+ Kernel.load "./lib/#{ $lib }.rb"
43
+ $version = Tagz.version
44
+ }
@@ -5,7 +5,7 @@ unless defined? Tagz
5
5
  Tagz::VERSION = [
6
6
  Tagz::VERSION_MAJOR = 5,
7
7
  Tagz::VERSION_MINOR = 0,
8
- Tagz::VERSION_TEENY = 0
8
+ Tagz::VERSION_TEENY = 1
9
9
  ].join('.')
10
10
  def Tagz.version() Tagz::VERSION end
11
11
  end
@@ -42,12 +42,18 @@ unless defined? Tagz
42
42
  if block
43
43
  size = tagz.size
44
44
  value = block.call(tagz)
45
- if NilClass === value
46
- tagz[-1] = "/>"
45
+
46
+ if value.nil?
47
+ unless(tagz.size > size)
48
+ tagz[-1] = "/>"
49
+ else
50
+ tagz.concat "</#{ name }>"
51
+ end
47
52
  else
48
53
  tagz << value.to_s unless(tagz.size > size)
49
54
  tagz.concat "</#{ name }>"
50
55
  end
56
+
51
57
  end
52
58
  else
53
59
  tagz << content.join
@@ -536,4 +536,18 @@ class TagzTest < Test::Unit::TestCase
536
536
 
537
537
  assert_raises(NoMethodError){ c.barfoo }
538
538
  end
539
+
540
+ def test_450
541
+ c = Class.new{
542
+ include Tagz.globally
543
+ def a() tagz{ a_{ b(tagz); nil } } end
544
+ def b(doc=nil) tagz(doc){ b_{ 'content' } } end
545
+ }.new
546
+
547
+ actual=nil
548
+ assert_nothing_raised{ actual=c.a }
549
+ expected = '<a><b>content</b></a>'
550
+ assert_equal expected, actual
551
+ assert_nothing_raised{ c.b }
552
+ end
539
553
  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: 5.0.0
4
+ version: 5.0.1
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-03-23 00:00:00 -06:00
12
+ date: 2009-03-25 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15