Forum: Ruby [ANN] Amrita2 1.9.6

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B4a4d3e4fae5ecdc906cc767abbf2ac3?d=identicon&s=25 tnakajima (Guest)
on 2005-12-07 09:54
(Received via mailing list)
Amrita2 is a XML/HTML template library for Ruby.  I released a new
version 1.9.6 as BETA1 for 2.0. Get it from

  http://amrita2.rubyforge.org/

I reduced undocumented features and refactored much to prepare the
comming stable release. And ..

* added gemspec and make it Rails plugin
* simplified the ERB processing feature
* new feature for setting two attributes (like class='odd' and
  class='even') alternately

Now Amrita2 template can contain ERB source in it.

        <table border='1'>
          <tr><th>name</th><th>author</th></tr>
          <tr id='languages'>
            <td><![CDATA[
               <a href='<%= $_.url %>'><%= $_.name %></a>
            ]]></td>
            <td id='creator'></td>
          </tr>
        </table>

CDATA in <td> element will be evaluated as many times as number of
'languages' data. And each item will be set to '$_' before ERB
evaluating. See this page for detail.

  How to use Amrita2 with Ruby On Rails
  http://amrita2.rubyforge.org/Rails.html

And this method setup Template to insert two attributes alternately.

  def languages_setup_template(template)
    tmpl = Amrita2::TemplateText.new(template)
    tmpl.use_erb(binding)
    tmpl.element_option[:languages] =  { :mv_attr=> { :class=>%w(odd
even)
} }
    tmpl
  end

This template produces output like this.

<table border='1'>
  <tr><th>name</th><th>author</th></tr>
  <tr class='odd'>
    <td><a href='http://www.ruby-lang.org/'>Ruby</a></td>
    <td>matz</td>
  </tr><tr class='even'>
    <td><a href='http://www.perl.com/'>perl</a></td>
    <td>Larry Wall</td>
  </tr><tr class='odd'>
    <td><a href='http://www.python.org/'>python</a></td>
    <td>Guido van Rossum</td>
  </tr>
</table>
6828ffc79486cd2442714bf32286a910?d=identicon&s=25 krishna.vivek (Guest)
on 2005-12-07 13:22
(Received via mailing list)
>     <td><a href='http://www.python.org/'>python</a></td>
>     <td>Guido van Rossum</td>
>   </tr>
> </table>


I fail to get the point.. RoR already has a template system .all views
are
templates..so whats the point of this thing? besides why cant I use a
for
loop in the view on some variable set in the controller to generate
these
table rows?
A1dd4c258405c0f659fe0bb614f908c2?d=identicon&s=25 takunakajima (Guest)
on 2005-12-07 15:17
(Received via mailing list)
2005/12/7, Vivek Krishna <krishna.vivek@gmail.com>:
>  I fail to get the point.. RoR already has a template system .all views are
> templates..so whats the point of this thing? besides why cant I use a for
> loop in the view on some variable set in the controller to generate these
> table rows?

Yes, RoR separates view from model completely. But ERB template
contains both VIEW PRESENTATION and VIEW LOGIC. Amrita2 and some other
template system like Kwartz, XTemplate, SikiTemplate, misen, try to
separate VIEW PRESENTATION from VIEW LOGIC.

  http://www.rubygarden.org/ruby?HtmlTemplates

There are cases at which ERB is not enough

* VIEW LOGICs must be tested separately
* Multi language (international) VIEW PRESENTATIONs share same VIEW
  LOGICs
* want to design or check VIEW PRESENTATION staticaly without RoR
  environment

And Amrita2 makes both VIEW PRESENTATION and VIEW LOGIC more
decralative than ERB. I think Decralative code is easier to write,
understand, modify, test than procedural code in ERB template.

I think ERB is good for default template system for RoR. But we need
alternative and that's what plugin is for.

--
Taku Nakajima
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 ara.t.howard (Guest)
on 2005-12-07 17:35
(Received via mailing list)
On Wed, 7 Dec 2005, Vivek Krishna wrote:

>>     <td>Guido van Rossum</td>
>>   </tr>
>> </table>
>
> I fail to get the point.. RoR already has a template system .all views are
> templates..

not so - all views are view-controllers: erb mixes the two and is an
ugly wart
on an otheriwse clean mvc architechture imho.

> so whats the point of this thing? besides why cant I use a for loop in the
> view on some variable set in the controller to generate these table rows?

for loops are relatively benign - but the second you put someother kind
of
logic into the view you've broken mvc.  erb makes this easy to do and
most of
the rails projects (only 4 or 5 admittedly) i've read do this to varying
degree.  breaking mvc isn't bad by definition - just like global
variables are
not bad by definition.

i've been waiting a long time to see rails/amrita integration and am
confident
that the same people who prefer normalized databases, postgresql to
mysql,
ruby to perl, object access control, data encapuslation and orthoganl
design
in general with grow to prefer it.

kind regards.

-a
B7c24a7df391a1c318a90974537afc43?d=identicon&s=25 Ramin Bozorg (i8ramin)
on 2005-12-07 18:45
(Received via mailing list)
I have been waiting for this ever since day 1 of using Rails. Just
like how I hate writing scriptlets in JSP's and putting PHP code in my
HTML. I really didn't like the use of Ruby code in my view templates.

Thanks for making and sharing this plugin! I really hope one of these
templating systems become part of the framework.

On 12/7/05, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> >>   </tr><tr class='odd'>
>
> that the same people who prefer normalized databases, postgresql to mysql,
> | comes from the desire for oneself to be happy.
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>


--
- Ramin
http://www.getintothis.com/blog
6d0eb16fc0643be173fc0993b1b4e513?d=identicon&s=25 john-mason (Guest)
on 2005-12-07 19:50
(Received via mailing list)
Not to mention cool tools: http://webpub.narucy.com/index.en.html.


John-Mason Shackelford

Software Developer
Pearson Educational Measurement

2510 North Dodge St.
Iowa City, IA 52245
ph. 319-354-9200x6214
john-mason.shackelford@pearson.com
http://pearsonedmeasurement.com
A2b2f4ee23989dc68529baef9cbddcd6?d=identicon&s=25 listbox (Guest)
on 2005-12-07 20:02
(Received via mailing list)
On 7-dec-2005, at 13:20, Vivek Krishna wrote:

>     <td>Guido van Rossum</td>
>   </tr>
> </table>
>
> I fail to get the point.. RoR already has a template system .all
> views are templates..so whats the point of this thing? besides why
> cant I use a for loop in the view on some variable set in the
> controller to generate these table rows?

Please, let's not get into the same argument again. Let's say so -
templating systems are different, and serve different needs. It's
very good that Rails supports view drivers and that we now have 3
different ways to do templating in Rails.


--
Julian 'Julik' Tarkhanov
me at julik.nl
This topic is locked and can not be replied to.