TITLE::Introduction of Amrita2
HEADER::Introduction of Amrita2
CHAPTER::Index
FOOTER::Amrita2の紹介
Introduction
of
Amrita2
----
HEADER::Index
FOOTER::内容
ALIGN::Left
1. What is [Template]?
2. What is [Template Engine]?
3. What is [Amrita]?
4. What is [Amrita2]?
----
HEADER::What is Template?
FOOTER::Templateとは何か?
CHAPTER::What is Template?
ALIGN::Left
What is Template?
----
HEADER::What is Template?
FOOTER::Templateとは何か?
ALIGN::Left
"Template is a [[EM:String]]" Model
vs
"Template is a [[EM:structured document]]" Model
テンプレートは文字列なのか構造のあるドキュメントか?
----
HEADER::What is Template?
FOOTER::Templateとは何か?
ALIGN::Left
HTML/XML document is a
[[EM:structured document]]
[[PRE:
<html>
<body>
<h1>
"Hello, world!"
</h1>
</body>
</html>
]]
HTMLテキストは構造化されている
----
HEADER::What is Template?
FOOTER::Templateとは何か?
ALIGN::Left
But, most of template engines
treat it as a [[EM:String]]
[[PRE:
"<html><body><h1>Hello, <%= name %></h1></body></html>"
]]
しかし、文字列として扱われている
----
HEADER::What is Template?
FOOTER::Templateとは何か?
Template can be a [[EM:structured document]]
[[PRE:
<html>
<body>
<h1>
"Hello, "
<span id='name' />
</h1>
</body>
</html>
]]
構造化されたテンプレートがあったっていいのでは?
----
HEADER::What is Template Engine?
CHAPTER::What is Template Engine?
FOOTER::テンプレートエンジンとは何か?
ALIGN::Left
What is Template Engine?
----
HEADER::What is Template Engine?
FOOTER::テンプレートエンジンとは何か?
"Template Engine is an [[EM:environment]]" Model
(Engine is passive and Template is active)
VS
"Template Engine is an [[EM:operator]]" Model
(Template is passive and Engine is active)
実行環境か演算か?
----
HEADER::What is Template Engine?
FOOTER::テンプレートエンジンとは何か?
ALIGN::Left
"Template Engine is an [[EM:environment]]" Model
(Engine is passive and Template is active)
[[PRE:
<h1>
"Hello, "
<%- if name -%>
<%= h(name) %>
<%- else -%>
Guest
<%- end -%>
</h1>
]]
----
HEADER::What is Template Engine?
FOOTER::テンプレートエンジンとは何か?
"Template Engine is an [[EM:operator]]" Model
(Template is passive and Engine is active)
(Template)
[[PRE:
Hello, <span id='name'>!
]]
+
(Data)
[[PRE:
{ :name => "David" }
]]
↓
[[PRE:
Hello, David!
]]
----
HEADER::What is Template Engine?
FOOTER::テンプレートエンジンとは何か?
With Template Engine as an [[EM:environment]],
(active templates)
you should verify [[EM:each]] [template] to verify the system.
With Template Engine as an [[EM:operator]],
(passiv templates)
you can need to verify the system
by verifing only [[EM:one]] [Engine].
エンジンが環境ならば、個々の[テンプレート]を検証する必要あり
エンジンが演算ならば、[エンジン]を検証すればよい
----
name = "<script>cracking code</script>"
+ Hello, <span id='name'> =
Hello, <script>......
+ "Hello, <%= name %>" =
Hello, <script>cracking code</script>"
----
HEADER::What is Amrita?
CHAPTER::What is Amrita?
FOOTER::Amritaとは何か?
Amrita is an Template Engine with
"Template is a [[EM:structure document]]" Model
+
"Template Engine is an [[EM:operator]]" Model
----
(CODE)
[[PRE:
require "amrita/template"
include Amrita
tmpl = TemplateText.new <<END
<html>
<body>
<h1 id='title'> </h1>
<p id='body'> </p>
</body>
</html>
END
tmpl.expand(STDOUT, :title=>"hello world",
:body=>"Amrita")
]]
----
(OUTPUT)
[[PRE:
<html>
<body>
<h1>hello world</h1>
<p>Amrita</p>
</body>
</html>
]]
----
(Template)
[[PRE:
Hello, <span id='name'>!
]]
+
(scalar)
[[PRE:
{ :name => "David" }
]]
↓
[[PRE:
Hello, David!
]]
----
(Template)
[[PRE:
<ul><li id='list' /></ul>
]]
+
(Enumerable)
[[PRE:
{ :list => [1,2,3] }
]]
↓
[[PRE:
<ul>
<li>1</li><li>2</li><li>3</li>
</ul>
]]
----
(Template)
[[PRE:
<span id='tag'>Boolean data</span>
]]
+
(true)
[[PRE:
{ :tag => true }
]]
↓
(output the same element)
[[PRE:
Boolean data
]]
----
(Template)
[[PRE:
<span id='tag'>Boolean data</span>
]]
+
(false or nil)
[[PRE:
{ :tag => nil }
]]
↓
[[PRE:
(nothing)
]]
----
(Template)
[[PRE:
<p id='time'>
<span id='hour' />:
<span id='min' />:
<span id='sec' />
</p>
]]
+
(plain Ruby object)
[[PRE:
{ :time => Time.now }
]]
↓
(output)
[[PRE:
<p>11:21:30</p>
]]
----
HEADER::What is Amrita2?
FOOTER::Amrita2とは何か?
CHAPTER::What is Amrita2?
What is Amrita2?
----
Amrita2 =
Amrita(V1.x)
+
"Template Engine as an environment" Model
(partial ERb template)
+
α
----
Amrita
on
Rails
----
ALIGN::Left
HEADER::partial ERb template
FOOTER::部分的ERbテンプレート
tmpl = TemplateText.new <<END
<html>
<body>
<h1 id='title'><![CDATA[
[[EM:<%= $_.upcase %>]]
]]></h1>
<p id='body'><![CDATA[
[[EM:<%= $_.sub('Amrita', 'Amrita2') %>]]
]]></p>
</body>
</html>
END
[[EM:tmpl.use_erb(binding)]]
tmpl.expand(STDOUT, :title=>"hello world",
:body=>"Amrita is a html template libraly for Ruby")
----
HEADER::partial ERb template
FOOTER::部分的ERbテンプレート
ALIGN::Left
(OUTPUT)
<html>
<body>
<h1>
[[EM:HELLO WORLD]]
</h1>
<p>
[[EM:Amrita2]] is a html template libraly for Ruby
</p>
</body>
</html>
----
HEADER::amrita:type
FOOTER::amrita:type
ALIGN::Left
[[PRE:
<a id='ruby_home' amrita:type='link'>Ruby Home Page</a>
]]
Amrita2 is HTML to Ruby [compiler].
amrita:type attribute is [compiler options].
Amrita2はHTML to Ruby [コンパイラ]
amrita:type属性は[コンパイラオプション]
----
HEADER::amrita:type='link'
FOOTER::amrita:type='link'
ALIGN::Left
tmpl = TemplateText.new <<END
<a id='ruby_home' amrita:type='link'>Ruby Home Page</a>
END
tmpl.expand(STDOUT,
:ruby_home=>"http://www.ruby-lang.org/")
#→[<a href='http://www.ruby-lang.org/'>Ruby Home Page</a>]
tmpl.expand(STDOUT,
:ruby_home=>["http://www.ruby-lang.org/",
"Rubyホームページ"])
#→[<a href='http://www.ruby-lang.org/'>Rubyホームページ</a>]
----
HEADER::amrita:type='use_args'
FOOTER::amrita:type='use_args'
ALIGN::Left
tmpl = TemplateText.new <<END
<span id='raa' amrita:type='use_args'>
<a href="http://raa.ruby-lang.org/project/[[EM:$1]]">[[EM:$2]]</a>
</span>
END
tmpl.expand(STDOUT,
:raa=>t("amrita", "amrita template library"))
# t() makes a Amrita2::Tuple object
↓
<span>
<a href='http://raa.ruby-lang.org/project/[[EM:amrita]]'>
[[EM:amrita template library]]
</a>
</span>
----
HEADER::Amrita2 on Rails
FOOTER::Amrita2 on Rails
ALIGN::Left
To use Amrita2 with Ruby on Rails,
1. [$ ln -s (Amrita2 root path) (RailsAppRoot)/vendor/plugin/amrita2]
2. make [*.a2html templates]
Ruby on Rails でAmrita2を使うには
----
HEADER::a real world example
FOOTER::実業務での使用例
ALIGN::Left
[[image src="coreserve.png" width="533" height="541"]]
[[http://f.hatena.ne.jp/amrita2/20060602174940]]
[[http://www.brain-tokyo.net:3000/]]
----
HEADER::What is Amrita2?
FOOTER::Amrita2とは何か?
ALIGN::Left
(ERb version)
<ul>
<%- case current_user -%>
<%- when nil -%>
<li><%= link_to 'ログイン', :controller => 'client',
:action => 'login' %></li>
<li><%= link_to '新規ユーザ登録', :controller => 'client',
:action => 'signup' %></li>
<%- when Counselor -%>
<li><%= link_to 'ログアウト', :controller => 'client',
:action => 'logout' %></li>
....
<%- end -%>
</ul>
----
HEADER::What is Amrita2?
FOOTER::Amrita2とは何か?
ALIGN::Left
(Amrita2 version)
<ul>
<li id='navi_links'>
<a id='link' amrita:type='link' />
</li>
</ul>
----
HEADER::What is Amrita2?
FOOTER::Amrita2とは何か?
ALIGN::Left
(Amrita2 version controller)
case current_user
when nil
@navi_links = [
{ :link => [
url_for( :controller => 'client', :action =>'login'),
'ログイン'
]
},
{ :link => [
url_for( :controller => 'client', :action =>'signup'),
'新規ユーザ登録'
]
}
]
when Counselor
@navi_links = [
{ :link => [
url_for( :controller => 'client', :action =>'logout'),
....
----
ALIGN::Left
It's easy to test
def test_index_for_client
get :index, {}, :user => @cl1
assert_response :success
[[EM:assert_equal "http://test.host/client/login",
assigns[:navi_links][:link][0]]]
end
テストが簡単
----
ALIGN::Left
Separate [[EM:view logics]]
from [[EM:presentation]]
----
ALIGN::Left
<table class="confirm">
<tr>
<th>カウンセラー</th>
<th><%= human_attribute_name(CounselingSession, 'status') %></th>
<th><%= human_attribute_name(CounselingSession, 'start') %></th>
<th><%= human_attribute_name(CounselingSession, 'end') %></th>
<th><%= human_attribute_name(CounselingSession, 'place') %></th>
<th><%= human_attribute_name(CounselingSession, 'memo') %></th>
<th><br></th>
</tr>
<%- for counseling_session in @counseling_sessions -%>
<tr>
<td><%=h counseling_session.counselor_name %></td>
<td><%=h counseling_session.status_j %></td>
<td><%=h human_attribute_value(counseling_session, 'start') %></td>
<td><%=h human_attribute_value(counseling_session, 'end') %></td>
<td><%=h human_attribute_value(counseling_session, 'place') %></td>
<td><%=h human_attribute_value(counseling_session, 'memo') %></td>
<%- case counseling_session.status -%>
<%- when :free -%>
<%- case current_user -%>
<%- when nil,Client -%>
<td><%= link_to '予約', :action => 'reserve', :id => counseling_session %></td>
<%- else -%>
<td />
<%- end -%>
<%- when :reserved -%>
<%- if current_user == counseling_session.client -%>
<td><%= link_to 'キャンセル', :action => 'cancel', :id => counseling_session %></td>
<%- else -%>
<td />
<%- end -%>
<%- else -%>
<td />
<%- end -%>
</tr>
<%- end -%>
</table>
----
ALIGN::Left
<table class="confirm">
<tr>
<th id='list_titles'></th>
</tr>
<tr id='counseling_sessions'>
<td id='counselor_name' />
<td id='status' />
<td id='start' />
<td id='end' />
<td id='place' />
<td id='memo' />
<td id='navi'>
<a id='navi_link' amrita:type='link' />
</td>
</tr>
</table>
----
ALIGN::Left
@counseling_sessions = sessions.collect do |s|
{
:counselor_name => s.counselor_name,
:status => s.status_j,
:start => human_attribute_value(s, 'start'),
:end => human_attribute_value(s, 'end'),
:memo => human_attribute_value(s, 'memo'),
:place => human_attribute_value(s, 'place'),
:navi => {
:navi_link =>
case s.status
when :free
case current_user
when nil,Client
[ url_for(:action => 'reserve', :id => s), '予約']
else
end
when :reserved
if current_user == s.client
[ url_for(:action => 'cancel', :id => s), 'キャンセル', ]
end
end
}
}
end
----
HEADER::Low level API
FOOTER::Low level API
ALIGN::Left
[[PRE:
tmpl.expand(STDOUT) do |m|
m.title("hello world")
m.body("Amrita2")
end
]]
m is a [compiled Ruby module].
title() and body() are [static Ruby methods].
To speed up template processing,
1. find [hot spots].
2. use low level API.
3. Give [optimizing options] to it.
----
HEADER::Schedule
CHAPTER::Summary
FOOTER::スケジュール
ALIGN::Left
Schedule
----
HEADER::Schedule
FOOTER::スケジュール
ALIGN::Left
?
----
TITLE::Introduction of Amrita2
HEADER::Introduction of Amrita2
CHAPTER::Summary
FOOTER::Amrita2の紹介
ALIGN::Left
Links
* [[http://amrita2.rubyforge.org/]]
* [[http://d.hatena.ne.jp/amrita2/]]
Thanks to
* [[高橋メソッドなプレゼンツール in XUL リターンズ|http://piro.sakura.ne.jp/xul/applications/takahashi-r/]]
----
HEADER::Introduction of Amrita2
FOOTER::Amrita2の紹介
または
[gem戦記]
(新ブログタイトル)
で検索
----
HEADER::Thank you
FOOTER::presented by essa
[[image src="http://amrita.s14.xrea.com/files/essa.jpg" width="333" height="341"]]