File: html-template.ja.rd

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 (237 lines) | stat: -rw-r--r-- 5,366 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

=begin

= HTML::Template

HTML ƥץ졼ȤȤư Ruby ⥸塼

== HTML::Template Ȥϡ

CGI ץ顢HTML Υƥץ졼Ȥ򰷤⥸塼Ǥ
ǥȥåδʬΥñ˽ޤ

¿Ť˥ͥȤ֥å(롼סʬ)򰷤ޤ

ŪˤϰʲΤ褦ʤȤޤ

ƥץ졼ȥե test.html

 <HTML>
 <HEAD><TITLE>Test Template</TITLE>
 <BODY>
 My Home Directory is <!var:home>
 <P>
 My Path is set to <!var:path>
 </BODY>
 </HTML>

Ruby ץ
 
 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

== 󥹥ȡ

install.rb ѤƤޤ

 % 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

== ƥץ졼ȥե

=== ƥץ졼ȤǻѤǤ륿

ƤΥȼ⤷ɸŪ HTML ȤȤƵҤ뤳ȤǽǤ

--- <!var:PARAMETER_NAME>
--- <!-- var:PARAMETER_NAME -->
    HTML::Template#param({PARAMETER_NAME => VAL}) Ƥ֤ȡñ VAL Ѵޤ

--- <!begin:PARAMETER_NAME>
--- <!end:PARAMETER_NAME>
--- <!-- begin:PARAMETER_NAME -->
--- <!-- end:PARAMETER_NAME -->
    Ϥޤ줿ϰϤ֥åȤơ롼סʬԤޤ
    Ҥˤ뤳ȤǽǤ
    PARAMETER_NAME ƱؤˤƤϡˡǤɬפޤ

--- <!include:FILE_NAME>
--- <!-- include:FILE_NAME -->
    FILE_NAME ǻꤵ줿եȤִޤ
    ƥץ졼ȥեꤹȡ礭ʰĤΥƥץ졼ȤȤƼ갷ޤ
    󥹥ȥ饯 path ѥ᡼ϤƤϤõޤ

== HTML::Template 饹

=== 饹᥽å

--- HTML::Template.new(params = {})
     HTML::Template ֥Ȥ롣
    ˥ե̾򤢤ȡΥեƥץ졼ȤȤƻѤޤ

    ѥ᡼ϥåȤͿǽǤ
    ʲΥץ󤬻ѤǤޤ

* filename

  ƥץ졼ȤΥե̾ꤷޤ

* path

  ƥץ졼Ȥõѥꤷޤ
  ʸ󡢤⤷ʸʣꤹ뤳ȤǽǤ


=== ᥽å

--- HTML::Template#load(file)
    ƥץ졼ȥե

--- HTML::Template#set_html(html)
    ʸƥץ졼ȤȤƥå

--- HTML::Template#param(hash = {})
--- HTML::Template#expand(hash = {})
    ִʸ󡢥롼פϥåǻꤹ롣
    롼פƱ˻ꤹϡϥåͤȤʤ롣

--- HTML::Template#node(name)
--- HTML::Template#loop(name)
--- HTML::Template#cond(name)
    <!begin:name><!end:name> ǻꤵ줿롼סʬ򼨤 HTML::TemplateNode ֥Ȥ֤

--- HTML::Template#output
--- HTML::Template#to_s
    ƥץ졼Ȥκǽ̤֤ޤ

== HTML::TemplateNode 饹

롼סʬɽ뤿Υ饹Ǥ
󥹥󥹤 HTML::Template 饹HTML::TemplateNode 饹ˤޤ

=== ᥽å

--- HTML::TemplateNode#node(name)
    <!begin:name><!end:name> ǻꤵ줿롼סʬ򼨤 HTMl::TemplateNode ֥Ȥ֤
    ҹ¤ξ˻ѡ

--- HTML::TemplateNode#param(hash = {})
--- HTML::TemplateNode#expand(hash = {})
--- HTML::TemplateNode#add(hash = {})

    ִʸ󡢥롼פϥåǻꤹ롣
    Υ᥽åɤ٤ƤФʤä硢Υ֥åɽޤ

== 롼פλȤ

Ķѿꥹɽ륵ץǤ

  <html>
  <body>
  <h1>Env List</h1>
  <hr>
  <!begin:envlist>
  <!var:key> : <!var:val><br>
  <!end:envlist>
  <hr>
  </body>
  </html>

  # ƥ졼ȶѤƥǡִ
  require "html/template"
  tmpl = HTML::Template.new("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

  # 롼פͤȤͿ硣
  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


== ʬˤĤ

  <html>
  <body>
  <!begin:true>
   True Ǥ
  <!var:hoge>
  <hr>
  <!end:true>
  <!begin:false>
   False Ǥ
  <!var:hoge>
  <hr>
  <!end:false>
  </body>
  </html>

  
  require "html/template"
  tmpl = HTML::Template.new("cond.html")
  tmpl.param({
	     'true' => {'hoge' => 'ۤۤ'}
	     }) 
  print "Content-Type: text/html\n\n"
  print tmpl.output

¹Է̤ϰʲΤ褦ˤʤꡢparam ᥽åɤǻꤵʤäʬɽޤ

  <html>
  <body>

   True Ǥ
  ۤۤ
  <hr>
  </body>
  </html>

== °ץˤĤ

:env.rb , env.html 
	ñʸִΥץǤ

:envlist.rb
        ĶѿΥꥹȤɽ륵ץǤ
        ƥ졼ȶ˻ѤΥץǤ

:envlist2.rb
        ¹Է̤ envlist.rb ƱͤǤ
        ǥ롼פΥץǤ

:nest.rb
        ͥȤ롼פΥץǤ

== 饤,

 IKEBE Tomohiro ݻޤ
Ruby ƱͤΥ饤󥹤ΤȤǡͳѤǤޤ

IKEBE Tomohiro <ikechin@0xfa.com>

=end