Forum: Ruby on Rails RXML: <ruby:put expr="1+2"/>

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.
606df44c18ea2757ecec1cb7f2cc9382?d=identicon&s=25 Canatella (Guest)
on 2007-07-31 16:59
(Received via mailing list)
Hello
railers,

I've always been annoyed by the fact that ERB doesn't respect XML
specs.
As I mostly write XHTML, I'm trying to write a renderer using only
valid
XML files. Here is an example of a file so you get the feeling of
what
it's going to
do:

  <?xml version="1.0" encoding="utf-8"?
>
  <html xmlns="http://www.w3.org/1999/
xhtml"
        xmlns:rails="http://www.cosinux.org/
rails"
        xmlns:ruby="http://www.cosinux.org/
ruby">

<body>
      <ruby:put expr="'1 + 2 = ' + (1 + 2).to_s"/
>
      <ruby:put> '1 + 2 = ' + (1 + 2).to_s</
ruby:put>
      <ruby:eval expr="(0..3).to_a.each"
args="i">
        <div
id="foo_">
          <ruby:attr name="id" expr="i"/
>
          <h1 rails:id="'foo'">title <ruby:put expr="i"/></
h1>
        </
div>
      </
ruby:eval>
    </
body>
  </
html>

It's still in the early development stage and I would like advice on
the
implementation and the various ruby/rails XML element that could/
should
be
implemented.

It uses REXML to parse the file. For each node encountered, a method
is
defined which will be called at render time to render the node. At
render
time, a copy of the parsed tree is created, using the output of
the
previously defined
methods.

For now, I have a put, attr  and eval tag. I'm not satisfied with
the
eval + block implementation and
syntax:

  <eval expr="[1,2,3].each"
args="i">
    <put
expr="i">
  </
eval>

The syntax doesn't quite feel alright. If anyone has suggestion, they
are
welcome.

Also in the implementation, I cannot evaluate the expressions in a
clean
binding because of the need to have a reference to the render_node
method.
It goes
like:


Kernel.eval(%Q[
    #{node['expr']} do |
#{node['args]}|
      render_node(current_node, parent_node,
binding)

end
  ])

If somebody is interested and is willing to review my code, I would be
very
happy to hear their thought/
advice/...

The code is available at http://www.cosinux.org/~dam/rxml.tar.gz

Best
regards,

--
Damien MERENNE
<dam@cosinux.org>
http://blog.cosinux.org/
606df44c18ea2757ecec1cb7f2cc9382?d=identicon&s=25 Canatella (Guest)
on 2007-07-31 17:05
(Received via mailing list)
Sorry for the formating. Google did not accept sending the mail from
my mutt client. Here is a hopefully better formatted version.

On 31 juil, 16:58, Canatella <dmere...@gmail.com> wrote:
Hello railers,

I've always been annoyed by the fact that ERB doesn't respect XML
specs. As I mostly write XHTML, I'm trying to write a renderer using
only valid XML files. Here is an example of a file so you get the
feeling of what it's going to do:

<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:rails="http://www.cosinux.org/rails"
         xmlns:ruby="http://www.cosinux.org/ruby">
  <body>
     <ruby:put expr="'1 + 2 = ' + (1 + 2).to_s"/>
     <ruby:put> '1 + 2 = ' + (1 + 2).to_s</ruby:put>
     <ruby:eval expr="(0..3).to_a.each" args="i">
       <div id="foo_">
         <ruby:attr name="id" expr="i"/>
         <h1 rails:id="'foo'">title <ruby:put expr="i"/></h1>
       </div>
     </ruby:eval>
   </body>
</html>

It's still in the early development stage and I would like advice on
the implementation and the various ruby/rails XML element that could/
should be implemented.

It uses REXML to parse the file. For each node encountered, a method
is defined which will be called at render time to render the node. At
render time, a copy of the parsed tree is created, using the output of
the previously defined methods.

For now, I have a put, attr  and eval tag. I'm not satisfied with the
eval + block implementation and syntax:

  <eval expr="[1,2,3].each" args="i">
    <put expr="i">
  </eval>

The syntax doesn't quite feel alright. If anyone has suggestion, they
are welcome.

Also in the implementation, I cannot evaluate the expressions in a
clean binding because of the need to have a reference to the
render_node method. It goes like:

Kernel.eval(%Q[
    #{node['expr']} do |#{node['args]}|
      render_node(current_node, parent_node, binding)
  end
])

If somebody is interested and is willing to review my code, I would be
very happy to hear their thought/advice/...

The code is available athttp://www.cosinux.org/~dam/rxml.tar.gz

Best regards,

--
Damien MERENNE
<d...@cosinux.org>
http://blog.cosinux.org/
This topic is locked and can not be replied to.