Amrita2 - a xml/xhtml template library for Ruby
Summary
Amrita2 is a a xml/xhtml template library for Ruby. It makes html documents from a template and a model data.
Key feature
specify "XML template" do
t = Amrita2::Template.new <<-END
<html>
<head>
<title am:src="page_title" />
</head>
<body>
<h1 am:src="header_title" />
<p class="text" am:src="text">
<span am:src="template" /> is a html template library for <span am:src="lang" />
</p>
</body>
</html>
END
data = {
:page_title=>'Amrita2',
:header_title=>'Hello, Amrita2',
:text=>{
:template => 'Amrita2',
:lang => 'Ruby'
}
}
expected = <<-END
<html>
<head>
<title>Amrita2</title>
</head>
<body>
<h1>Hello, Amrita2</h1>
<p class="text">Amrita2 is a html template library for Ruby</p>
</body>
</html>
END
#
t.render_with(data).should_be_samexml_as(expected)
t2 = Amrita2::Template.new <<-END
<<html<
<<head<
<<title:page_title>>
<<body<
<<h1:header_title>>
<<p class="text":text<
<<:template>> is a html template library for <<:lang>>
END
#
t2.render_with(data).should_be_samexml_as(expected)
end
-
The template for amrita2 is a pure html/xhtml document without no special tag like <?…?> or <% .. %>
-
The template can be written by designers using almost any xhtml/xml Editor.
-
Need no change on Ruby code to change the view of dynamic part (not only static part) of the template
-
The model data may be standard Ruby data, Hash, Array, String… or an instance of a classes you made.
-
The output is controlled by data not by logic. So It’s easy to write, test, debug code. (Good for eXtreamPrograming)
Amrita2 mixes a template and model data up to a html document naturally matching the id
attribute of XML element to model data.
Current version and roadmap
Current version is 2.0.2 .
Setup
# gem install amrita2
document
Start spec/intro.rb or Amrita2 Wiki (retro.brain-tokyo.net/projects/amrita2/wiki/Amrita2)
support/developement
Download
License
Amrita2 is Copyright © 2008 Taku Nakajima <[email protected]>. It is free software, and may be redistributed under the terms specified in the README file of the Ruby distribution.
Sample source code under sample/depot is Amrita2 version of Depot Application of “Agile Web Development with Rails”.
http://www.pragprog.com/titles/rails2/source_code
Sample source code under sample/login_engine is Amrita2 version of LoginEngine.
http://rails-engines.org/news/2007/01/23/farewell-login_engine-/