tagz 1.0.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +171 -196
- data/a.rb +8 -0
- data/gemspec.rb +12 -4
- data/lib/tagz.rb +51 -29
- data/samples/a.rb +15 -0
- data/samples/b.rb +41 -0
- data/samples/c.rb +15 -0
- data/samples/d.rb +28 -0
- data/samples/e.rb +21 -0
- metadata +12 -10
- data/README.tmpl +0 -240
- data/sample/a.rb +0 -9
- data/test/tagz.rb +0 -470
data/README
CHANGED
@@ -1,240 +1,215 @@
|
|
1
1
|
NAME
|
2
|
+
|
2
3
|
tagz.rb
|
3
4
|
|
4
5
|
SYNOPSIS
|
5
|
-
object mixin for squeaky clean and super speedy generation of any sgml
|
6
|
-
(html/xml) tags using a private dsl
|
7
|
-
|
8
|
-
+ module level interface
|
9
|
-
|
10
|
-
require 'tagz'
|
11
|
-
|
12
|
-
html =
|
13
|
-
Tagz{
|
14
|
-
html_{
|
15
|
-
body_(:class => 'container'){
|
16
|
-
div_{ 'content' }
|
17
|
-
}
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
+ private mixin interface
|
22
6
|
|
23
|
-
|
7
|
+
require Tagz
|
24
8
|
|
25
|
-
|
26
|
-
include Tagz
|
9
|
+
include Tagz.globally
|
27
10
|
|
28
|
-
|
29
|
-
@width, @height = width, height
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_row
|
33
|
-
Tagz{
|
34
|
-
table_(:width => @width, :height => @height){
|
35
|
-
each do |row|
|
36
|
-
tr_{
|
37
|
-
row.each{|cell| td_{ cell }}
|
38
|
-
}
|
39
|
-
end
|
40
|
-
}
|
41
|
-
}
|
42
|
-
end
|
43
|
-
end
|
11
|
+
a_(:href => "/foo"){ "bar" } #=> <a href="/foo">bar</a>
|
44
12
|
|
45
13
|
DESCRIPTION
|
46
|
-
tagz.rb offers a mixin module which adds four private methods to the calling
|
47
|
-
object:
|
48
14
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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 200 lines of code tagz.rb adds
|
18
|
+
an html 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.
|
53
23
|
|
54
|
-
|
55
|
-
in the controller of a web framework which exposes methods to the world as
|
56
|
-
http actions
|
24
|
+
INSTALL
|
57
25
|
|
58
|
-
|
59
|
-
block, for instance
|
26
|
+
gem install tagz
|
60
27
|
|
61
|
-
|
28
|
+
HISTORY
|
62
29
|
|
63
|
-
|
30
|
+
4.2.0
|
31
|
+
- general lib cleanup
|
32
|
+
- introduction of dual-mixin technique (Tagz.globally)
|
33
|
+
- few small bug fixes
|
34
|
+
- ninja tales
|
64
35
|
|
65
|
-
|
36
|
+
SAMPLES
|
66
37
|
|
67
|
-
|
68
|
-
html4, xml, whatever, all using the same simple interface
|
38
|
+
<========< samples/a.rb >========>
|
69
39
|
|
70
|
-
|
40
|
+
~ > cat samples/a.rb
|
71
41
|
|
42
|
+
#
|
43
|
+
# in the simplest case tagz generates html using a syntax which safely mixes
|
44
|
+
# in to any object
|
45
|
+
#
|
46
|
+
|
72
47
|
require 'tagz'
|
73
|
-
include Tagz
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
tagz{
|
83
|
-
img_(:src => 'foo.png')
|
84
|
-
img_(:src => 'foo.png'){}
|
85
|
-
}
|
86
|
-
|
87
|
-
#=> <img src="foo.png">
|
88
|
-
#=> <img src="foo.png" />
|
89
|
-
|
90
|
-
|
91
|
-
tagz{
|
92
|
-
br_
|
93
|
-
br_!
|
94
|
-
br_{}
|
95
|
-
}
|
48
|
+
include Tagz.globally
|
49
|
+
|
50
|
+
class GiraffeModel
|
51
|
+
def link
|
52
|
+
a_(:href => "/giraffe/neck/42"){ "whack!" }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
puts GiraffeModel.new.link
|
96
57
|
|
97
|
-
|
98
|
-
#=> <br />
|
99
|
-
#=> <br />
|
58
|
+
~ > ruby samples/a.rb
|
100
59
|
|
101
|
-
|
102
|
-
tagz{
|
103
|
-
span_('content', :style => 'color:mauve')
|
104
|
-
}
|
60
|
+
<a href="/giraffe/neck/42">whack!</a>
|
105
61
|
|
106
|
-
#=> <span style="color:mauve">content</span>
|
107
62
|
|
108
|
-
|
109
|
-
tagz{
|
110
|
-
div_(:class => 'container'){
|
111
|
-
span_('content', :style => 'color:mauve')
|
112
|
-
}
|
113
|
-
}
|
114
|
-
|
115
|
-
#=> <div class="container"><span style="color:mauve">content</span></div>
|
116
|
-
|
117
|
-
|
118
|
-
tagz{
|
119
|
-
div_(:class => 'container')
|
120
|
-
span_('content', :style => 'color:mauve')
|
121
|
-
_div
|
122
|
-
}
|
63
|
+
<========< samples/b.rb >========>
|
123
64
|
|
124
|
-
|
65
|
+
~ > cat samples/b.rb
|
125
66
|
|
126
|
-
|
127
|
-
tagz
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
67
|
+
#
|
68
|
+
# tagz.rb mixes quite easily with your favourite templating engine, avoiding
|
69
|
+
# the need for '<% rows.each do |row| %> ... <% row.each do |cell| %> '
|
70
|
+
# madness and other types of logic to be coded in the templating language,
|
71
|
+
# leaving templating to template engines and logic and looping to ruby -
|
72
|
+
# unencumbered by extra funky syntax
|
73
|
+
#
|
74
|
+
|
75
|
+
require 'tagz'
|
76
|
+
include Tagz.globally
|
77
|
+
|
78
|
+
require 'erb'
|
79
|
+
|
80
|
+
rows = %w( a b c ), %w( 1 2 3 )
|
81
|
+
|
82
|
+
template = ERB.new <<-ERB
|
83
|
+
<html>
|
84
|
+
<body>
|
85
|
+
<%=
|
86
|
+
|
87
|
+
if rows
|
88
|
+
|
89
|
+
table_{
|
90
|
+
rows.each do |row|
|
91
|
+
tr_{
|
92
|
+
row.each do |cell|
|
93
|
+
td_{ cell }
|
94
|
+
end
|
95
|
+
}
|
96
|
+
end
|
97
|
+
}
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
%>
|
102
|
+
</body>
|
103
|
+
</html>
|
104
|
+
ERB
|
105
|
+
|
106
|
+
puts template.result(binding)
|
107
|
+
|
108
|
+
|
109
|
+
~ > ruby samples/b.rb
|
110
|
+
|
111
|
+
<html>
|
112
|
+
<body>
|
113
|
+
<table><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>1</td><td>2</td><td>3</td></tr></table>
|
114
|
+
</body>
|
115
|
+
</html>
|
116
|
+
|
117
|
+
|
118
|
+
<========< samples/c.rb >========>
|
119
|
+
|
120
|
+
~ > cat samples/c.rb
|
121
|
+
|
122
|
+
#
|
123
|
+
# once you've learned to generate html using tagz you're primed to generate
|
124
|
+
# xml too
|
125
|
+
#
|
126
|
+
|
127
|
+
require 'tagz'
|
128
|
+
include Tagz.globally
|
129
|
+
|
130
|
+
doc =
|
131
|
+
xml_{
|
132
|
+
giraffe_{ 'large' }
|
133
|
+
ninja_{ 'small' }
|
134
134
|
}
|
135
|
-
|
135
|
+
|
136
|
+
puts doc
|
136
137
|
|
137
|
-
|
138
|
+
~ > ruby samples/c.rb
|
138
139
|
|
139
|
-
|
140
|
-
# is *NOT* added to the content. the rule is: add the return value of
|
141
|
-
# the block if, and only if, the block did not add any content itself
|
142
|
-
# during evaluation
|
140
|
+
<xml><giraffe>large</giraffe><ninja>small</ninja></xml>
|
143
141
|
|
144
|
-
|
145
|
-
tagz{
|
146
|
-
div_{
|
147
|
-
div_{ 'content' }
|
148
|
-
'this is ignored'
|
149
|
-
}
|
150
|
-
}
|
151
142
|
|
152
|
-
|
143
|
+
<========< samples/d.rb >========>
|
153
144
|
|
154
|
-
|
145
|
+
~ > cat samples/d.rb
|
155
146
|
|
156
|
-
|
157
|
-
tagz
|
158
|
-
|
159
|
-
|
147
|
+
#
|
148
|
+
# tagz.rb doesn't cramp your style, allowing even invalid html to be
|
149
|
+
# generated. note the use of the 'tagz' method, which can be used both to
|
150
|
+
# capture output and to append content to the top of the stack.
|
151
|
+
#
|
152
|
+
|
153
|
+
require 'tagz'
|
154
|
+
include Tagz.globally
|
155
|
+
|
156
|
+
def header
|
157
|
+
tagz{
|
158
|
+
html_
|
159
|
+
body_(:class => 'ninja-like', :id => 'giraffe-slayer')
|
160
|
+
|
161
|
+
tagz << "\n<!-- this is the header -->\n"
|
160
162
|
}
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
tagz << 'this is appended' << ' and so is this'
|
163
|
+
end
|
164
|
+
|
165
|
+
def footer
|
166
|
+
tagz{
|
167
|
+
tagz << "\n<!-- this is the footer -->\n"
|
168
|
+
|
169
|
+
body_
|
170
|
+
html_
|
170
171
|
}
|
171
|
-
|
172
|
+
end
|
173
|
+
|
174
|
+
puts header, footer
|
172
175
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
tagz{
|
177
|
-
a_
|
178
|
-
b_
|
179
|
-
c_
|
180
|
-
tagz << 'valid html'
|
181
|
-
_a
|
182
|
-
_b
|
183
|
-
_c
|
184
|
-
_invalid
|
185
|
-
}
|
186
|
-
|
187
|
-
#=> <a><b><c>valid html</a></b></c></invalid>
|
176
|
+
~ > ruby samples/d.rb
|
188
177
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
178
|
+
<html><body class="ninja-like" id="giraffe-slayer">
|
179
|
+
<!-- this is the header -->
|
180
|
+
|
181
|
+
<!-- this is the footer -->
|
182
|
+
<body><html>
|
193
183
|
|
194
|
-
__ __
|
195
|
-
b_{ 'content' }
|
196
|
-
|
197
|
-
__ __ __
|
198
|
-
c_{ 'content' }
|
199
|
-
}
|
200
184
|
|
201
|
-
|
185
|
+
<========< samples/e.rb >========>
|
202
186
|
|
203
|
-
|
204
|
-
# you can do 'tagz << "\n"' or just use the '__' method to output some
|
205
|
-
# linebreaks
|
187
|
+
~ > cat samples/e.rb
|
206
188
|
|
207
|
-
|
208
|
-
tagz
|
209
|
-
|
210
|
-
|
211
|
-
|
189
|
+
#
|
190
|
+
# tagz.rb allows a safer method of mixin which requires any tagz methods to be
|
191
|
+
# insider a tagz block - tagz generating methods outside a tagz block with
|
192
|
+
# raise an error if tagz is included this way. also notice that the error is
|
193
|
+
# reported from where it was raised - not from the bowels of the the tagz.rb
|
194
|
+
# lib.
|
195
|
+
#
|
196
|
+
|
197
|
+
require 'tagz'
|
198
|
+
include Tagz
|
199
|
+
|
200
|
+
puts tagz{
|
201
|
+
html_{ 'works only in here' }
|
212
202
|
}
|
203
|
+
|
204
|
+
begin
|
205
|
+
html_{ 'not out here' }
|
206
|
+
rescue Object => e
|
207
|
+
puts e.backtrace
|
208
|
+
end
|
209
|
+
|
213
210
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
a couple of notes: *none* of the method_missing magic is available outside
|
218
|
-
the 'tagz' block and, even inside, it supers-up when the missing method does
|
219
|
-
not look like a tag method. you can use Tagz{} as a module method but to
|
220
|
-
have access to @ivars you'll want to mixin the module to your own class and
|
221
|
-
use tagz{}. no public methods are added to your object, only four private
|
222
|
-
ones.
|
223
|
-
|
224
|
-
|
225
|
-
HISTORY
|
226
|
-
1.0.0
|
227
|
-
totally reworked tagz, dropping 300 loc - only 170 loc now. this release
|
228
|
-
is *NOT* backward compatible with other tagz versions, though the api is
|
229
|
-
very very close. the rework makes tagz safer to mixin, faster, and
|
230
|
-
produces nicer looking html. this version also marks ramaze template
|
231
|
-
support.
|
232
|
-
|
233
|
-
INSTALL
|
234
|
-
gem install tagz
|
211
|
+
~ > ruby samples/e.rb
|
235
212
|
|
236
|
-
|
237
|
-
|
213
|
+
<html>works only in here</html>
|
214
|
+
samples/e.rb:17
|
238
215
|
|
239
|
-
AUTHOR
|
240
|
-
ara.t.howard@gmail.com
|
data/a.rb
ADDED
data/gemspec.rb
CHANGED
@@ -1,27 +1,35 @@
|
|
1
|
-
|
2
1
|
lib, version = File::basename(File::dirname(File::expand_path(__FILE__))).split %r/-/, 2
|
3
2
|
|
4
3
|
require 'rubygems'
|
5
4
|
|
6
5
|
Gem::Specification::new do |spec|
|
7
6
|
$VERBOSE = nil
|
7
|
+
|
8
|
+
shiteless = lambda do |list|
|
9
|
+
list.delete_if do |file|
|
10
|
+
file =~ %r/\.svn/ or
|
11
|
+
file =~ %r/\.tmp/
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
8
15
|
spec.name = lib
|
9
16
|
spec.version = version
|
10
17
|
spec.platform = Gem::Platform::RUBY
|
11
18
|
spec.summary = lib
|
12
19
|
|
13
|
-
spec.files = Dir::glob
|
14
|
-
spec.executables = Dir::glob("bin/*").map{|exe| File::basename exe}
|
20
|
+
spec.files = shiteless[Dir::glob("**/**")]
|
21
|
+
spec.executables = shiteless[Dir::glob("bin/*")].map{|exe| File::basename exe}
|
15
22
|
|
16
23
|
spec.require_path = "lib"
|
17
24
|
spec.autorequire = lib
|
18
25
|
|
19
26
|
spec.has_rdoc = File::exist? "doc"
|
20
27
|
spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
|
28
|
+
#spec.add_dependency 'lib', '>= version'
|
21
29
|
|
22
30
|
spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
|
23
31
|
|
24
32
|
spec.author = "Ara T. Howard"
|
25
|
-
spec.email = "ara.t.howard@
|
33
|
+
spec.email = "ara.t.howard@gmail.com"
|
26
34
|
spec.homepage = "http://codeforpeople.com/lib/ruby/#{ lib }/"
|
27
35
|
end
|