File: HTML%3A%3ATemplate.3ruby

package info (click to toggle)
html-template 0.16-2.1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 128 kB
  • ctags: 111
  • sloc: ruby: 869; makefile: 41
file content (329 lines) | stat: -rw-r--r-- 6,105 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
.\" DO NOT MODIFY THIS FILE! it was generated by rd2
.TH HTML::Template 3ruby "June 2002"
.SH NAME
HTML::Template \- Ruby extension for HTML::Template
.SH DESCRIPTION
.PP
This module deals with HTML template by CGI scripts and use a complete selectivity between design and logic easily. 
You can deal with a nested block, a loop and a conditional expression.
Simple example, see below.
.fi
.PP
template file test.html
.nf
\&    <HTML>
\&    <HEAD><TITLE>Test Template</TITLE>
\&    <BODY>
\&    My Home Directory is <!var:home>
\&    <P>
\&    My Path is set to <!var:path>
\&    </BODY>
\&    </HTML>
.fi
Ruby script
.nf
\&    require "html/template"
\&    tmpl = HTML::Template.new("./test.html")
\&    tmpl.param({
\&               'home' => ENV['HOME'],
\&               'path' => ENV['PATH']
\&               })
\&    print "Content\-Type: text/html\\n\\n"
\&    print tmpl.output
.fi
.SH INSTALL
.PP
using install.rb 
.nf
\&    % tar xvzf html\-template\-x.xx.tar.gz
\&    % cd html\-template\-x.xx
\&    % ruby install.rb config
\&    % ruby install.rb setup
\&    % su
\&    # ruby install.rb install
.fi
.SH Template File
.PP
.SH TAGS
.PP
You can use original style tag or valid HTML comment style tag.

.TP
.fi
.B
<!var:PARAMETER_NAME>

.TP
.fi
.B
<!\-\- var:PARAMETER_NAME \-\->
When you call HTML::Template#param ({PARAMETER_NAME => VAL}), tags will be simply replaced to VAL.


.TP
.fi
.B
<!begin:PARAMETER_NAME>

.TP
.fi
.B
<!end:PARAMETER_NAME>

.TP
.fi
.B
<!\-\- begin:PARAMETER_NAME \-\->

.TP
.fi
.B
<!\-\- end:PARAMETER_NAME \-\->
It allows you to separate a section of text and give it a name
It would be able to make them loop or conditional expression.
And, it can be nested.


.TP
.fi
.B
<!include:FILE_NAME>

.TP
.fi
.B
<!\-\- include:FILE_NAME \-\->
A file specified by FILE_NAME is simply inserted to a template file.
The template file will be treated as a merged template.
If you pass the path param to HTML::Template.new , include file will be searched under the path.
.SH HTML::Template CLASS
.PP
.SH CLASS METHODS
.PP

.TP
.fi
.B
HTML::Template.new(params = {})
Creates a HTML::Template object.
Given a file name to its first argument, use this file as a template.

Also you can pass params as Hash.
The options are below
.TP
.B
\(bu filename
template filename
.TP
.B
\(bu path
template search path.
you can specified as String or Array of String.
.SH METHODS
.PP

.TP
.fi
.B
HTML::Template#load(file)
Load template file.


.TP
.fi
.B
HTML::Template#set_html(html)
Setting up a string as a template.


.TP
.fi
.B
HTML::Template#param(hash = {})

.TP
.fi
.B
HTML::Template#expand(hash = {})
Specifies a string or a loop by Hash for a substitute. 
When specifying more than a loop simultaneously, value of the hash becomes an array.


.TP
.fi
.B
HTML::Template#node(name)

.TP
.fi
.B
HTML::Template#loop(name)

.TP
.fi
.B
HTML::Template#cond(name)
Stands a loop and a conditional expression specified by <!begin:name><!end:name>
Retrieves HTML::TemplateNode object.


.TP
.fi
.B
HTML::Template#output

.TP
.fi
.B
HTML::Template#to_s
Returns the final result.
.SH HTML::TemplateNode CLASS
.PP
This is a class for a loop or a conditional expression. 
An instance consists of HTML::Template Class and HTML::TemplateNode CLASS.
.SH METHODS
.PP

.TP
.fi
.B
HTML::TemplateNode#node(name)
Stands a loop or a conditional expression specified by <!begin:name><!end:name>
Returns HTML::TemplateNode object.
Is only used for nested.


.TP
.fi
.B
HTML::TemplateNode#param(hash = {})

.TP
.fi
.B
HTML::TemplateNode#expand(hash = {})

.TP
.fi
.B
HTML::TemplateNode#add(hash = {})
Specifies a string or a loop by Hash for a substitute. 
If you don't call the method, the block won't be displayed.
.SH A LOOP
.PP
This sample is a displaying list of environment valiables.
.nf
\&    <html>
\&    <body>
\&    <h1>Env List</h1>
\&    <hr>
\&    <!begin:envlist>
\&    <!var:key> : <!var:val><br>
\&    <!end:envlist>
\&    <hr>
\&    </body>
\&    </html>
\&    
\&    # In case of using it with iterator and replace data.
\&    require "html/template"
\&    tmpl = HTML::Template.new("filename" => "envlist.html")
\&    ENV.keys.sort.each do |k|
\&      tmpl.node("envlist").param({'key' => k,
\&                                  'val' => ENV[k]
\&                                 })
\&    end
\&    print "Content\-Type: text/html\\n\\n"
\&    print tmpl.output
\&    
\&    # In case of giving a loop as an array
\&    require "html/template"
\&    tmpl = HTML::Template.new("envlist.html")
\&    envlist = []
\&    ENV.keys.sort.each do |k|
\&      envlist.push({'key' => k,
\&                    'val' => ENV[k]
\&                   })
\&    end
\&    tmpl.param({'envlist' => envlist}) 
\&    print "Content\-Type: text/html\\n\\n"
\&    print tmpl.output
.fi
.SH A Conditional Expression
.PP
.nf
\&    <html>
\&    <body>
\&    <!begin:true>
\&    This is True
\&    <!var:foo>
\&    <hr>
\&    <!end:true>
\&    <!begin:false>
\&    This is False
\&    <!var:foo>
\&    <hr>
\&    <!end:false>
\&    </body>
\&    </html>
\&    
\&    
\&    require "html/template"
\&    tmpl = HTML::Template.new("cond.html")
\&    tmpl.param({'true' => {'foo' => 'foobar'}
\&               }) 
\&    print "Content\-Type: text/html\\n\\n"
\&    print tmpl.output
.fi
The performed result is below, however, a part not specied with the method isn't displayed.
.nf
\&    <html>
\&    <body>
\&    
\&    This is True
\&    foobar
\&    <hr>
\&    </body>
\&    </html>
.fi
.SH An attached Sample.
.PP

.TP
.fi
.B
env.rb
This sample is a simply replacing valiables.


.TP
.fi
.B
envlist.rb
This sample is a displaying list of environment valiables.
This sample is a case for using with iterator.


.TP
.fi
.B
envlist2.rb
Performed result is the same as the envlist.rb.'s.


.TP
.fi
.B
nest.rb
A sample of a nested loop.
.SH THANKS
.PP
English Documentation
NAKAYAMA Nao <nao_o@netlaputa.ne.jp>
thanks a lot :\-)
.SH AUTHOR
.PP
Copyright 2001 IKEBE Tomohiro 
This library is free software; you can redistribute it and / or modify it under the same terms as
Ruby itself.
IKEBE Tomohiro <ikechin@Oxfa.com>