File: Tour2

package info (click to toggle)
ruby-amrita 1.0.2-10
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,940 kB
  • sloc: ruby: 9,159; xml: 978; makefile: 78
file content (379 lines) | stat: -rw-r--r-- 8,836 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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379

= Amrita tour2

This document describes features not fixed until V1.0.
So these features may be modified later.
---
== parts tempalte (experimental)

=== code and output

code:

  :include: sample/tour/parts1.rb

output:

    <html> 
      <body>  
        <h1>Scripting Languages</h1>   
        <ul> 
          <li>Ruby</li>
          <li>Perl</li>
          <li>Python</li>
        </ul>  
        <table>  
          <tr> 
          <td>Ruby</td>
          <td>matz</td>
          <td><a href="http://www.ruby-lang.org/">http://www.ruby-lang.org/</a></td>
          </tr>  
          <tr> 
          <td>perl</td>
          <td>Larry Wall</td>
          <td><a href="http://www.perl.com/">http://www.perl.com/</a></td>
          </tr>  
          <tr> 
          <td>python</td>
          <td>Guido van Rossum</td>
          <td><a href="http://www.python.org/">http://www.python.org/</a></td>
          </tr>  
        </table> 
      </body> 
    </html>

=== description

If you want to add a presentation to a Class like this,

  class Header
    attr_reader :title
    def initialize(title)
      @title = title
    end
  end

write a template for it and install the template to the Class.

  <span class=Header>
    <h1 id=title></h1>  
  </span>

Now, the Header object has the ability to show itself as a HTML data

   h = Header.new("Scripting Languages")

   puts h.to_s # => <h1>Scripting Languages</h1>   

And if it was used as a part of model data, it will be embeded in the
HTML document.

You can install the parts template in another module and select
view-module at runtime. For detail see sample/tour/parts2.rb

---


== attribute expand (experimental)

=== code and output

code:

  :include: sample/tour/makeurl2.rb

output:
  
   <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>                                                              


=== description

   tmpl.expand_attr = true

If this attribute was set, then amrita checks all attribute values and
convert it with model data if the value in template begins "@" like
"@url".


---

== merge two template (experimental)

You can merge template with Amrita::MergeTemplate

=== code and output

code:

  :include: sample/tour/merge_template.rb

output:

  <html>
    <head>
      <title>Insertion MockUp</title>
    </head>
    <body>
      This comes from a template fragment:
      <b>Hello World!</b>
    </body>
  </html>


=== description

    <body id="data">
      This comes from a template fragment:
      <span id="another_template.html#insert_me">This will be replaced.</span>
    </body>

    model_data = { :data => MergeTemplate.new}
    tmpl.expand(STDOUT, model_data)

MergeTemplate is a special model object that takes
<tt>id="filename#tag"</tt> as template insertion.

MergeTemplate read from +filename+ and search +id+ with +tag+ and
insert it to the original temaplte.

You can recursive expansion to the merged template. For detail see
sample/tour/merge_tempalte2.rb

---

== cgikit interface (experimental)

CGIKit(http://www.spice-of-life.net/download/cgikit/index_en.html) is
a CGI application framework with Ruby. This framework bases component
for development, you will develop CGI application speedy and
efficiency.

amrita has an interface to cgikit. You can use CKAmritaElement with
other standard componet of cgikt.

=== code and output

HelloWorld.cgi:

    require 'amrita/cgikit' 

    app = CKApplication.instance
    app.run

MainPage/MainPage.html

    <html>
    <head>
    <title>Hello World</title>
    </head>
    <body>

    <h1>
    <CGIKIT NAME=HelloWorld>
      <span id="hello"></span>
    </CGIKIT>
    </h1>

    </body>
    </html>

MainPage/MainPage.ckd

    HelloWorld : CKAmritaElement {
      hello = sayHello;
    }

MainPage/MainPage.rb

    class MainPage < CKComponent
	def sayHello
		"Hello World!"
	end
    end


output:

    Hello World!

=== description 

The html source between <CGIKIT>...</CGIKIT> is provided as the
template for amrita if the NAME for it is assined to CKAmritaElement
in ckd file.

Other source is treated by cgikit as usual. So you can use amrita
(CKAmritaElement: a cgikit componet with amrita template engine) with
other cgikit's standard componets.

CKAmritaElement gets the model data from cgikit. 

  * the method of main page object ( parent componet )

    the +id+ attribute value is use for method search.
    you can assign different name for it in ckd file.

  * a value assigned in ckd file

  * a value dynamically assinged by other componets

I think it's better to use cgikit for FORM and action ( a button can
be binded to a Ruby method easily) and use amrita for displaying the
result.

see sample/cgikit/Examples for detail.

---

== Amrita Script (experimental)

AmritaScript is an experimental feature that packs a template with the
model data for it.

=== code and output

code:

  :include: sample/tour/amstest.ams

output:

  $ ams amstest.ams

  <html>
    <body>
      <h1>hello world</h1>
      <p>Amrita is a html template libraly for Ruby</p>
      <hr>
      Wed Aug 07 18:12:38 JST 2002/
      last-modified Wed Aug 07 08:44:33 JST 2002
     </body>
  </html>

=== description

The command +ams+ (provided at bin/ams with amrita) extracts text in
<tt><amritascript> <!-- ...  //--></amritascript></tt> and +eval+ as a
Ruby code to use it as a model data for amrita.


---

== amx: yet anothor style-sheet for XML (experimental)

amx(AMrita eXtention for XML) is a style-sheet for XML. It converts an
XML document to HTML. You can use amrita template for specifing the
output format.

=== code and output

source document:

  :include: sample/tour/amxtest.xml
  
template:

  :include: sample/tour/amxtest.amx

output:

   <html>
      <body>
        <title>amx sample</title>
        
          <p>
      amx is a XML document.
      It contains model data as well-formed XML, HTML template 
      and a small Ruby code map both.
    </p><p>
      This is a sample AMX document.
    </p>
        
        <hr />
        Fri Aug 23 13:35:02 JST 2002
      </body>
    </html>

=== description

To use amx, type this command from command line

   $ amx amxtest.xml

The source document can be any well-formed XML document with an
instruction

  <?amx href="index.amx" ?>

href attribute is the path for amx-template.

amx loads the template file and generate a template object from it.
The template file is a special XML document and has two parts

* <template> element

  this is a normal amrita template

* <method> element

  by this element, you can define a method in the template
  object. 

the template object is a Amx::Template object. It will make a model
data from source document loaded as a REXML DOM tree.

=== more information

The top page of amrita is generated by amx. 

[docs/index.xml] source document
[docs/index.amx] template document
[docs/amritadoc.rb] additional Ruby code

detail spec of amx is not fixed yet.

If you want to use amx, feel free to mail me. I will make a sample for
you if you gave me ....

* source XML document
* desired output HTML document 

These samples will be attached to the next release of amrita archive.

I will fix the spec and write a document for this feature after I've
got enough requests and samples.

---

== X

=== code and output

code:

output:

=== description