
= Amrita quick start guide

== 1. hello world

Amritaˤ2٥APIޤΥץǤϹ٥APIΤ߰ޤ

٥API Amrita::Template  ƳФ줿 
Amrita::TemplateFile  Amrita::TemplateText Ȥ饹ʤꤿäƤޤ
Υ饹ϡ¾AmritaΥ饹򱣤Ƥޤ


=== HTML template

Ǥñʥƥץ졼ȤϼΤ褦ʤΤǤ

  :include: sample/hello/template.html

Amrita +id+ °äǤưŪǤȤưޤ
ơǥǡ +id+ °ͤ򥭡ˤƥǡФޤ


=== code

嵭Υƥץ졼ȤѤ̤ɸϤ˽Ϥ륳ɤϰʲΤ褦ˤʤޤ

  :include: sample/hello/hello.rb



Amrita::Templateϥƥץ졼Ȥȥǥǡߥå
ϤHTMLɥȤޤ

=== output

̤ϰʲΤ褦ˤʤޤ

  <html>
    <body>
      <h1>hello world</h1>
      <p>Amrita is a html template library for Ruby</p>
    </body>
  </html>

"hello world"ȤƥȤϡǥǡ+title+ȤǼ
 <tt>id="title"</tt>Ȥ°äǡʤ<tt><h1></tt>
ޤ

<tt><p id="body">...</p></tt>Ʊͤ˽ޤ

== 

AmritaϰʲΥƥåפǻѤޤ

1. ƥץ졼ȥեؤΥѥꤷơAmrita::TemplateFile 
   ֥Ȥ

      tmpl = TemplateFile.new("template.html")

2. ƥץ졼ŸΤΥǥǡ

      data = {
        :title => "hello world",
        :body => "Amrita is a html template library for Ruby"
      }

   ǥǡϤޤޤʷȤޤ
   ɬƥץ졼Ȥ +id+ Ǽ빽¤Ŭ礷Ƥɬפޤ
   ξϡƥץ졼ȤˤϤդĤ+id+äơ
   ͤ "title"  "body" Ǥ
   äơǥǡϤΤդĤΥбͤɬפޤ


3.  Amrita::Template#expand Ƥ
   
      tmpl.expand(STDOUT, data)

    +expand+ κǽΥѥ᡼ϥȥ꡼Ǥ
    Amrita << ᥽åɤˤäƷ̤Ϥޤ
    äơ << ᥽åɤĤǤդΥ֥
    (FileIO,String, Array)Ѥ뤳ȤǤޤ

---

== 2 list 

ΥץAmritaǷ֤Ԥʤˡޤ

֤ԤʤǤͿФǤԡޤ


=== code and output

code:

  :include: sample/hello/list.rb

output:

  <ul>        
    <li>1</li>
    <li>2</li>
    <li>3</li>
  </ul>       


=== description

   tmpl = TemplateText.new <<END
   <ul>                         
     <li id=list1>              
   </ul>                        
   END                          

ΥץǤ Amrita::TemplateText ѤƤޤ
Υ饹ϥƥץ졼ȤեǤʤʸȤƼޤ
¾ǤϡAmrita::TemplateFile Ʊͤ˻ѤǤޤ

    data = {                 
       :list1=>[ 1, 2, 3 ]   
    }

ǥǡǡȤƻHashǤ
HTMLǤбǥǡ(Enumerable)Ǥä硢
AmritaϤǤ򥳥ԡơ
줾γǤˤäŸޤ

    tmpl.prettyprint = true  
    tmpl.expand(STDOUT, data)

+prettyprint+ åȤƤȡ
Ϥޤ

---

== 3. table 

== code and output

code:

  :include: sample/hello/table.rb

output:

  <table>                    
    <tr>                     
    <th>name</th>            
    <th>author</th>          
    </tr>                    
    <tr>                     
    <td>Ruby</td>            
    <td>matz</td>            
    </tr>                    
    <tr>                     
    <td>perl</td>            
    <td>Larry Wall</td>      
    </tr>                    
    <tr>                     
    <td>python</td>          
    <td>Guido van Rossum</td>
    </tr>                    
  </table>                   

=== description

   <table border="1">                      
     <tr><th>name</th><th>author</th></tr> 
     <tr id="table1">                        
       <td id="name"><td id="author">      
     </tr>                                 
   </table>                                
   

   data = {                                               
      :table1=>[                                          
         { :name=>"Ruby", :author=>"matz" },              
         { :name=>"perl", :author=>"Larry Wall" },        
         { :name=>"python", :author=>"Guido van Rossum" },
      ]                                                   
   }                                                      

бǥǡʤΤǡ
<tt><tr id="table1">...</tr></tt> ʬ3󥳥ԡޤ
ơη֤ΤӤˡ
Ǥ <tt>{ :name=>"...", :author=>"..." }</tt> Ȥǡˤä
Ÿޤ

Τ褦ˡAmrita HTML +id+ Ǻ줿¤˥ǥǡƵŪ
ŬѤƤޤ
äơɤΤ褦ʣHTMLǤAmritaˤä뤳ȤǤޤ

---

== 4. conditional

⤷Ǥбǥǡ +nil+  +false+ ä硢
ǤϺޤ
εǽѤơ
ƥץ졼ȤǽϤʬ򤹤뤳ȤǤޤ


== code and output

code:

  :include: sample/hello/conditional.rb

output:

  <html>                                                     
    <body>                                                   
      <div>                                                  
        <h1>Group A</h1>                                     
        <div> This group has only one data: "only_one".      
        </div>                                               
      </div>                                                 
      <div>                                                  
        <h1>Group B</h1>                                     
        <div> Here's the list of this group's data.          
          <ul>                                               
            <li>one</li>                                     
            <li>two</li>                                     
            <li>three</li>                                   
          </ul>                                              
        </div>                                               
      </div>                                                 
      <div>                                                  
        <h1>Group C</h1>                                     
        <div>                                                
          <em>This group has no data.</em>                   
        </div>                                               
      </div>                                                 
    </body>                                                  
  </html>                                                    

=== description

Υƥץ졼Ȥˤ <tt><div id=...>...</div></tt> Ȥ꤬3Ĥ
ޤΤҤȤĤȤޤ+no_data+ +one_data+ +many_data+
ҤȤĤåȤƤޤ HashϥåȤƤʤФ
ϡ+nil+֤Τǡ +nil+ бʬϺޤ

ǥǡ+true+ξϡǥǡѹ줺ˤΤޤ޽Ϥ
ޤ

---
