tagz 0.0.4 → 1.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 (70) hide show
  1. data/README +240 -0
  2. data/README.tmpl +240 -0
  3. data/install.rb +4 -0
  4. data/lib/tagz.rb +146 -351
  5. data/test/tagz.rb +226 -191
  6. metadata +3 -106
  7. data/lib/tagz/rails.rb +0 -198
  8. data/rails/README +0 -182
  9. data/rails/Rakefile +0 -10
  10. data/rails/app/controllers/application.rb +0 -7
  11. data/rails/app/controllers/tagz_controller.rb +0 -51
  12. data/rails/app/helpers/application_helper.rb +0 -3
  13. data/rails/app/helpers/tagz_helper.rb +0 -2
  14. data/rails/app/views/layouts/layout.rb +0 -16
  15. data/rails/app/views/tagz/b.rb +0 -19
  16. data/rails/app/views/tagz/c.rb +0 -9
  17. data/rails/app/views/tagz/d.rhtml +0 -17
  18. data/rails/app/views/tagz/e.rb +0 -3
  19. data/rails/config/boot.rb +0 -45
  20. data/rails/config/database.yml +0 -36
  21. data/rails/config/environment.rb +0 -65
  22. data/rails/config/environments/development.rb +0 -21
  23. data/rails/config/environments/production.rb +0 -18
  24. data/rails/config/environments/test.rb +0 -19
  25. data/rails/config/lighttpd.conf +0 -54
  26. data/rails/config/routes.rb +0 -23
  27. data/rails/doc/README_FOR_APP +0 -2
  28. data/rails/log/development.log +0 -6713
  29. data/rails/log/fastcgi.crash.log +0 -103
  30. data/rails/log/lighttpd.access.log +0 -171
  31. data/rails/log/lighttpd.error.log +0 -116
  32. data/rails/log/production.log +0 -0
  33. data/rails/log/server.log +0 -0
  34. data/rails/log/test.log +0 -0
  35. data/rails/public/404.html +0 -30
  36. data/rails/public/500.html +0 -30
  37. data/rails/public/dispatch.cgi +0 -10
  38. data/rails/public/dispatch.fcgi +0 -24
  39. data/rails/public/dispatch.rb +0 -10
  40. data/rails/public/favicon.ico +0 -0
  41. data/rails/public/images/rails.png +0 -0
  42. data/rails/public/index.html +0 -277
  43. data/rails/public/javascripts/application.js +0 -2
  44. data/rails/public/javascripts/controls.js +0 -833
  45. data/rails/public/javascripts/dragdrop.js +0 -942
  46. data/rails/public/javascripts/effects.js +0 -1088
  47. data/rails/public/javascripts/prototype.js +0 -2515
  48. data/rails/public/robots.txt +0 -1
  49. data/rails/script/about +0 -3
  50. data/rails/script/breakpointer +0 -3
  51. data/rails/script/console +0 -3
  52. data/rails/script/destroy +0 -3
  53. data/rails/script/generate +0 -3
  54. data/rails/script/performance/benchmarker +0 -3
  55. data/rails/script/performance/profiler +0 -3
  56. data/rails/script/plugin +0 -3
  57. data/rails/script/process/inspector +0 -3
  58. data/rails/script/process/reaper +0 -3
  59. data/rails/script/process/spawner +0 -3
  60. data/rails/script/runner +0 -3
  61. data/rails/script/server +0 -4
  62. data/rails/test/functional/tagz_controller_test.rb +0 -18
  63. data/rails/test/test_helper.rb +0 -28
  64. data/rails/tmp/cache/index.html-gzip-1958902-7552-1181801882 +0 -0
  65. data/rails/tmp/cache/javascripts/effects.js-gzip-1958907-38200-1181801882 +0 -0
  66. data/rails/tmp/cache/javascripts/prototype.js-gzip-1958906-71260-1181801882 +0 -0
  67. data/rails/tmp/sessions/ruby_sess.365e696810aa7418 +0 -0
  68. data/rails/tmp/sessions/ruby_sess.3ab0cb2f589d3855 +0 -0
  69. data/rails/tmp/sessions/ruby_sess.c812e68d96a6e99f +0 -0
  70. data/rails/tmp/sessions/ruby_sess.e0a954440a7e27d7 +0 -0
data/install.rb CHANGED
@@ -36,7 +36,11 @@ def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
36
36
  next unless FileTest.file?(f)
37
37
  next if (f = f[srcdir.length+1..-1]) == nil
38
38
  next if (/CVS$/ =~ File.dirname(f))
39
+ next if (/\.svn/ =~ File.dirname(f))
39
40
  next if f =~ %r/\.lnk/
41
+ next if f =~ %r/\.svn/
42
+ next if f =~ %r/\.swp/
43
+ next if f =~ %r/\.svn/
40
44
  path.push f
41
45
  dir |= [File.dirname(f)]
42
46
  end
@@ -1,406 +1,201 @@
1
- module Tagz
2
- Tagz::VERSION = '0.0.4' unless defined? Tagz::VERSION
3
- def self.version() VERSION end
1
+ unless defined? Tagz
4
2
 
5
- class NotOpen < StandardError; end
6
- class StillOpen < StandardError; end
3
+ require 'cgi'
7
4
 
8
- class << self
9
- def default_non_container_tag_list
10
- # http://www.w3schools.com/xhtml/xhtml_ref_byfunc.asp
11
- %w[
12
- br hr input img area base basefont
13
- ]
5
+ module Tagz
6
+ unless defined?(Tagz::VERSION)
7
+ Tagz::VERSION = [
8
+ Tagz::VERSION_MAJOR = 1,
9
+ Tagz::VERSION_MINOR = 0,
10
+ Tagz::VERSION_TEENY = 0
11
+ ].join('.')
12
+ def Tagz.version() Tagz::VERSION end
14
13
  end
15
14
 
16
- def non_container_tag_list *argv
17
- if argv.first
18
- @non_container_tag_list = [argv.first].flatten.uniq.map{|arg| arg.to_s}
19
- @non_container_tags = @non_container_tag_list.inject(Hash.new){|h,k| h.update k => true}
20
- @non_container_tag_list
21
- else
22
- if defined?(@non_container_tag_list) and @non_container_tag_list
23
- @non_container_tag_list
24
- else
25
- non_container_tag_list default_non_container_tag_list
26
- @non_container_tag_list
27
- end
15
+ class Fragment < ::String
16
+ def << other
17
+ super other.to_s
18
+ self
28
19
  end
29
- end
30
20
 
31
- def non_container_tags
32
- if defined?(@non_container_tags) and @non_container_tags
33
- @non_container_tags
34
- else
35
- non_container_tag_list
36
- @non_container_tags
21
+ def + other
22
+ self.dup << other
37
23
  end
38
24
  end
39
25
 
40
- def container? tag
41
- not(non_container_tags[tag.to_s] or false)
42
- end
43
-
44
- def emtpy? tag
45
- not container?(tag)
46
- end
47
- end
26
+ class Element < ::String
27
+ def Element.attributes options
28
+ unless options.empty?
29
+ ' ' <<
30
+ options.map do |key, value|
31
+ key = CGI.escapeHTML key.to_s
32
+ value = CGI.escapeHTML value.to_s
33
+ if value =~ %r/"/
34
+ raise ArgumentError, value if value =~ %r/'/
35
+ value = "'#{ value }'"
36
+ else
37
+ raise ArgumentError, value if value =~ %r/"/
38
+ value = "\"#{ value }\""
39
+ end
40
+ [key, value].join('=')
41
+ end.join(' ')
42
+ else
43
+ ''
44
+ end
45
+ end
48
46
 
49
- module Fragment
50
- attr_accessor 'tag'
51
- attr_accessor 'open'
52
- attr_accessor 'added'
53
- attr_accessor 'created_at'
54
- alias_method 'open?', 'open'
47
+ attr 'name'
55
48
 
56
- def self.new str='', tag='', options = {}
57
- return str if Fragment === str
58
- str.extend Fragment
59
- str.tag = tag.to_s
60
- str.stack << tag.to_s
61
- str.open = true
62
- str.added = { str.object_id => true }
63
- options.each{|k,v| str.send "#{ k }=", v}
64
- str.created_at = caller
65
- str
66
- end
49
+ def initialize name, *argv, &block
50
+ options = {}
51
+ content = []
67
52
 
68
- def stack
69
- @stack ||= []
70
- end
53
+ argv.each do |arg|
54
+ case arg
55
+ when Hash
56
+ options.update arg
57
+ else
58
+ content.push arg
59
+ end
60
+ end
71
61
 
72
- def push fragment
73
- if Fragment === fragment
74
- stack.push fragment.tag
75
- end
76
- end
62
+ content.push block.call if block
63
+ content.compact!
77
64
 
78
- def pop
79
- stack.pop
80
- end
65
+ @name = name.to_s
81
66
 
82
- def closes? other
83
- tag.to_s == other.tag.to_s
67
+ if content.empty?
68
+ replace "<#{ @name }#{ Element.attributes options }>"
69
+ else
70
+ replace "<#{ @name }#{ Element.attributes options }>#{ content.join }</#{ name }>"
71
+ end
72
+ end
84
73
  end
85
74
 
86
- def << content
87
- super content.to_s
75
+ def Tagz.export *methods
76
+ methods.flatten.compact.uniq.each do |m|
77
+ module_function m
78
+ end
88
79
  end
89
80
 
90
- def add fragment
91
- push fragment
92
- oid = fragment.object_id
93
- self << fragment unless added[oid]
81
+ def Tagz.<< other
82
+ Tagz.tagz << other
94
83
  self
95
- ensure
96
- added[oid] = true
97
84
  end
98
- end
99
85
 
100
-
101
- module Abilities
102
86
  private
103
- def tagz *argv, &block
104
- stack = __tag_stack__
105
- top = stack.last
106
- size = stack.size
107
87
 
108
- unless block
109
- top ||= Fragment()
110
- if argv.empty?
111
- top
112
- else
113
- string = argv.join
114
- top.add string
115
- string
88
+ def tagz &block
89
+ if block
90
+ if not defined?(@tagz) or @tagz.nil?
91
+ @tagz = Fragment.new
92
+ top = true
116
93
  end
117
- else
118
- obj = Tagz === self ? self : clone.instance_eval{ extend Tagz; self }
119
- stack << (top=Fragment())
120
- top = stack.last
121
- tid = top.object_id
122
-
123
- string = obj.instance_eval(&block)
124
-
125
- until stack.last.object_id == tid
126
- pop = stack.pop
127
- last = stack.last
128
- last.add pop
94
+ begin
95
+ size = @tagz.size
96
+ value = instance_eval(&block)
97
+ @tagz << value unless(Fragment === value or @tagz.size > size)
98
+ @tagz
99
+ ensure
100
+ @tagz = nil if top
129
101
  end
130
-
131
- top = stack.pop
132
-
133
- content_was_added = top.size > 0
134
- top.add string unless content_was_added
135
-
136
- top
137
- end
138
- end
139
-
140
- def method_missing m, *a, &b
141
- case m.to_s
142
- when %r/^(.*[^_])_(!)?$/o
143
- m, bang = $1, $2
144
- unless bang
145
- __tag_start__ m, *a, &b
146
- else
147
- __tag_start__(m, *a){}
148
- end
149
- when %r/^_([^_].*)$/o
150
- m = $1
151
- __tag_stop__ m, *a, &b
152
- else
153
- super
102
+ else
103
+ @tagz ||= Fragment.new
154
104
  end
155
105
  end
156
106
 
157
- def __tag_stack__
158
- @__tag_stack__ ||= []
159
- end
107
+ def tagz__ name, *argv, &block
108
+ options = {}
109
+ content = []
160
110
 
161
- def __tag_attrs__ attrs = {}
162
- return nil if attrs.empty?
163
- ( 42 - 10 ).chr <<
164
- case attrs
111
+ argv.each do |arg|
112
+ case arg
165
113
  when Hash
166
- attrs.map{|k,v| "#{ k }=#{ v.to_s.inspect }"}.join(" ")
114
+ options.update arg
167
115
  else
168
- attrs.to_s
116
+ content.push arg
169
117
  end
170
- end
171
-
172
- def __tag_start__ *argv, &block
173
- tag = argv.shift
174
-
175
- case argv.size
176
- when 0 # no attrs, no content
177
- attrs = {}
178
- content = nil
179
- when 1 # string content
180
- case argv.first
181
- when Hash
182
- attrs = argv.shift
183
- content = nil
184
- else
185
- if block
186
- attrs = argv.shift
187
- content = nil
188
- else
189
- content = argv.shift
190
- attrs = {}
191
- end
192
- end
193
- when 2 # string attrs, string content OR string content, hash attrs
194
- case argv.last
195
- when Hash
196
- attrs = argv.last
197
- content = argv.first.to_s
198
- else
199
- attrs = argv.first
200
- content = argv.last.to_s
201
- end
202
- else # string attrs, string content(s) OR string content(s), hash attrs
203
- case argv.last
204
- when Hash
205
- attrs = argv.last
206
- content = argv[0..-2].join
207
- else
208
- attrs = argv.first
209
- content = argv[1..-1].join
210
- end
211
- end
212
-
213
- if content and block
214
- b = block and block = lambda{ "#{ content }#{ b.call }" }
215
118
  end
216
119
 
217
- if content and block.nil?
218
- #block = lambda{ content }
219
- end
220
-
221
- stack = __tag_stack__
222
-
223
- if block.nil?
224
- start = Fragment( "<#{ tag }#{ __tag_attrs__ attrs } >#{ content }", tag )
225
- stack << start
226
- start
120
+ unless options.empty?
121
+ attributes = ' ' <<
122
+ options.map do |key, value|
123
+ key = CGI.escapeHTML key.to_s
124
+ value = CGI.escapeHTML value.to_s
125
+ if value =~ %r/"/
126
+ raise ArgumentError, value if value =~ %r/'/
127
+ value = "'#{ value }'"
128
+ else
129
+ raise ArgumentError, value if value =~ %r/"/
130
+ value = "\"#{ value }\""
131
+ end
132
+ [key, value].join('=')
133
+ end.join(' ')
227
134
  else
228
- ### we reserve two bytes ( 0.chr 0.chr ) to avoid massive data shift/copy
229
- start = Fragment( "<#{ tag }#{ __tag_attrs__ attrs } #{ 0.chr }#{ 0.chr }", tag )
230
- stack << start
231
- size = start.size
232
- pos = ( (size - 2) .. (size - 1) )
233
- top = stack.last
234
- tid = top.object_id
235
- ssize = stack.size
236
-
237
-
238
- content = block.call top
239
- content_was_added = size < start.size
240
-
135
+ attributes = ''
136
+ end
241
137
 
242
- ### handle dangling tags
243
- if stack.size > ssize
244
- i = ssize
245
- while((opentag = stack[i]))
246
- top.add opentag
247
- i += 1
248
- end
249
- stack.pop until stack.size == ssize
250
- end
138
+ tagz << "<#{ name }#{ attributes }>"
251
139
 
252
- ### TODO we could raise an error
253
- =begin
254
- until stack.last.object_id == tid
255
- begin
256
- last = stack.last
257
- ne = last.created_at[3]
258
- raise StillOpen, "<#{ last.tag }> @ '#{ ne }'"
259
- ensure
260
- stack.clear
140
+ if content.empty?
141
+ if block
142
+ size = tagz.size
143
+ value = block.call(tagz)
144
+ unless value
145
+ tagz[-1] = "/>"
146
+ else
147
+ tagz << value.to_s unless(Fragment === value or tagz.size > size)
148
+ tagz << "</#{ name }>"
261
149
  end
262
150
  end
263
- =end
264
-
265
- if content or Tagz.container?(tag)
266
- top[pos] = ' >'
267
- top.add content unless content_was_added
268
- stop = Fragment( "</#{ tag }>", tag, :open => false )
269
- top.add stop
270
- top.open = false
271
- else
272
- top[pos] = '/>'
273
- top.open = false
274
- end
275
-
276
- content = stack.pop
277
-
278
- top = stack.last
279
- if top and top.open?
280
- top.add content
281
- end
282
-
283
- content
284
- end
285
- end
286
-
287
- def __tag_stop__ tag
288
- stack = __tag_stack__
289
- top = stack.last
290
- stop = Fragment( "</#{ tag }>", tag, :open => false )
291
- if top
292
- if stop.closes?(top)
293
- top.add stop
294
- top.open = false
295
- content = stack.pop
296
- top = stack.last
297
- top.add content if top and top.open?
298
- content
299
- else
300
- raise NotOpen, tag.to_s
301
- end
302
151
  else
303
- raise NotOpen, tag.to_s
152
+ content.each{|c| tagz << c.to_s unless Fragment === c}
153
+ if block
154
+ size = tagz.size
155
+ value = block.call(tagz)
156
+ tagz << value.to_s unless(Fragment === value or tagz.size > size)
157
+ end
158
+ tagz << "</#{ name }>"
304
159
  end
305
- end
306
-
307
- def Fragment(*a, &b) Fragment.new(*a, &b) end
308
-
309
- def element tag, *a, &b
310
- __tag_stack__ << (top=Fragment())
311
- __tag_start__ tag, *a, &b
312
- __tag_stack__.pop
313
- end
314
- alias_method "e", "element"
315
-
316
- def element_ tag, *a, &b
317
- __tag_stack__ << (top=Fragment())
318
- __tag_start__ tag, *a, &b
319
- __tag_stack__.pop
320
- end
321
- alias_method "e_", "element_"
322
160
 
323
- def _element tag, *a, &b
324
- __tag_stack__ << (top=Fragment())
325
- __tag_stop__ tag, *a, &b
326
- __tag_stack__.pop
161
+ tagz
327
162
  end
328
- alias_method "_e", "_element"
329
163
 
330
- def element! tag, *a, &b
331
- b ||= lambda{}
332
- __tag_stack__ << (top=Fragment())
333
- __tag_start__ tag, *a, &b
334
- __tag_stack__.pop
164
+ def __tagz tag, *a, &b
165
+ tagz << "</#{ tag }>"
335
166
  end
336
- alias_method "e!", "element!"
337
167
 
338
- def xhtml_ which = :transitional, *a, &b
339
- decl =
340
- %Q|<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-#{ which }.dtd'>|
341
- attrs = {}
342
- attrs.update 'xmlns' => 'http://www.w3.org/1999/xhtml',
343
- 'xml:lang' => 'en'
344
- decl << html_(attrs, &b)
345
- end
346
- end
347
-
348
- def self.included other
349
- other.module_eval{ include Abilities }
350
- end
351
-
352
- def self.extend_object other
353
- other.extend Abilities
354
- end
355
-
356
- class ::String
357
- include Tagz
358
- def tag *a, &b
359
- tagz{ __tag_start__ self, *a, &b }
360
- end
361
- def tag_ *a, &b
362
- tagz{ __tag_start__ self, *a, &b }
363
- end
364
- def _tag *a, &b
365
- tagz{ __tag_start__ self, *a, &b }
366
- end
367
- def tag! *a
368
- tagz{ __tag_start__(self, *a){} }
168
+ def method_missing m, *a, &b
169
+ return super unless @tagz
170
+ case m.to_s
171
+ when %r/^(.*[^_])_(!)?$/o
172
+ m, bang = $1, $2
173
+ unless bang
174
+ tagz__(m, *a, &b)
175
+ else
176
+ tagz__(m, *a){}
177
+ end
178
+ when %r/^_([^_].*)$/o
179
+ m = $1
180
+ __tagz(m, *a, &b)
181
+ when 'e'
182
+ Element.new(*a, &b)
183
+ when '__'
184
+ tagz << "\n"
185
+ else
186
+ super
187
+ end
369
188
  end
370
- end
371
189
 
372
- class ::Symbol
373
- include Tagz
374
- def tag *a, &b
375
- tagz{ __tag_start__ self, *a, &b }
376
- end
377
- def tag_ *a, &b
378
- tagz{ __tag_start__ self, *a, &b }
379
- end
380
- def _tag *a, &b
381
- tagz{ __tag_start__ self, *a, &b }
382
- end
383
- def tag! *a
384
- tagz{ __tag_start__(self, *a){} }
385
- end
190
+ export %w( tagz tagz__ __tagz method_missing )
386
191
  end
387
- end
388
192
 
389
- class Object
390
- def Tagz &block
391
- const = Object.const_get :Tagz
392
- if block
393
- if const === self
394
- this = self
395
- else
396
- this = eval('self', block).dup
397
- this.send :extend, Tagz
398
- end
399
- this.send :tagz, &block
193
+ def Tagz *argv, &block
194
+ if argv.empty? and block.nil?
195
+ ::Tagz
400
196
  else
401
- const
197
+ Tagz.tagz(*argv, &block)
402
198
  end
403
199
  end
404
- end
405
200
 
406
- require File.join(File.dirname(__FILE__), 'tagz', 'rails') if defined? Rails
201
+ end