tagz 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/a.rb +11 -0
- data/gemspec.rb +27 -0
- data/gen_readme.rb +32 -0
- data/install.rb +210 -0
- data/lib/tagz.rb +376 -0
- data/lib/tagz/rails.rb +198 -0
- data/rails/README +182 -0
- data/rails/Rakefile +10 -0
- data/rails/app/controllers/application.rb +7 -0
- data/rails/app/controllers/tagz_controller.rb +51 -0
- data/rails/app/helpers/application_helper.rb +3 -0
- data/rails/app/helpers/tagz_helper.rb +2 -0
- data/rails/app/views/layouts/layout.rb +16 -0
- data/rails/app/views/tagz/b.rb +19 -0
- data/rails/app/views/tagz/c.rb +9 -0
- data/rails/app/views/tagz/d.rhtml +17 -0
- data/rails/app/views/tagz/e.rb +3 -0
- data/rails/config/boot.rb +45 -0
- data/rails/config/database.yml +36 -0
- data/rails/config/environment.rb +65 -0
- data/rails/config/environments/development.rb +21 -0
- data/rails/config/environments/production.rb +18 -0
- data/rails/config/environments/test.rb +19 -0
- data/rails/config/lighttpd.conf +54 -0
- data/rails/config/routes.rb +23 -0
- data/rails/doc/README_FOR_APP +2 -0
- data/rails/log/development.log +6713 -0
- data/rails/log/fastcgi.crash.log +103 -0
- data/rails/log/lighttpd.access.log +171 -0
- data/rails/log/lighttpd.error.log +116 -0
- data/rails/log/production.log +0 -0
- data/rails/log/server.log +0 -0
- data/rails/log/test.log +0 -0
- data/rails/public/404.html +30 -0
- data/rails/public/500.html +30 -0
- data/rails/public/dispatch.cgi +10 -0
- data/rails/public/dispatch.fcgi +24 -0
- data/rails/public/dispatch.rb +10 -0
- data/rails/public/favicon.ico +0 -0
- data/rails/public/images/rails.png +0 -0
- data/rails/public/index.html +277 -0
- data/rails/public/javascripts/application.js +2 -0
- data/rails/public/javascripts/controls.js +833 -0
- data/rails/public/javascripts/dragdrop.js +942 -0
- data/rails/public/javascripts/effects.js +1088 -0
- data/rails/public/javascripts/prototype.js +2515 -0
- data/rails/public/robots.txt +1 -0
- data/rails/script/about +3 -0
- data/rails/script/breakpointer +3 -0
- data/rails/script/console +3 -0
- data/rails/script/destroy +3 -0
- data/rails/script/generate +3 -0
- data/rails/script/performance/benchmarker +3 -0
- data/rails/script/performance/profiler +3 -0
- data/rails/script/plugin +3 -0
- data/rails/script/process/inspector +3 -0
- data/rails/script/process/reaper +3 -0
- data/rails/script/process/spawner +3 -0
- data/rails/script/runner +3 -0
- data/rails/script/server +4 -0
- data/rails/test/functional/tagz_controller_test.rb +18 -0
- data/rails/test/test_helper.rb +28 -0
- data/rails/tmp/cache/index.html-gzip-1958902-7552-1181801882 +0 -0
- data/rails/tmp/cache/javascripts/effects.js-gzip-1958907-38200-1181801882 +0 -0
- data/rails/tmp/cache/javascripts/prototype.js-gzip-1958906-71260-1181801882 +0 -0
- data/rails/tmp/sessions/ruby_sess.365e696810aa7418 +0 -0
- data/rails/tmp/sessions/ruby_sess.3ab0cb2f589d3855 +0 -0
- data/rails/tmp/sessions/ruby_sess.c812e68d96a6e99f +0 -0
- data/rails/tmp/sessions/ruby_sess.e0a954440a7e27d7 +0 -0
- data/sample/a.rb +9 -0
- data/test/tagz.rb +436 -0
- data/tidy +3 -0
- metadata +161 -0
data/a.rb
ADDED
data/gemspec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib, version = File::basename(File::dirname(File::expand_path(__FILE__))).split %r/-/, 2
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
Gem::Specification::new do |spec|
|
7
|
+
$VERBOSE = nil
|
8
|
+
spec.name = lib
|
9
|
+
spec.version = version
|
10
|
+
spec.platform = Gem::Platform::RUBY
|
11
|
+
spec.summary = lib
|
12
|
+
|
13
|
+
spec.files = Dir::glob "**/**"
|
14
|
+
spec.executables = Dir::glob("bin/*").map{|exe| File::basename exe}
|
15
|
+
|
16
|
+
spec.require_path = "lib"
|
17
|
+
spec.autorequire = lib
|
18
|
+
|
19
|
+
spec.has_rdoc = File::exist? "doc"
|
20
|
+
spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
|
21
|
+
|
22
|
+
spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
|
23
|
+
|
24
|
+
spec.author = "Ara T. Howard"
|
25
|
+
spec.email = "ara.t.howard@noaa.gov"
|
26
|
+
spec.homepage = "http://codeforpeople.com/lib/ruby/#{ lib }/"
|
27
|
+
end
|
data/gen_readme.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
$VERBOSE=nil
|
4
|
+
|
5
|
+
def indent s, n = 2
|
6
|
+
ws = ' ' * n
|
7
|
+
s.gsub %r/^/, ws
|
8
|
+
end
|
9
|
+
|
10
|
+
template = IO::read 'README.tmpl'
|
11
|
+
|
12
|
+
samples = ''
|
13
|
+
prompt = '~ > '
|
14
|
+
|
15
|
+
Dir['sample*/*'].sort.each do |sample|
|
16
|
+
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
17
|
+
|
18
|
+
cmd = "cat #{ sample }"
|
19
|
+
samples << indent(prompt + cmd, 2) << "\n\n"
|
20
|
+
samples << indent(`#{ cmd }`, 4) << "\n"
|
21
|
+
|
22
|
+
cmd = "ruby #{ sample }"
|
23
|
+
samples << indent(prompt + cmd, 2) << "\n\n"
|
24
|
+
|
25
|
+
cmd = "ruby -Ilib #{ sample }"
|
26
|
+
samples << indent(`#{ cmd } 2>&1`, 4) << "\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
#samples.gsub! %r/^/, ' '
|
30
|
+
|
31
|
+
readme = template.gsub %r/^\s*@samples\s*$/, samples
|
32
|
+
print readme
|
data/install.rb
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rbconfig'
|
3
|
+
require 'find'
|
4
|
+
require 'ftools'
|
5
|
+
require 'tempfile'
|
6
|
+
include Config
|
7
|
+
|
8
|
+
LIBDIR = "lib"
|
9
|
+
LIBDIR_MODE = 0644
|
10
|
+
|
11
|
+
BINDIR = "bin"
|
12
|
+
BINDIR_MODE = 0755
|
13
|
+
|
14
|
+
|
15
|
+
$srcdir = CONFIG["srcdir"]
|
16
|
+
$version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
|
17
|
+
$libdir = File.join(CONFIG["libdir"], "ruby", $version)
|
18
|
+
$archdir = File.join($libdir, CONFIG["arch"])
|
19
|
+
$site_libdir = $:.find {|x| x =~ /site_ruby$/}
|
20
|
+
$bindir = CONFIG["bindir"] || CONFIG['BINDIR']
|
21
|
+
$ruby_install_name = CONFIG['ruby_install_name'] || CONFIG['RUBY_INSTALL_NAME'] || 'ruby'
|
22
|
+
$ruby_ext = CONFIG['EXEEXT'] || ''
|
23
|
+
$ruby = File.join($bindir, ($ruby_install_name + $ruby_ext))
|
24
|
+
|
25
|
+
if !$site_libdir
|
26
|
+
$site_libdir = File.join($libdir, "site_ruby")
|
27
|
+
elsif $site_libdir !~ %r/#{Regexp.quote($version)}/
|
28
|
+
$site_libdir = File.join($site_libdir, $version)
|
29
|
+
end
|
30
|
+
|
31
|
+
def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
|
32
|
+
#{{{
|
33
|
+
path = []
|
34
|
+
dir = []
|
35
|
+
Find.find(srcdir) do |f|
|
36
|
+
next unless FileTest.file?(f)
|
37
|
+
next if (f = f[srcdir.length+1..-1]) == nil
|
38
|
+
next if (/CVS$/ =~ File.dirname(f))
|
39
|
+
next if f =~ %r/\.lnk/
|
40
|
+
path.push f
|
41
|
+
dir |= [File.dirname(f)]
|
42
|
+
end
|
43
|
+
for f in dir
|
44
|
+
next if f == "."
|
45
|
+
next if f == "CVS"
|
46
|
+
File::makedirs(File.join(destdir, f))
|
47
|
+
end
|
48
|
+
for f in path
|
49
|
+
next if (/\~$/ =~ f)
|
50
|
+
next if (/^\./ =~ File.basename(f))
|
51
|
+
unless bin
|
52
|
+
File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
|
53
|
+
else
|
54
|
+
from = File.join(srcdir, f)
|
55
|
+
to = File.join(destdir, f)
|
56
|
+
shebangify(from) do |sf|
|
57
|
+
$deferr.print from, " -> ", File::catname(from, to), "\n"
|
58
|
+
$deferr.printf "chmod %04o %s\n", mode, to
|
59
|
+
File::install(sf, to, mode, false)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
#}}}
|
64
|
+
end
|
65
|
+
def shebangify f
|
66
|
+
#{{{
|
67
|
+
open(f) do |fd|
|
68
|
+
buf = fd.read 42
|
69
|
+
if buf =~ %r/^\s*#\s*!.*ruby/o
|
70
|
+
ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
|
71
|
+
begin
|
72
|
+
fd.rewind
|
73
|
+
ftmp.puts "#!#{ $ruby }"
|
74
|
+
while((buf = fd.read(8192)))
|
75
|
+
ftmp.write buf
|
76
|
+
end
|
77
|
+
ftmp.close
|
78
|
+
yield ftmp.path
|
79
|
+
ensure
|
80
|
+
ftmp.close!
|
81
|
+
end
|
82
|
+
else
|
83
|
+
yield f
|
84
|
+
end
|
85
|
+
end
|
86
|
+
#}}}
|
87
|
+
end
|
88
|
+
def ARGV.switch
|
89
|
+
#{{{
|
90
|
+
return nil if self.empty?
|
91
|
+
arg = self.shift
|
92
|
+
return nil if arg == '--'
|
93
|
+
if arg =~ /^-(.)(.*)/
|
94
|
+
return arg if $1 == '-'
|
95
|
+
raise 'unknown switch "-"' if $2.index('-')
|
96
|
+
self.unshift "-#{$2}" if $2.size > 0
|
97
|
+
"-#{$1}"
|
98
|
+
else
|
99
|
+
self.unshift arg
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
#}}}
|
103
|
+
end
|
104
|
+
def ARGV.req_arg
|
105
|
+
#{{{
|
106
|
+
self.shift || raise('missing argument')
|
107
|
+
#}}}
|
108
|
+
end
|
109
|
+
def linkify d, linked = []
|
110
|
+
#--{{{
|
111
|
+
if test ?d, d
|
112
|
+
versioned = Dir[ File::join(d, "*-[0-9].[0-9].[0-9].rb") ]
|
113
|
+
versioned.each do |v|
|
114
|
+
src, dst = v, v.gsub(%r/\-[\d\.]+\.rb$/, '.rb')
|
115
|
+
lnk = nil
|
116
|
+
begin
|
117
|
+
if test ?l, dst
|
118
|
+
lnk = "#{ dst }.lnk"
|
119
|
+
puts "#{ dst } -> #{ lnk }"
|
120
|
+
File::rename dst, lnk
|
121
|
+
end
|
122
|
+
unless test ?e, dst
|
123
|
+
puts "#{ src } -> #{ dst }"
|
124
|
+
File::copy src, dst
|
125
|
+
linked << dst
|
126
|
+
end
|
127
|
+
ensure
|
128
|
+
if lnk
|
129
|
+
at_exit do
|
130
|
+
puts "#{ lnk } -> #{ dst }"
|
131
|
+
File::rename lnk, dst
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
linked
|
138
|
+
#--}}}
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
#
|
143
|
+
# main program
|
144
|
+
#
|
145
|
+
|
146
|
+
libdir = $site_libdir
|
147
|
+
bindir = $bindir
|
148
|
+
no_linkify = false
|
149
|
+
linked = nil
|
150
|
+
help = false
|
151
|
+
|
152
|
+
usage = <<-usage
|
153
|
+
#{ File::basename $0 }
|
154
|
+
-d, --destdir <destdir>
|
155
|
+
-l, --libdir <libdir>
|
156
|
+
-b, --bindir <bindir>
|
157
|
+
-r, --ruby <ruby>
|
158
|
+
-n, --no_linkify
|
159
|
+
-s, --sudo
|
160
|
+
-h, --help
|
161
|
+
usage
|
162
|
+
|
163
|
+
begin
|
164
|
+
while switch = ARGV.switch
|
165
|
+
case switch
|
166
|
+
when '-d', '--destdir'
|
167
|
+
libdir = ARGV.req_arg
|
168
|
+
when '-l', '--libdir'
|
169
|
+
libdir = ARGV.req_arg
|
170
|
+
when '-b', '--bindir'
|
171
|
+
bindir = ARGV.req_arg
|
172
|
+
when '-r', '--ruby'
|
173
|
+
$ruby = ARGV.req_arg
|
174
|
+
when '-n', '--no_linkify'
|
175
|
+
no_linkify = true
|
176
|
+
when '-s', '--sudo'
|
177
|
+
sudo = 'sudo'
|
178
|
+
when '-h', '--help'
|
179
|
+
help = true
|
180
|
+
else
|
181
|
+
raise "unknown switch #{switch.dump}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
rescue
|
185
|
+
STDERR.puts $!.to_s
|
186
|
+
STDERR.puts usage
|
187
|
+
exit 1
|
188
|
+
end
|
189
|
+
|
190
|
+
if help
|
191
|
+
STDOUT.puts usage
|
192
|
+
exit
|
193
|
+
end
|
194
|
+
|
195
|
+
system "#{ sudo } #{ $ruby } pre-install.rb" if test(?s, 'pre-install.rb')
|
196
|
+
|
197
|
+
unless no_linkify
|
198
|
+
linked = linkify('lib') + linkify('bin')
|
199
|
+
end
|
200
|
+
|
201
|
+
system "#{ $ruby } extconf.rb && make && #{ sudo } make install" if test(?s, 'extconf.rb')
|
202
|
+
|
203
|
+
install_rb(LIBDIR, libdir, LIBDIR_MODE)
|
204
|
+
install_rb(BINDIR, bindir, BINDIR_MODE, bin=true)
|
205
|
+
|
206
|
+
if linked
|
207
|
+
linked.each{|path| File::rm_f path}
|
208
|
+
end
|
209
|
+
|
210
|
+
system "#{ sudo } #{ $ruby } post-install.rb" if test(?s, 'post-install.rb')
|
data/lib/tagz.rb
ADDED
@@ -0,0 +1,376 @@
|
|
1
|
+
module Tagz
|
2
|
+
Tagz::VERSION = '0.0.1' unless defined? Tagz::VERSION
|
3
|
+
def self.version() VERSION end
|
4
|
+
|
5
|
+
class NotOpen < StandardError; end
|
6
|
+
class StillOpen < StandardError; end
|
7
|
+
|
8
|
+
module Fragment #--{{{
|
9
|
+
attr_accessor 'tag'
|
10
|
+
attr_accessor 'open'
|
11
|
+
attr_accessor 'added'
|
12
|
+
attr_accessor 'created_at'
|
13
|
+
alias_method 'open?', 'open'
|
14
|
+
|
15
|
+
def self.new str='', tag='', options = {} #--{{{
|
16
|
+
return str if Fragment === str
|
17
|
+
str.extend Fragment
|
18
|
+
str.tag = tag.to_s
|
19
|
+
str.stack << tag.to_s
|
20
|
+
str.open = true
|
21
|
+
str.added = { str.object_id => true }
|
22
|
+
options.each{|k,v| str.send "#{ k }=", v}
|
23
|
+
str.created_at = caller
|
24
|
+
str
|
25
|
+
end #--}}}
|
26
|
+
|
27
|
+
=begin
|
28
|
+
def tag
|
29
|
+
stack.last
|
30
|
+
end
|
31
|
+
=end
|
32
|
+
|
33
|
+
def stack
|
34
|
+
@stack ||= []
|
35
|
+
end
|
36
|
+
|
37
|
+
def push fragment
|
38
|
+
if Fragment === fragment
|
39
|
+
stack.push fragment.tag
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def pop
|
44
|
+
stack.pop
|
45
|
+
end
|
46
|
+
|
47
|
+
def closes? other #--{{{
|
48
|
+
tag.to_s == other.tag.to_s
|
49
|
+
end #--}}}
|
50
|
+
|
51
|
+
def << content #--{{{
|
52
|
+
super content.to_s
|
53
|
+
end #--}}}
|
54
|
+
|
55
|
+
def add fragment #--{{{
|
56
|
+
push fragment
|
57
|
+
oid = fragment.object_id
|
58
|
+
self << fragment unless added[oid]
|
59
|
+
self
|
60
|
+
ensure
|
61
|
+
added[oid] = true
|
62
|
+
end #--}}}
|
63
|
+
end #--}}}
|
64
|
+
|
65
|
+
module Abilities #--{{{
|
66
|
+
def __tag_stack__ #--{{{
|
67
|
+
@__tag_stack__ ||= []
|
68
|
+
end #--}}}
|
69
|
+
|
70
|
+
def __tag_attrs__ attrs = {} #--{{{
|
71
|
+
return nil if attrs.empty?
|
72
|
+
( 42 - 10 ).chr <<
|
73
|
+
case attrs
|
74
|
+
when Hash
|
75
|
+
attrs.map{|k,v| "#{ k }=#{ v.to_s.inspect }"}.join(" ")
|
76
|
+
else
|
77
|
+
attrs.to_s
|
78
|
+
end
|
79
|
+
end #--}}}
|
80
|
+
|
81
|
+
def __tag_start__ *argv, &block #--{{{
|
82
|
+
tag = argv.shift
|
83
|
+
|
84
|
+
case argv.size
|
85
|
+
when 0 # no attrs, no content
|
86
|
+
attrs = {}
|
87
|
+
content = nil
|
88
|
+
when 1 # string content
|
89
|
+
case argv.first
|
90
|
+
when Hash
|
91
|
+
attrs = argv.shift
|
92
|
+
content = nil
|
93
|
+
else
|
94
|
+
if block
|
95
|
+
attrs = argv.shift
|
96
|
+
content = nil
|
97
|
+
else
|
98
|
+
content = argv.shift
|
99
|
+
attrs = {}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
when 2 # string attrs, string content OR string content, hash attrs
|
103
|
+
case argv.last
|
104
|
+
when Hash
|
105
|
+
attrs = argv.last
|
106
|
+
content = argv.first.to_s
|
107
|
+
else
|
108
|
+
attrs = argv.first
|
109
|
+
content = argv.last.to_s
|
110
|
+
end
|
111
|
+
else # string attrs, string content(s) OR string content(s), hash attrs
|
112
|
+
case argv.last
|
113
|
+
when Hash
|
114
|
+
attrs = argv.last
|
115
|
+
content = argv[0..-2].join
|
116
|
+
else
|
117
|
+
attrs = argv.first
|
118
|
+
content = argv[1..-1].join
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
if content and block
|
123
|
+
b = block and block = lambda{ "#{ content }#{ b.call }" }
|
124
|
+
end
|
125
|
+
|
126
|
+
if content and block.nil?
|
127
|
+
#block = lambda{ content }
|
128
|
+
end
|
129
|
+
|
130
|
+
stack = __tag_stack__
|
131
|
+
|
132
|
+
if block.nil?
|
133
|
+
start = Fragment( "<#{ tag }#{ __tag_attrs__ attrs } >#{ content }", tag )
|
134
|
+
stack << start
|
135
|
+
start
|
136
|
+
else
|
137
|
+
### we reserve two bytes ( 0.chr 0.chr ) to avoid massive data shift/copy
|
138
|
+
start = Fragment( "<#{ tag }#{ __tag_attrs__ attrs } #{ 0.chr }#{ 0.chr }", tag )
|
139
|
+
stack << start
|
140
|
+
size = start.size
|
141
|
+
pos = ( (size - 2) .. (size - 1) )
|
142
|
+
top = stack.last
|
143
|
+
tid = top.object_id
|
144
|
+
ssize = stack.size
|
145
|
+
|
146
|
+
|
147
|
+
content = block.call top
|
148
|
+
content_was_added = size < start.size
|
149
|
+
|
150
|
+
|
151
|
+
### handle dangling tags
|
152
|
+
if stack.size > ssize
|
153
|
+
i = ssize
|
154
|
+
while((opentag = stack[i]))
|
155
|
+
top.add opentag
|
156
|
+
i += 1
|
157
|
+
end
|
158
|
+
stack.pop until stack.size == ssize
|
159
|
+
end
|
160
|
+
|
161
|
+
### TODO we could raise an error
|
162
|
+
=begin
|
163
|
+
until stack.last.object_id == tid
|
164
|
+
begin
|
165
|
+
last = stack.last
|
166
|
+
ne = last.created_at[3]
|
167
|
+
raise StillOpen, "<#{ last.tag }> @ '#{ ne }'"
|
168
|
+
ensure
|
169
|
+
stack.clear
|
170
|
+
end
|
171
|
+
end
|
172
|
+
=end
|
173
|
+
|
174
|
+
if content
|
175
|
+
top[pos] = ' >'
|
176
|
+
top.add content unless content_was_added
|
177
|
+
stop = Fragment( "</#{ tag }>", tag, :open => false )
|
178
|
+
top.add stop
|
179
|
+
top.open = false
|
180
|
+
else
|
181
|
+
top[pos] = '/>'
|
182
|
+
top.open = false
|
183
|
+
end
|
184
|
+
|
185
|
+
content = stack.pop
|
186
|
+
|
187
|
+
top = stack.last
|
188
|
+
if top and top.open?
|
189
|
+
top.add content
|
190
|
+
end
|
191
|
+
|
192
|
+
content
|
193
|
+
end
|
194
|
+
end #--}}}
|
195
|
+
|
196
|
+
def __tag_stop__ tag #--{{{
|
197
|
+
stack = __tag_stack__
|
198
|
+
top = stack.last
|
199
|
+
stop = Fragment( "</#{ tag }>", tag, :open => false )
|
200
|
+
if top
|
201
|
+
if stop.closes?(top)
|
202
|
+
top.add stop
|
203
|
+
top.open = false
|
204
|
+
content = stack.pop
|
205
|
+
top = stack.last
|
206
|
+
top.add content if top and top.open?
|
207
|
+
content
|
208
|
+
else
|
209
|
+
raise NotOpen, tag.to_s
|
210
|
+
end
|
211
|
+
else
|
212
|
+
raise NotOpen, tag.to_s
|
213
|
+
end
|
214
|
+
end #--}}}
|
215
|
+
|
216
|
+
def method_missing m, *a, &b #--{{{
|
217
|
+
case m.to_s
|
218
|
+
when %r/^(.*[^_])_(!)?$/o
|
219
|
+
m, bang = $1, $2
|
220
|
+
unless bang
|
221
|
+
__tag_start__ m, *a, &b
|
222
|
+
else
|
223
|
+
__tag_start__(m, *a){}
|
224
|
+
end
|
225
|
+
when %r/^_([^_].*)$/o
|
226
|
+
m = $1
|
227
|
+
__tag_stop__ m, *a, &b
|
228
|
+
else
|
229
|
+
super
|
230
|
+
end
|
231
|
+
end #--}}}
|
232
|
+
|
233
|
+
def tagz *argv, &block #--{{{
|
234
|
+
stack = __tag_stack__
|
235
|
+
top = stack.last
|
236
|
+
size = stack.size
|
237
|
+
|
238
|
+
unless block
|
239
|
+
top ||= Fragment()
|
240
|
+
if argv.empty?
|
241
|
+
top
|
242
|
+
else
|
243
|
+
string = argv.join
|
244
|
+
top.add string
|
245
|
+
string
|
246
|
+
end
|
247
|
+
else
|
248
|
+
obj = Tagz === self ? self : clone.instance_eval{ extend Tagz; self }
|
249
|
+
stack << (top=Fragment())
|
250
|
+
top = stack.last
|
251
|
+
tid = top.object_id
|
252
|
+
|
253
|
+
string = obj.instance_eval(&block)
|
254
|
+
|
255
|
+
until stack.last.object_id == tid
|
256
|
+
pop = stack.pop
|
257
|
+
last = stack.last
|
258
|
+
last.add pop
|
259
|
+
end
|
260
|
+
|
261
|
+
top = stack.pop
|
262
|
+
|
263
|
+
content_was_added = top.size > 0
|
264
|
+
top.add string unless content_was_added
|
265
|
+
|
266
|
+
top
|
267
|
+
end
|
268
|
+
end #--}}}
|
269
|
+
alias_method "markup", "tagz"
|
270
|
+
alias_method "__", "tagz"
|
271
|
+
alias_method "_", "tagz"
|
272
|
+
|
273
|
+
def Fragment(*a, &b) Fragment.new(*a, &b) end
|
274
|
+
|
275
|
+
### TODO - i'd like to use 'tag' for these but action view has eaten it!
|
276
|
+
def element tag, *a, &b
|
277
|
+
__tag_stack__ << (top=Fragment())
|
278
|
+
__tag_start__ tag, *a, &b
|
279
|
+
__tag_stack__.pop
|
280
|
+
end
|
281
|
+
alias_method "e", "element"
|
282
|
+
|
283
|
+
def element_ tag, *a, &b
|
284
|
+
__tag_stack__ << (top=Fragment())
|
285
|
+
__tag_start__ tag, *a, &b
|
286
|
+
__tag_stack__.pop
|
287
|
+
end
|
288
|
+
alias_method "e_", "element_"
|
289
|
+
|
290
|
+
def _element tag, *a, &b
|
291
|
+
__tag_stack__ << (top=Fragment())
|
292
|
+
__tag_stop__ tag, *a, &b
|
293
|
+
__tag_stack__.pop
|
294
|
+
end
|
295
|
+
alias_method "_e", "_element"
|
296
|
+
|
297
|
+
def element! tag, *a, &b
|
298
|
+
b ||= lambda{}
|
299
|
+
__tag_stack__ << (top=Fragment())
|
300
|
+
__tag_start__ tag, *a, &b
|
301
|
+
__tag_stack__.pop
|
302
|
+
end
|
303
|
+
alias_method "e!", "element!"
|
304
|
+
|
305
|
+
def xhtml_ which = :transitional, *a, &b
|
306
|
+
decl =
|
307
|
+
%Q|<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-#{ which }.dtd'>|
|
308
|
+
attrs = {}
|
309
|
+
attrs.update 'xmlns' => 'http://www.w3.org/1999/xhtml',
|
310
|
+
'xml:lang' => 'en'
|
311
|
+
decl << html_(attrs, &b)
|
312
|
+
end
|
313
|
+
end #--}}}
|
314
|
+
|
315
|
+
=begin
|
316
|
+
def concat s #--{{{
|
317
|
+
tagz << s.to_s
|
318
|
+
self
|
319
|
+
end #--}}}
|
320
|
+
def tag *a, &b #--{{{
|
321
|
+
__tag_start__ *a, &b
|
322
|
+
end #--}}}
|
323
|
+
def tag! *a, &b #--{{{
|
324
|
+
__tag_start__(*a){}
|
325
|
+
end #--}}}
|
326
|
+
def tag_ *a, &b #--{{{
|
327
|
+
__tag_start__ *a, &b
|
328
|
+
end #--}}}
|
329
|
+
def _tag *a, &b #--{{{
|
330
|
+
__tag_stop__ *a, &b
|
331
|
+
end #--}}}
|
332
|
+
=end
|
333
|
+
|
334
|
+
def self.included other #--{{{
|
335
|
+
other.module_eval{ include Abilities }
|
336
|
+
end #--}}}
|
337
|
+
|
338
|
+
def self.extend_object other #--{{{
|
339
|
+
other.extend Abilities
|
340
|
+
end #--}}}
|
341
|
+
|
342
|
+
class ::String
|
343
|
+
include Tagz
|
344
|
+
def tag *a, &b
|
345
|
+
tagz{ __tag_start__ self, *a, &b }
|
346
|
+
end
|
347
|
+
def tag_ *a, &b
|
348
|
+
tagz{ __tag_start__ self, *a, &b }
|
349
|
+
end
|
350
|
+
def _tag *a, &b
|
351
|
+
tagz{ __tag_start__ self, *a, &b }
|
352
|
+
end
|
353
|
+
def tag! *a
|
354
|
+
tagz{ __tag_start__(self, *a){} }
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
class ::Symbol
|
359
|
+
include Tagz
|
360
|
+
def tag *a, &b
|
361
|
+
tagz{ __tag_start__ self, *a, &b }
|
362
|
+
end
|
363
|
+
def tag_ *a, &b
|
364
|
+
tagz{ __tag_start__ self, *a, &b }
|
365
|
+
end
|
366
|
+
def _tag *a, &b
|
367
|
+
tagz{ __tag_start__ self, *a, &b }
|
368
|
+
end
|
369
|
+
def tag! *a
|
370
|
+
tagz{ __tag_start__(self, *a){} }
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
require File.join(File.dirname(__FILE__), 'tagz', 'rails') if defined? Rails
|