[ANN] amrita 0.8.1

Amrita is a a html/xhtml template library for Ruby.
It makes html documents from a template and a model data.

Key feature

  • The template for amrita is a pure html/xhtml document without
    special tags like <?...?> or <% … %>

  • The template can be written by designers using almost any HTML
    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)) no by logic. So It’s easy to
    write, test, debug code. (Good for eXtreamPrograming)

  • HTML template can be compiled into Ruby code before execution
    with a little effort.

Amrita mixes a template and model data up to a html document naturally
matching the +id+ attribute of HTML element to model data.

For detail see http://kari.to/amrita/ .

···


tnakajima@brain-tokyo.jp

very nice work. i thiink this is the best looking html/xhtml template
system i’ve seen so far. few questions:

  1. can dummy data be used in the template itself for designer purposes?

  2. how does it far with xml itself? (if no, would you add that support?)

  3. and finally, how fast is it?

i had stared my own xml/html/xhtml template system myself based on
zope’s tals, call xmlTails, though i got it to work it used eval a lot,
which i didn’t like and it was exceedly slow. with Amrita i think i can
happily dump that into my trash can. yes?

···

On Thu, 2002-07-18 at 20:26, Taku Nakajima wrote:

Amrita is a a html/xhtml template library for Ruby.
It makes html documents from a template and a model data.


~transami

(") dobee dobee do…
\v/
^ ^

Taku Nakajima tnakajima@brain-tokyo.jp wrote in message news:200207190226.LAA24643@brain-tokyo.jp

Amrita is a a html/xhtml template library for Ruby.
It makes html documents from a template and a model data.

This is a really cool, clean approach - I very much like being able to
see the skeleton of the page without looking at the template (most
templating systems require starting by reading the template and
piecing everything together from there).

To throw out a couple of thoughts:

  • It would be cool during development to have the template completely
    inferred from the data; obviously it would have to make some arbitrary
    choices (lists vs. tables, anchors vs. buttons) but it would probably
    be good enough to get a prototype up for simple sites.

  • If I were using it, I’d want to mix callbacks in for form elements
    and links, so that you could do, say,

i = 0
data = {“count” => i,
“increment” => callback{i += 1},
“decrement” => callback{i -= 1}}

and then have a template like

++ --

and have it do the obvious thing. Obviously this requires a lot more
infrastructure than just Amrita, but it’s completely doable.

Avi

Hi:

I downloaded amrita (stable version) and ran
make test_it

and got several errors. Did I do something wrong or get the
incorrect version?

Thanks

Jim

make test_it
(cd test; ruby -I…/lib testall.rb)
E.E…E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E…E.E.E.F…E…E…
Time: 0.654986
FAILURES!!!
Test Results:
Run: 82/82(158 asserts) Failures: 1 Errors: 45
Failures: 1
./testparser.rb:31:in test_scanner'(TestHtmlParser): expected:<[#<Amrita::HtmlScanner::TagInline:0x80bb8ec @attrs=[["src", "xxx.gif"]], @name="img">]> but was:<[#<Amrita::HtmlScanner::TagInline:0x80baf8c @attrs=[], @name="src">]> (RUNIT::AssertionFailedError) from testall.rb:22 Errors: 45 ../lib/amrita/parser.rb:433:inparse’(TestFormat): error hapend in :4(

can’t be in )
==> id=“body”>body text will be inserted here

(Amrita::HtmlParseError) from ../lib/amrita/parser.rb:398:in `parse_text' from ./testformat.rb:50:in `test_asisformatter' from testall.rb:22 ../lib/amrita/parser.rb:433:in `parse'(TestFormat): error hapend in :0( can't be in <__id>)
···


Jim Freeze
If only I had something clever to say for my comment…
~

I released amrita V0.8.2

amrita-0.8.1.tar.gz has a XSS(cross-site-scripting)
vulnerability. Don’t use it!

Amrita is a a html/xhtml template library for Ruby.
For detail and ChangeLog see http://kari.to/amrita/

···


Taku Nakajima

Amrita is a a html/xhtml template library for Ruby.
It makes html documents from a template and a model data.

very nice work. i thiink this is the best looking html/xhtml template
system i’ve seen so far. few questions:

Thnak you.

  1. can dummy data be used in the template itself for designer purposes?

Yes, dummy data will be deleted in real use.

tmpl = TemplateText.new "<p id=xyz>This is dummy data</p>"
data = {  :xyz => "This is real data" }
tmpl.expand(STDOUT, data) # =><p>This is real data</p>
  1. how does it far with xml itself? (if no, would you add that support?)

I think it can be used with xml right now.

Html dependent parts are

  • parser will add omitted tags for html

    but it doese not matter for well-formed xml/xhtml

  • parser will generate special data for

    I think I can provide a flag to avoid this feature if you need.

  • pretty printer uses html tag info (see lib/amrita/format.rb:227)

    but you can avoid this feature not setting prettypring flag or
    provide tag info yourself fit to your DTD.

  1. and finally, how fast is it?

It’s slow but has pre-compiled mode. In pre-compiled mode, it runs as
fast as a standard ruby script like

STDOUT << "<html>........"
STDOUT << "<ul>"
some_array.each do |x|
  STDOUT << "<li>"> << x
end
.....

see sample/tour/precompile.rb and docs/Tour:177 for detail.

···

On Fri, Jul 19, 2002 at 01:36:52PM +0900, Tom Sawyer wrote:

On Thu, 2002-07-18 at 20:26, Taku Nakajima wrote:


Taku Nakajima

Doesn’t Iowa have a similar approach? How would you compare
both?

Regards,
Pit

···

On 19 Jul 2002, at 17:00, Avi Bryant wrote:

This is a really cool, clean approach (…)

You need strscan:

See: http://www.loveruby.net/ja/prog/strscan.html

-rich

From: Jim Freeze [mailto:jfreeze@freebsdportal.com]
Sent: Saturday, July 20, 2002 11:16 AM
To: ruby-talk ML
Subject: Re: [ANN] amrita 0.8.1

Hi:

I downloaded amrita (stable version) and ran
make test_it

and got several errors. Did I do something wrong or get the
incorrect version?

Thanks

Jim

make test_it
(cd test; ruby -I…/lib testall.rb)

E.E…E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E
.E

.E.E.E…E.E.E.F…E…E…
Time: 0.654986
FAILURES!!!
Test Results:
Run: 82/82(158 asserts) Failures: 1 Errors: 45
Failures: 1
./testparser.rb:31:in test_scanner'(TestHtmlParser): expected:<[#<Amrita::HtmlScanner::TagInline:0x80bb8ec @attrs=[["src", "xxx.gif"]], @name="img">]> but was:<[#<Amrita::HtmlScanner::TagInline:0x80baf8c @attrs=[], @name="src">]> (RUNIT::AssertionFailedError) from testall.rb:22 Errors: 45 ../lib/amrita/parser.rb:433:inparse’(TestFormat): error hapend in
:4(

···

-----Original Message-----
can’t be in )
==> id=“body”>body text will be inserted here

(Amrita::HtmlParseError) from ../lib/amrita/parser.rb:398:in `parse_text' from ./testformat.rb:50:in `test_asisformatter' from testall.rb:22 ../lib/amrita/parser.rb:433:in `parse'(TestFormat): error hapend in :0( can't be in <__id>)


Jim Freeze
If only I had something clever to say for my comment…
~

I downloaded amrita (stable version) and ran
make test_it

and got several errors. Did I do something wrong or get the
incorrect version?

strscan has c version and ruby version. They have subtle difference and
amrita needs c version.

see http://www.loveruby.net/en/man/strscan/usage.html

I’ve got the same messages when I removed cscan.so ( c version of
strscan in my system: linux) for testing. I think you have strscan.rb
installed but the c-version was not installed or it does not work now.

I should have inserted checking if strscan of c version is running. I
will put this check to next release of amrita. Thank you for
reporting.

···


Taku Nakajima

Amrita is a a html/xhtml template library for Ruby.

See http://kari.to/amrita/

I added REXML-based XML parser and a document with sample code about
how to use amrita with XML in this release.

http://kari.to/amrita/rdocs/files/docs/XML.html

···

On Fri, Jul 19, 2002 at 01:36:52PM +0900, Tom Sawyer wrote:

  1. how does it far with xml itself? (if no, would you add that support?)

Now my answer is “amrita can be used with XML very well” . I hope you
like it.


Taku Nakajima

“Pit Capitain” pit@capitain.de wrote in message news:3D37E786.27741.191E7AE5@localhost

This is a really cool, clean approach (…)

Doesn’t Iowa have a similar approach? How would you compare
both?

Similar, yes, although a comparison is difficult because Iowa is
bidirectional (data goes from your model out to the template, through
an HTTP response/request cycle, and the back to your model), which
complicates things a lot.

The two main differences in terms of templating are that Iowa’s
bindings are a flat namespace whereas Amrita uses hierarchy, and that
Iowa has a lot of back and forth interaction between the template and
the model, whereas Amrita takes a more pipelined approach - once the
data tree is built, that’s all the template refers to. This
simplifies iteration logic in particular.

What would be interesting to me would be an Amrita like system that
introduced Iowa’s bidirectionality by storing blocks inside the data
tree. Particularly if combined with call/cc based session management.

···

On 19 Jul 2002, at 17:00, Avi Bryant wrote:

Hi,

Anyone can tell me how to use the TkImage class method? Seems it is much
different from the Perl/Tk.
In Perl/Tk there is no “new” method, but according to the
Rdoc,http://www.eng.dmu.ac.uk/~hgs/ruby/ruby-1.6.7-rdocs/,there is a new
method. And I have tried for severl times,such as
TkImage.new{type "phoimage"
file “xxxx.gif”
}
but still cannot use it to create a image. Thanks.

Hi,

···

On Sun, Jul 21, 2002, Rich Kilmer wrote:

You need strscan:

See: http://www.loveruby.net/ja/prog/strscan.html

Could someone who has access to the adequate compilation software
build a win32 version of this library ?

Thanks a lot,

Pierre Baillet
It is a good viewpoint to see the world as a dream. When you have something
like a nightmare, you will wake up and tell yourself that it was only a dream.
It is said that the world we live in is not a bit different from this.

wonderful to hear! i’m planning to use amrita for a report engine.
essentially it will pull from a database and use amrita to generate
texml (texml is a way to mark-up (La)Tex in XML) from there is gets
converted into LaTex and then into a dvi.

thanks for such a great tool,
~transami

···

On Wed, 2002-07-24 at 20:00, Taku Nakajima wrote:

Now my answer is “amrita can be used with XML very well” . I hope you
like it.

not sure if i follow you here exactly, but i’ve been trying to do
something similiar with object <-> gui communication. in fact after
reading you plug for amrita i was surprised by the coorelations, the
distinction being only that Amrita goes one direction, where i was
trying to go back again.

i have yet to succeed in this endeavor. i have come to realize that
there is much more to the whole thing then i initially thought, but i
will keep tinkering away at it. perhaps eventually i have something
useable. (in the mean time, i’ve switched to rebol for gui front ends.
oh well.)

~transami

(") dobee dobee do…
\v/
^ ^

···

On Fri, 2002-07-19 at 15:41, Avi Bryant wrote:

What would be interesting to me would be an Amrita like system that
introduced Iowa’s bidirectionality by storing blocks inside the data
tree. Particularly if combined with call/cc based session management.

Thanks a lot.
Pit

···

On 20 Jul 2002, at 6:41, Avi Bryant wrote:

(Comparison between bidirectional Iowa and pipelined Amrita
and ideas for a combination of both)

  TkImage.new{type "phoimage"
                        file "xxxx.gif"
                        }

Apparently you want a PhotoImage, try

    TkPhotoImage.new { file "xxxx.gif" }

Guy Decoux

What Ruby version to you have 1.6 or 1.7?

ruby -v

I am set up to build for 1.7 and not 1.6.

-rich

From: Pierre Baillet [mailto:pierre.baillet@zoy.org]
Sent: Sunday, July 21, 2002 5:54 PM
To: ruby-talk ML
Cc: Minero Aoki
Subject: Re: [ANN] amrita 0.8.1

Hi,

You need strscan:

See: http://www.loveruby.net/ja/prog/strscan.html

Could someone who has access to the adequate compilation software
build a win32 version of this library ?

Thanks a lot,

Pierre Baillet
It is a good viewpoint to see the world as a dream. When you have
something
like a nightmare, you will wake up and tell yourself that it was only
a

···

-----Original Message-----
On Sun, Jul 21, 2002, Rich Kilmer wrote:
dream.
It is said that the world we live in is not a bit different from this.

Do you have any sample texml documents or good information
on texml usage?

Thanks

···

On Thu, Jul 25, 2002 at 12:23:44PM +0900, Tom Sawyer wrote:

On Wed, 2002-07-24 at 20:00, Taku Nakajima wrote:

Now my answer is “amrita can be used with XML very well” . I hope you
like it.

wonderful to hear! i’m planning to use amrita for a report engine.
essentially it will pull from a database and use amrita to generate
texml (texml is a way to mark-up (La)Tex in XML) from there is gets
converted into LaTex and then into a dvi.

thanks for such a great tool,
~transami


Jim Freeze
If only I had something clever to say for my comment…
~

Hello,

···

On Mon, Jul 22, 2002, Rich Kilmer wrote:

What Ruby version to you have 1.6 or 1.7?

ruby -v

I am set up to build for 1.7 and not 1.6.

-rich

Unfortunately, I’m on 1.6.7 win32. But i’ll be interested in 1.7
binaries anyway, I can’t wait to test this ! :slight_smile:

Cheers,

Pierre Baillet
Linux is user friendly. Linux is not idiot friendly
If you don’t understand that, use Windows