Rails + Amrita, Rails + XTemplate?

G

Greg McIntyre

Has anybody thought about putting Amrita/XTemplate support in Rails?
Does anybody think this would be a worthwhile thing to do?

Personally I'm a big XTemplate (xtemplate.sf.net) fan but it's 90%
theoretical as I haven't had much experience in taking a designer's
mockup and turning it into a functioning web site. Has anybody else
had this experience? Has anybody compared the ease with which this can
be done between erb and Amrita/XTemplate? If so, is the difference in
effort significant enough to make Amrita/XTemplate support in Rails
worthwhile?

If XTemplate support were put in Rails, I imagine it would work like
so:

class MyController < ActionController::Base
def operation
@amrita_data = {
:x => 1,
:y => 2,
:z => a( ... ),
}
render_view 'amrita:myview'
end

def operation
@xtemplate_data = {
'x' => 1,
'y' => 2,
'@z' => 3,
}
render_view 'xtemplate:myview'
end
end

The system here is to prefix the view name with "method:" which can be
detected by the render_view method and used to dispatch to a
particular module or extension without having to check what files
exist on the disk. These view library-specific methods know which
attribute of the controller to use (e.g. render_amrita always uses
'@amrita_data') as input data for the template. This could generalise
the current support for either erb or builder views by giving them
their own prefixes with the current behaviour being the default if no
prefix exists (i.e. it checks on disk for files with the right
extensions).

def operation
@x = 1
@y = 2
@z = 3
render_view 'myview' # uses erb or builder
# same as:
# render_view 'erb:myview' # uses myview.rhtml
# or
# render_view 'builder:myview' # uses myview.rxml
# depending on which file exists.
end

Potentially Amrita's support for using a Ruby object graph as input
could make its usage more homogenous with the current scheme:

def operation
@x = 1
@y = 2
@z = a( ... )
render_view 'amrita:myview'
end

(Sorry, I'm not as familiar with Amrita as I am with XTemplate.)

This could be turned into the hash input to Amrita:
{
:x => 1,
:y => 2,
:z => a( ... ),
}
by the Amrita render method in Rails, using
"controller.instance_variables".

And possibly there could be a simple mechanism for converting an
object graph into XTemplate input as a wrapper built into Rails, to
provide similar support:

def operation
@x = 1
@y = 2
@xattr_z = 3
render_view 'xtemplate:myview'
end

(Translated into:)

{
'x' => 1,
'y' => 2,
'@z' => 3,
}

Comments? Suggestions? I've been out of the ruby-talk loop for a while
but I tried to search around before posting. Nevertheless if this has
already been discussed, please point me in the right direction.

Thanks
 
J

Jeff Barczewski

I believe David has added support for templating into rails based on
some work by Jamis Buck (if my memory serves). You can use these hooks
to invoke whatever templating system you would like. I know that
Amrita2 has an example in its package. Although I am new to working
with Amrita2, it looks very exciting, you may want to check it out.
http://amrita2.rubyforge.org/
I am planning on using it with Rails myself.
 
G

Greg McIntyre

Aha! I see the hooks now. Yes, these could be used with XTemplate quite
nicely. I think that's what I'll be using. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top