ahoward-tagz 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,387 @@
1
+ NAME
2
+
3
+ tagz.rb
4
+
5
+ SYNOPSIS
6
+
7
+ require Tagz
8
+
9
+ include Tagz.globally
10
+
11
+ a_(:href => "/foo"){ "bar" } #=> <a href="/foo">bar</a>
12
+
13
+ DESCRIPTION
14
+
15
+ tagz.rb is generates html, xml, or any sgml variant like a small ninja
16
+ running across the backs of a herd of giraffes swatting of heads like a
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
+ globally to objects without the need for any builder or superfluous objects.
20
+ tagz.rb is designed for applications that generate html to be able to do so
21
+ easily in any context without heavyweight syntax or scoping issues, like a
22
+ ninja sword through butter.
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
+
45
+ RAILS
46
+
47
+ in config/environment.rb
48
+
49
+ require 'tagz'
50
+
51
+ in a helper
52
+
53
+ def list_of_users
54
+ ul_(:class => 'users'){
55
+ @users.each{|user| li_{ user }}
56
+ }
57
+ end
58
+
59
+ in a view
60
+
61
+ <%=
62
+ table_{
63
+ rows.each do |row|
64
+ tr_{
65
+ row.each do |cell|
66
+ td_{ cell }
67
+ end
68
+ }
69
+ end
70
+ }
71
+ %>
72
+
73
+ in a controller
74
+
75
+ def ajax_responder
76
+ text =
77
+ tagz{
78
+ table_{
79
+ rows.each do |row|
80
+ tr_{
81
+ row.each do |cell|
82
+ td_{ cell }
83
+ end
84
+ }
85
+ end
86
+ }
87
+ }
88
+
89
+ render :text => text
90
+ end
91
+
92
+ INSTALL
93
+
94
+ gem install tagz
95
+
96
+ URIS
97
+
98
+ http://github.com/ahoward/tagz/tree/master
99
+ http://rubyforge.org/projects/codeforpeople
100
+
101
+ HISTORY
102
+ 5.1.0
103
+ - attribute/content auto-escaping can be turned off with
104
+
105
+ Tagz.i_know_what_the_hell_i_am_doing!
106
+
107
+ and turned back on with
108
+
109
+ Tagz.i_do_not_know_what_the_hell_i_am_doing!
110
+
111
+ attribute and content escaping can be configured individually too. see
112
+ tests for examples
113
+
114
+
115
+ thanks Dan Fitzpatrick
116
+
117
+ - << and concat escape (if configured) while puts and push and write do not
118
+
119
+ thanks JoelVanderWerf
120
+
121
+ 5.0.0
122
+ - introduce better escaping for attributes using xchar.rb approach
123
+ - indroduce smart escaping for content
124
+ - make Tagz.globally kick ass more hard
125
+ - note that this version is not backward compatibile if you were relying
126
+ on tagz never escaping any content should be an ok upgrade for most
127
+ applications
128
+
129
+ 4.6.0
130
+ - fix a bug with self closing tagz that had crept in 1.0.0 -> 4.2.0. thx
131
+ jeremy hinegardner
132
+
133
+ - added tests from 1.0.0 back into svn
134
+
135
+ 4.4.0
136
+ - remove dependancy on cgi lib, tagz is now completely standalone
137
+
138
+ 4.3.0
139
+ - detect rails and auto-include into ActionController::Base and include
140
+ globally into ActionView::Base
141
+
142
+ 4.2.0
143
+ - general lib cleanup
144
+ - introduction of dual-mixin technique (Tagz.globally)
145
+ - few small bug fixes
146
+ - ninja tales
147
+
148
+ SAMPLES
149
+
150
+ <========< samples/a.rb >========>
151
+
152
+ ~ > cat samples/a.rb
153
+
154
+ #
155
+ # in the simplest case tagz generates html using a syntax which safely mixes
156
+ # in to any object
157
+ #
158
+
159
+ require 'tagz'
160
+ include Tagz.globally
161
+
162
+ class GiraffeModel
163
+ def link
164
+ a_(:href => "/giraffe/neck/42"){ "whack!" }
165
+ end
166
+ end
167
+
168
+ puts GiraffeModel.new.link
169
+
170
+ ~ > ruby samples/a.rb
171
+
172
+ <a href="/giraffe/neck/42">whack!</a>
173
+
174
+
175
+ <========< samples/b.rb >========>
176
+
177
+ ~ > cat samples/b.rb
178
+
179
+ #
180
+ # tagz.rb mixes quite easily with your favourite templating engine, avoiding
181
+ # the need for '<% rows.each do |row| %> ... <% row.each do |cell| %> '
182
+ # madness and other types of logic to be coded in the templating language,
183
+ # leaving templating to template engines and logic and looping to ruby -
184
+ # unencumbered by extra funky syntax. in rails tagz will automatically be
185
+ # available in your erb templates.
186
+ #
187
+
188
+ require 'tagz'
189
+ include Tagz.globally
190
+
191
+ require 'erb'
192
+
193
+ rows = %w( a b c ), %w( 1 2 3 )
194
+
195
+ template = ERB.new <<-ERB
196
+ <html>
197
+ <body>
198
+ <%=
199
+ table_{
200
+ rows.each do |row|
201
+ tr_{
202
+ row.each do |cell|
203
+ td_{ cell }
204
+ end
205
+ }
206
+ end
207
+ }
208
+ %>
209
+ </body>
210
+ </html>
211
+ ERB
212
+
213
+ puts template.result(binding)
214
+
215
+
216
+ ~ > ruby samples/b.rb
217
+
218
+ <html>
219
+ <body>
220
+ <table><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>1</td><td>2</td><td>3</td></tr></table>
221
+ </body>
222
+ </html>
223
+
224
+
225
+ <========< samples/c.rb >========>
226
+
227
+ ~ > cat samples/c.rb
228
+
229
+ #
230
+ # once you've learned to generate html using tagz you're primed to generate
231
+ # xml too
232
+ #
233
+
234
+ require 'tagz'
235
+ include Tagz.globally
236
+
237
+ doc =
238
+ xml_{
239
+ giraffe_{ 'large' }
240
+ ninja_{ 'small' }
241
+ }
242
+
243
+ puts doc
244
+
245
+ ~ > ruby samples/c.rb
246
+
247
+ <xml><giraffe>large</giraffe><ninja>small</ninja></xml>
248
+
249
+
250
+ <========< samples/d.rb >========>
251
+
252
+ ~ > cat samples/d.rb
253
+
254
+ #
255
+ # tagz.rb doesn't cramp your style, allowing even invalid html to be
256
+ # generated. note the use of the 'tagz' method, which can be used both to
257
+ # capture output and to append content to the top of the stack.
258
+ #
259
+
260
+ require 'tagz'
261
+ include Tagz.globally
262
+
263
+ def header
264
+ tagz{
265
+ html_
266
+ body_(:class => 'ninja-like', :id => 'giraffe-slayer')
267
+
268
+ __ "<!-- this is the header -->"
269
+ }
270
+ end
271
+
272
+ def footer
273
+ tagz{
274
+ __ "<!-- this is the footer -->"
275
+
276
+ _body
277
+ _html
278
+ }
279
+ end
280
+
281
+ puts header, footer
282
+
283
+ ~ > ruby samples/d.rb
284
+
285
+ <html><body class="ninja-like" id="giraffe-slayer">
286
+ <!-- this is the header -->
287
+
288
+ <!-- this is the footer -->
289
+ </body></html>
290
+
291
+
292
+ <========< samples/e.rb >========>
293
+
294
+ ~ > cat samples/e.rb
295
+
296
+ #
297
+ # tagz.rb allows a safer method of mixin which requires any tagz methods to be
298
+ # insider a tagz block - tagz generating methods outside a tagz block with
299
+ # raise an error if tagz is included this way. also notice that the error is
300
+ # reported from where it was raised - not from the bowels of the the tagz.rb
301
+ # lib.
302
+ #
303
+
304
+ require 'tagz'
305
+ include Tagz
306
+
307
+ puts tagz{
308
+ html_{ 'works only in here' }
309
+ }
310
+
311
+ begin
312
+ html_{ 'not out here' }
313
+ rescue Object => e
314
+ p :backtrace => e.backtrace
315
+ end
316
+
317
+
318
+ ~ > ruby samples/e.rb
319
+
320
+ <html>works only in here</html>
321
+ {:backtrace=>["samples/e.rb:17"]}
322
+
323
+
324
+ <========< samples/f.rb >========>
325
+
326
+ ~ > cat samples/f.rb
327
+
328
+ #
329
+ # tagz.rb can generate really compact html. this is great to save bandwidth
330
+ # but can sometimes make reading the generated html a bit rough. of course
331
+ # using tidy or the dom inspector in firebug obviates the issue; nevertheless
332
+ # it's sometime nice to break things up a little. you can use 'tagz << "\n"'
333
+ # or the special shorthand '__' or '___' to accomplish this
334
+ #
335
+
336
+ require 'tagz'
337
+ include Tagz.globally
338
+
339
+ html =
340
+ div_{
341
+ span_{ true }
342
+ __
343
+ span_{ false } # hey ryan, i fixed this ;-)
344
+ ___
345
+
346
+ ___ 'foo & escaped bar'
347
+ }
348
+
349
+ puts html
350
+
351
+ ~ > ruby samples/f.rb
352
+
353
+ <div><span>true</span>
354
+ <span>false</span>
355
+
356
+ foo & escaped bar
357
+ </div>
358
+
359
+
360
+ <========< samples/g.rb >========>
361
+
362
+ ~ > cat samples/g.rb
363
+
364
+ # tagz gives you low-level control of the output and makes even dashersized
365
+ # xml tagz easy enough to work with
366
+ #
367
+
368
+ require 'tagz'
369
+ include Tagz.globally
370
+
371
+ xml =
372
+ root_{
373
+ tagz__('foo-bar', :key => 'foo&bar'){ 'content' }
374
+
375
+ tagz__('bar-foo')
376
+ tagz.concat 'content'
377
+ tagz.concat tagz.escape('foo&bar')
378
+ __tagz('bar-foo')
379
+ }
380
+
381
+ puts xml
382
+
383
+
384
+ ~ > ruby samples/g.rb
385
+
386
+ <root><foo-bar key="foo&amp;bar">content</foo-bar><bar-foo>contentfoo&amp;amp;bar</bar-foo></root>
387
+
data/README.tmpl ADDED
@@ -0,0 +1,150 @@
1
+ NAME
2
+
3
+ tagz.rb
4
+
5
+ SYNOPSIS
6
+
7
+ require Tagz
8
+
9
+ include Tagz.globally
10
+
11
+ a_(:href => "/foo"){ "bar" } #=> <a href="/foo">bar</a>
12
+
13
+ DESCRIPTION
14
+
15
+ tagz.rb is generates html, xml, or any sgml variant like a small ninja
16
+ running across the backs of a herd of giraffes swatting of heads like a
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
+ globally to objects without the need for any builder or superfluous objects.
20
+ tagz.rb is designed for applications that generate html to be able to do so
21
+ easily in any context without heavyweight syntax or scoping issues, like a
22
+ ninja sword through butter.
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
+
45
+ RAILS
46
+
47
+ in config/environment.rb
48
+
49
+ require 'tagz'
50
+
51
+ in a helper
52
+
53
+ def list_of_users
54
+ ul_(:class => 'users'){
55
+ @users.each{|user| li_{ user }}
56
+ }
57
+ end
58
+
59
+ in a view
60
+
61
+ <%=
62
+ table_{
63
+ rows.each do |row|
64
+ tr_{
65
+ row.each do |cell|
66
+ td_{ cell }
67
+ end
68
+ }
69
+ end
70
+ }
71
+ %>
72
+
73
+ in a controller
74
+
75
+ def ajax_responder
76
+ text =
77
+ tagz{
78
+ table_{
79
+ rows.each do |row|
80
+ tr_{
81
+ row.each do |cell|
82
+ td_{ cell }
83
+ end
84
+ }
85
+ end
86
+ }
87
+ }
88
+
89
+ render :text => text
90
+ end
91
+
92
+ INSTALL
93
+
94
+ gem install tagz
95
+
96
+ URIS
97
+
98
+ http://github.com/ahoward/tagz/tree/master
99
+ http://rubyforge.org/projects/codeforpeople
100
+
101
+ HISTORY
102
+ 5.1.0
103
+ - attribute/content auto-escaping can be turned off with
104
+
105
+ Tagz.i_know_what_the_hell_i_am_doing!
106
+
107
+ and turned back on with
108
+
109
+ Tagz.i_do_not_know_what_the_hell_i_am_doing!
110
+
111
+ attribute and content escaping can be configured individually too. see
112
+ tests for examples
113
+
114
+
115
+ thanks Dan Fitzpatrick
116
+
117
+ - << and concat escape (if configured) while puts and push and write do not
118
+
119
+ thanks JoelVanderWerf
120
+
121
+ 5.0.0
122
+ - introduce better escaping for attributes using xchar.rb approach
123
+ - indroduce smart escaping for content
124
+ - make Tagz.globally kick ass more hard
125
+ - note that this version is not backward compatibile if you were relying
126
+ on tagz never escaping any content should be an ok upgrade for most
127
+ applications
128
+
129
+ 4.6.0
130
+ - fix a bug with self closing tagz that had crept in 1.0.0 -> 4.2.0. thx
131
+ jeremy hinegardner
132
+
133
+ - added tests from 1.0.0 back into svn
134
+
135
+ 4.4.0
136
+ - remove dependancy on cgi lib, tagz is now completely standalone
137
+
138
+ 4.3.0
139
+ - detect rails and auto-include into ActionController::Base and include
140
+ globally into ActionView::Base
141
+
142
+ 4.2.0
143
+ - general lib cleanup
144
+ - introduction of dual-mixin technique (Tagz.globally)
145
+ - few small bug fixes
146
+ - ninja tales
147
+
148
+ SAMPLES
149
+
150
+ @samples