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 " <html>\n <head>\n <title am:src=\"page_title\" />\n </head>\n <body>\n <h1 am:src=\"header_title\" />\n <p class=\"text\" am:src=\"text\">\n <span am:src=\"template\" /> is a html template library for <span am:src=\"lang\" />\n </p>\n </body>\n </html>\n END\n\n data = {\n :page_title=>'Amrita2',\n :header_title=>'Hello, Amrita2',\n :text=>{\n :template => 'Amrita2',\n :lang => 'Ruby'\n }\n }\n expected = <<-END\n <html>\n <head>\n <title>Amrita2</title>\n </head>\n <body>\n <h1>Hello, Amrita2</h1>\n <p class=\"text\">Amrita2 is a html template library for Ruby</p>\n </body>\n </html>\n END\n #\n t.render_with(data).should_be_samexml_as(expected)\n\n t2 = Amrita2::Template.new <<-END\n <<html<\n <<head<\n <<title:page_title>>\n <<body<\n <<h1:header_title>>\n <<p class=\"text\":text<\n <<:template>> is a html template library for <<:lang>>\n END\n #\n t2.render_with(data).should_be_samexml_as(expected)\nend\n"
-
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-/