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
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