File: Tour_ja

package info (click to toggle)
amrita 1.0.2-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 1,880 kB
  • ctags: 1,363
  • sloc: ruby: 9,159; xml: 978; makefile: 111
file content (274 lines) | stat: -rw-r--r-- 8,139 bytes parent folder | download | duplicates (4)
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

= Amrita ĥ

==  HTMLǤ°ѹ

href="..." Τ褦°ͤѹˡޤ

:

  :include: sample/tour/makeurl.rb


:

   <table border="1">                                                    
     <tr>                                                                
     <th>name</th>                                                       
     <th>author</th>                                                     
     <th>webpage</th>                                                    
     </tr>                                                               
     <tr>                                                                
     <td>Ruby</td>                                                       
     <td>matz</td>                                                       
     <td><a href="http://www.ruby-lang.org/">Ruby Home Page</a></td>     
     </tr>                                                               
     <tr>                                                                
     <td>perl</td>                                                       
     <td>Larry Wall</td>                                                 
     <td><a href="http://www.perl.com/">Perl.com</a></td>                
     </tr>                                                               
     <tr>                                                                
     <td>python</td>                                                     
     <td>Guido van Rossum</td>                                           
     <td><a href="http://www.python.org/">Python Language Website</a></td>
     </tr>                                                               
   </table>                                                              


=== 

Amrita#a() Ȥ᥽åɤ Amrita::AttrArray Ȥ̤ʥ֥Ȥޤ

    a(:href=>"http://www.ruby-lang.org/") { "Ruby Home Page" },

Υ֥ȤǥǡȤƻѤȡHTMLǤ°ѹޤ
㤨СΤ褦ʥƥץ졼ȤˤΥǡͿȤ

    <td><a id="webpage"></a></td>

ϤϼΤ褦ˤʤޤ

    <td><a href="http://www.ruby-lang.org/">Ruby Home Page</a></td>     

docs/XML_ja Ƥ filelist.rb ȤץAttrArrayѤƤޤ

ʤ°Ÿ̤ˡ⤢ޤܤ docs/Tour2 expand_attr 򻲾ȤƤ

---

== Proc֥

ǥǡ+id+°Υޥå󥰤Ȥamritaäˡϡ
ץǸ̤Τ褤ɤǽˤޤ

Τ褦ˡǤϤ줤˽ʤ⵩ˤ¸ߤޤ
+Proc+ ֥ȤǥǡȤͿȡ
³Ū˥ƥץ졼Ȥѹ뤳ȤǤޤ

=== ɤȽ


:

  :include: sample/tour/proc.rb

:

   <ul> 
     <li><font color="black">java</font> </li>
     <li><em><font color="red" size="big">I love Ruby!</font></em> </li>
     <li><font color="blue">perl</font> </li>
     ...
   </ul>

=== 

ǥǡȤ Proc ֥ȤϤȡamrita ϡ
ƥץ졼ŸˡProc ƤӽФޤ
κݡѥ᡼Ȥơб +id+ ΤĤHTMLǤ Amrita::Element ֥ȤȤ
Ϥޤ
ơ Proc η̤ȥƥץ졼Ȥ֤ޤ

 Proc ǡΤ褦ʥ᥽åɤѤƼͳ˥ƥץ졼ȤԽ뤳ȤǤޤ


°ͤ

     elem[:color] = "red" 


Ǥ˥ƥȤꤹ

     elem.set_text("I love Ruby!")

Amrita#e ᥽åɤˤäơHTMLǤ

     e(:em) { elem } 


---

== ¸Υ饹ǥǡȤƻѤ

HashArrayǤʤ
¸Υ饹(Rubyɸ९饹桼Υ饹)Υ֥Ȥ
Τޤޡamrita ΥǥǡȤƻѤǤ

=== ɤȽ

:

  :include: sample/tour/time.rb


:

  2002/7/17

=== 

⤷ǥǡAmrita::ExpandByMember Ȥ⥸塼includeƤ顢
amrita +id+ °ͤ᥽å̾ȸʤơΥ᥽åɤƤӽФޤ

ΥץǤϡ+:time+бǡϡRubyɸTime֥ȤǤ
ExpandByMember ⥸塼 +extend+ Ƥޤ
 +id+°ͤǤ +year+ ᥽å̾Ȥߤʤamrita
+t+ ФƤΥ᥽åɤθƽФԤޤ

η <tt><span id="year"></span></tt> Ȥʬϡ
<tt>t.year</tt>η "2002" Ÿ졢¾ʬƱͤ˽
Τ褦Ÿޤ

  <span><span>2002</span>/<span>7</span>/<span>17</span></span>

amrita  °Τʤ <tt><span></tt> ǤϺޤΤǡǽŪʽϤ

  2002/7/17

Ȥʤޤ

---

== ץꥳѥ

amrita  HTML ƥץ졼Ȥ Ruby Υɤ˥ѥ뤹뤳ȤǤޤ

=== ɤȽ

(table.rb˥ѥѤ뤿ɲäʬ) :

  tmpl = TemplateText.new(TEMPLATE)
  tmpl.use_compiler = true
  tmpl.set_hint_by_sample_data(data) # ɲäȤΥǡ˺Ŭޤ
  tmpl.expand(STDOUT, data)  #
  puts "----code generated by Amrita -----------"
  puts tmpl.src
  puts "----code generated by Amrita end -------"

Ϥtable.rbƱǤ
ѥνϤɤȥ٥ޡɲäƤޤ

Crusoe TM5600ޥ(NEC Lavie MX)ǤνϤϼΤ褦ˤʤޤ

  43.068354 seconds for 1000 times without compiling
  5.078764 seconds for 1000 times with pre-compiled code


=== 

ŪˤϡνɲäǥѥѤǤޤ

  tmpl.use_compiler = true

ʹߡ+expand+ ϥѥ뤵줿RubyɤǼ¹Ԥޤ
prettyprintεǽϥݡȤޤ󤬡ʳƱ̤ˤʤޤ

ץǡѤơŬԤʤˤϼνɲäޤ

And optionally give a sample data to amrita.

  tmpl.set_hint_by_sample_data(data)

amritaΥѥϡΥǡϤRubyɤκŬΤ˻Ѥޤ
äơϤǥǡι¤Ѳ顢١οǡ
+set_hint_by_sample_data+ Ƥɬפޤ

amritaΥѥϡʬŪ˥󥿥ץ꥿⡼ɤޤ뤳ȤǤޤ
ʬŪ˹¤ѲǡФơѥѤϡ
ץǡбʬ(Ѳǡʬ)ˡ+nil+ Ϥɬפޤ

ѥϡElement::expandѤ褦ʥɤбĽޤ

Τ褦ˤơԡɤȽΥȥ졼ɥդͳ˼뤳ȤǤޤ

---

== ˥ -- XSS(ȥץƥ)к

amritaˤϡXSSкȤơAmrita::Sanitizer Ȥ⥸塼뤬ȹޤƤޤ
Amrita::Formatter ϼưŪˤΥ⥸塼Ѥޤ

I will provide interface to controle sanitizer through
Amrita::Template in future release.

=== ɤȽ

  :include: sample/tour/sanitizer.rb

=== 

==== ƥ

xhtml/html ΥƥȤȤƴʸ(<>&) ϼưŪ˥פޤ

    "<abc>" => "&lt;abc&gt;"

==== °

°ͤȤƴʸ(<>&"')ϼưŪ˥פޤ

==== URL°ΰ

<a>Ǥhref°Τ褦ˡURLͤȤƻ°ͤϡ̰ޤ

ɤ°̰ͤ뤫ξܺ٤ˤĤƤ tag.rb 򻲾ȤƤ

°ͤϡΤ褦ˤ˸åޤ

  * °ͤURLȤƵʤʸĤȤϤǤޤ
  * °ͤϵʤ(ץȥ)ĤȤϤǤޤ

ξ˰ȿ顢°ͤnil֤<tt><a href="">....</a></tt>
Τ褦ɽޤ

Τ褦+setup_taginfo+ ᥽åɤ뤳Ȥǡ
ɤ°򤳤Τ褦˰(ʤ)򥫥ޥ뤳ȤǤޤ


    t = TemplateFile.new ...

    def t.setup_taginfo
      ret = TagInfo.new
      ret[:aaa].set_url_attr(:bbb)
      ret
    end

ξϡ +aaa+Ǥ+bbb+°ϡURLȤƥ˥ޤ

==== ˥̵ˤ

Amrita::SanitizedString ֥Ȥǥǡ˴ޤ뤳Ȥǡ
εǽ̵ˤ뤳ȤǤޤ

    t = TemplateText.new '<p id="a">sample_text</p>'
    t.expand(STDOUT, { :a=>"<xxx>" })                  # => <p>&lt;xxx&gt;</p>
    t.expand(result, { :a=>SanitizedString["<xxx>"] }) # => <p><xxx></p>

εǽϡXSSˤĤ򤷤ǡʬդѤƤ

ʤ⤦ҤȤƱͤθ̤ˡȤơ<tt>escape {...} </tt> 
ǥǡϤȤˡ⤢ޤ

---