tagz 5.0.1 → 6.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 (13) hide show
  1. data/README +40 -249
  2. data/Rakefile +228 -0
  3. data/lib/tagz.rb +234 -154
  4. data/readme.erb +154 -0
  5. data/samples/d.rb +4 -4
  6. data/tagz.gemspec +26 -0
  7. data/test/tagz.rb +154 -0
  8. metadata +6 -8
  9. data/a.rb +0 -12
  10. data/gemspec.rb +0 -44
  11. data/gen_readme.rb +0 -34
  12. data/install.rb +0 -214
  13. data/prof.rb +0 -25
data/README CHANGED
@@ -58,17 +58,15 @@ RAILS
58
58
 
59
59
  in a view
60
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
- %>
61
+ table_{
62
+ rows.each do |row|
63
+ tr_{
64
+ row.each do |cell|
65
+ td_{ cell }
66
+ end
67
+ }
68
+ end
69
+ }
72
70
 
73
71
  in a controller
74
72
 
@@ -93,7 +91,37 @@ INSTALL
93
91
 
94
92
  gem install tagz
95
93
 
94
+ URIS
95
+
96
+ http://github.com/ahoward/tagz/tree/master
97
+ http://rubyforge.org/projects/codeforpeople
98
+
96
99
  HISTORY
100
+ 6.0.0
101
+ - reorganize lib to avoid dumping a few constants into the includee - aka
102
+ don't absolutely minimize namespace pollution. there is now reason to
103
+ thing this version shouldn't be backwards compat - i bumped the version
104
+ just in case
105
+
106
+ 5.1.0
107
+ - attribute/content auto-escaping can be turned off with
108
+
109
+ Tagz.i_know_what_the_hell_i_am_doing!
110
+
111
+ and turned back on with
112
+
113
+ Tagz.i_do_not_know_what_the_hell_i_am_doing!
114
+
115
+ attribute and content escaping can be configured individually too. see
116
+ tests for examples
117
+
118
+
119
+ thanks Dan Fitzpatrick
120
+
121
+ - << and concat escape (if configured) while puts and push and write do not
122
+
123
+ thanks JoelVanderWerf
124
+
97
125
  5.0.0
98
126
  - introduce better escaping for attributes using xchar.rb approach
99
127
  - indroduce smart escaping for content
@@ -123,241 +151,4 @@ HISTORY
123
151
 
124
152
  SAMPLES
125
153
 
126
- <========< samples/a.rb >========>
127
-
128
- ~ > cat samples/a.rb
129
-
130
- #
131
- # in the simplest case tagz generates html using a syntax which safely mixes
132
- # in to any object
133
- #
134
-
135
- require 'tagz'
136
- include Tagz.globally
137
-
138
- class GiraffeModel
139
- def link
140
- a_(:href => "/giraffe/neck/42"){ "whack!" }
141
- end
142
- end
143
-
144
- puts GiraffeModel.new.link
145
-
146
- ~ > ruby samples/a.rb
147
-
148
- <a href="/giraffe/neck/42">whack!</a>
149
-
150
-
151
- <========< samples/b.rb >========>
152
-
153
- ~ > cat samples/b.rb
154
-
155
- #
156
- # tagz.rb mixes quite easily with your favourite templating engine, avoiding
157
- # the need for '<% rows.each do |row| %> ... <% row.each do |cell| %> '
158
- # madness and other types of logic to be coded in the templating language,
159
- # leaving templating to template engines and logic and looping to ruby -
160
- # unencumbered by extra funky syntax. in rails tagz will automatically be
161
- # available in your erb templates.
162
- #
163
-
164
- require 'tagz'
165
- include Tagz.globally
166
-
167
- require 'erb'
168
-
169
- rows = %w( a b c ), %w( 1 2 3 )
170
-
171
- template = ERB.new <<-ERB
172
- <html>
173
- <body>
174
- <%=
175
- table_{
176
- rows.each do |row|
177
- tr_{
178
- row.each do |cell|
179
- td_{ cell }
180
- end
181
- }
182
- end
183
- }
184
- %>
185
- </body>
186
- </html>
187
- ERB
188
-
189
- puts template.result(binding)
190
-
191
-
192
- ~ > ruby samples/b.rb
193
-
194
- <html>
195
- <body>
196
- <table><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>1</td><td>2</td><td>3</td></tr></table>
197
- </body>
198
- </html>
199
-
200
-
201
- <========< samples/c.rb >========>
202
-
203
- ~ > cat samples/c.rb
204
-
205
- #
206
- # once you've learned to generate html using tagz you're primed to generate
207
- # xml too
208
- #
209
-
210
- require 'tagz'
211
- include Tagz.globally
212
-
213
- doc =
214
- xml_{
215
- giraffe_{ 'large' }
216
- ninja_{ 'small' }
217
- }
218
-
219
- puts doc
220
-
221
- ~ > ruby samples/c.rb
222
-
223
- <xml><giraffe>large</giraffe><ninja>small</ninja></xml>
224
-
225
-
226
- <========< samples/d.rb >========>
227
-
228
- ~ > cat samples/d.rb
229
-
230
- #
231
- # tagz.rb doesn't cramp your style, allowing even invalid html to be
232
- # generated. note the use of the 'tagz' method, which can be used both to
233
- # capture output and to append content to the top of the stack.
234
- #
235
-
236
- require 'tagz'
237
- include Tagz.globally
238
-
239
- def header
240
- tagz{
241
- html_
242
- body_(:class => 'ninja-like', :id => 'giraffe-slayer')
243
-
244
- ___ "<!-- this is the header -->"
245
- }
246
- end
247
-
248
- def footer
249
- tagz{
250
- ___ "<!-- this is the footer -->"
251
-
252
- body_
253
- html_
254
- }
255
- end
256
-
257
- puts header, footer
258
-
259
- ~ > ruby samples/d.rb
260
-
261
- <html><body class="ninja-like" id="giraffe-slayer">
262
- <!-- this is the header -->
263
-
264
- <!-- this is the footer -->
265
- <body><html>
266
-
267
-
268
- <========< samples/e.rb >========>
269
-
270
- ~ > cat samples/e.rb
271
-
272
- #
273
- # tagz.rb allows a safer method of mixin which requires any tagz methods to be
274
- # insider a tagz block - tagz generating methods outside a tagz block with
275
- # raise an error if tagz is included this way. also notice that the error is
276
- # reported from where it was raised - not from the bowels of the the tagz.rb
277
- # lib.
278
- #
279
-
280
- require 'tagz'
281
- include Tagz
282
-
283
- puts tagz{
284
- html_{ 'works only in here' }
285
- }
286
-
287
- begin
288
- html_{ 'not out here' }
289
- rescue Object => e
290
- p :backtrace => e.backtrace
291
- end
292
-
293
-
294
- ~ > ruby samples/e.rb
295
-
296
- <html>works only in here</html>
297
- {:backtrace=>["samples/e.rb:17"]}
298
-
299
-
300
- <========< samples/f.rb >========>
301
-
302
- ~ > cat samples/f.rb
303
-
304
- #
305
- # tagz.rb can generate really compact html. this is great to save bandwidth
306
- # but can sometimes make reading the generated html a bit rough. of course
307
- # using tidy or the dom inspector in firebug obviates the issue; nevertheless
308
- # it's sometime nice to break things up a little. you can use 'tagz << "\n"'
309
- # or the special shorthand '__' or '___' to accomplish this
310
- #
311
-
312
- require 'tagz'
313
- include Tagz.globally
314
-
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
326
-
327
- ~ > ruby samples/f.rb
328
-
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>
363
-
154
+
@@ -0,0 +1,228 @@
1
+
2
+ This.rubyforge_project = 'codeforpeople'
3
+ This.author = "Ara T. Howard"
4
+ This.email = "ara.t.howard@gmail.com"
5
+ This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
6
+
7
+
8
+ task :default do
9
+ puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
10
+ end
11
+
12
+
13
+ task :gemspec do
14
+ ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
15
+ ignore_directories = 'pkg'
16
+ ignore_files = 'test/log'
17
+
18
+ shiteless =
19
+ lambda do |list|
20
+ list.delete_if do |entry|
21
+ next unless test(?e, entry)
22
+ extension = File.basename(entry).split(%r/[.]/).last
23
+ ignore_extensions.any?{|ext| ext === extension}
24
+ end
25
+ list.delete_if do |entry|
26
+ next unless test(?d, entry)
27
+ dirname = File.expand_path(entry)
28
+ ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
29
+ end
30
+ list.delete_if do |entry|
31
+ next unless test(?f, entry)
32
+ filename = File.expand_path(entry)
33
+ ignore_files.any?{|file| File.expand_path(file) == filename}
34
+ end
35
+ end
36
+
37
+ lib = This.lib
38
+ version = This.version
39
+ files = shiteless[Dir::glob("**/**")]
40
+ executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
41
+ has_rdoc = true #File.exist?('doc')
42
+ test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
43
+
44
+ extensions = This.extensions
45
+ if extensions.nil?
46
+ %w( Makefile configure extconf.rb ).each do |ext|
47
+ extensions << ext if File.exists?(ext)
48
+ end
49
+ end
50
+ extensions = [extensions].flatten.compact
51
+
52
+ template =
53
+ if test(?e, 'gemspec.erb')
54
+ Template{ IO.read('gemspec.erb') }
55
+ else
56
+ Template {
57
+ <<-__
58
+ ## #{ lib }.gemspec
59
+ #
60
+
61
+ Gem::Specification::new do |spec|
62
+ spec.name = #{ lib.inspect }
63
+ spec.version = #{ version.inspect }
64
+ spec.platform = Gem::Platform::RUBY
65
+ spec.summary = #{ lib.inspect }
66
+
67
+ spec.files = #{ files.inspect }
68
+ spec.executables = #{ executables.inspect }
69
+
70
+ spec.require_path = "lib"
71
+
72
+ spec.has_rdoc = #{ has_rdoc.inspect }
73
+ spec.test_files = #{ test_files.inspect }
74
+ #spec.add_dependency 'lib', '>= version'
75
+ #spec.add_dependency 'fattr'
76
+
77
+ spec.extensions.push(*#{ extensions.inspect })
78
+
79
+ spec.rubyforge_project = #{ This.rubyforge_project.inspect }
80
+ spec.author = #{ This.author.inspect }
81
+ spec.email = #{ This.email.inspect }
82
+ spec.homepage = #{ This.homepage.inspect }
83
+ end
84
+ __
85
+ }
86
+ end
87
+
88
+ open("#{ lib }.gemspec", "w"){|fd| fd.puts template}
89
+ This.gemspec = "#{ lib }.gemspec"
90
+ end
91
+
92
+ task :gem => [:clean, :gemspec] do
93
+ Fu.mkdir_p This.pkgdir
94
+ before = Dir['*.gem']
95
+ cmd = "gem build #{ This.gemspec }"
96
+ `#{ cmd }`
97
+ after = Dir['*.gem']
98
+ gem = ((after - before).first || after.first) or abort('no gem!')
99
+ Fu.mv gem, This.pkgdir
100
+ This.gem = File.basename(gem)
101
+ end
102
+
103
+ task :readme do
104
+ samples = ''
105
+ prompt = '~ > '
106
+ lib = This.lib
107
+ version = This.version
108
+
109
+ Dir['sample*/*'].sort.each do |sample|
110
+ samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
111
+
112
+ cmd = "cat #{ sample }"
113
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
114
+ samples << Util.indent(`#{ cmd }`, 4) << "\n"
115
+
116
+ cmd = "ruby #{ sample }"
117
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
118
+
119
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
120
+ samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
121
+ end
122
+
123
+ template =
124
+ if test(?e, 'readme.erb')
125
+ Template{ IO.read('readme.erb') }
126
+ else
127
+ Template {
128
+ <<-__
129
+ NAME
130
+ #{ lib }
131
+
132
+ DESCRIPTION
133
+
134
+ INSTALL
135
+ gem install #{ lib }
136
+
137
+ SAMPLES
138
+ #{ samples }
139
+ __
140
+ }
141
+ end
142
+
143
+ open("README", "w"){|fd| fd.puts template}
144
+ end
145
+
146
+
147
+ task :clean do
148
+ Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
149
+ end
150
+
151
+
152
+ task :release => [:clean, :gemspec, :gem] do
153
+ gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
154
+ raise "which one? : #{ gems.inspect }" if gems.size > 1
155
+ raise "no gems?" if gems.size < 1
156
+ cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
157
+ puts cmd
158
+ system cmd
159
+ end
160
+
161
+
162
+
163
+
164
+
165
+ BEGIN {
166
+ $VERBOSE = nil
167
+
168
+ require 'ostruct'
169
+ require 'erb'
170
+ require 'fileutils'
171
+
172
+ Fu = FileUtils
173
+
174
+ This = OpenStruct.new
175
+
176
+ This.file = File.expand_path(__FILE__)
177
+ This.dir = File.dirname(This.file)
178
+ This.pkgdir = File.join(This.dir, 'pkg')
179
+
180
+ lib = ENV['LIB']
181
+ unless lib
182
+ lib = File.basename(Dir.pwd)
183
+ end
184
+ This.lib = lib
185
+
186
+ version = ENV['VERSION']
187
+ unless version
188
+ name = lib.capitalize
189
+ require "./lib/#{ lib }"
190
+ version = eval(name).send(:version)
191
+ end
192
+ This.version = version
193
+
194
+ abort('no lib') unless This.lib
195
+ abort('no version') unless This.version
196
+
197
+ module Util
198
+ def indent(s, n = 2)
199
+ s = unindent(s)
200
+ ws = ' ' * n
201
+ s.gsub(%r/^/, ws)
202
+ end
203
+
204
+ def unindent(s)
205
+ indent = nil
206
+ s.each do |line|
207
+ next if line =~ %r/^\s*$/
208
+ indent = line[%r/^\s*/] and break
209
+ end
210
+ indent ? s.gsub(%r/^#{ indent }/, "") : s
211
+ end
212
+ extend self
213
+ end
214
+
215
+ class Template
216
+ def initialize(&block)
217
+ @block = block
218
+ @template = block.call.to_s
219
+ end
220
+ def expand(b=nil)
221
+ ERB.new(Util.unindent(@template)).result(b||@block)
222
+ end
223
+ alias_method 'to_s', 'expand'
224
+ end
225
+ def Template(*args, &block) Template.new(*args, &block) end
226
+
227
+ Dir.chdir(This.dir)
228
+ }