Forum: Ruby adding any <text/> to a rexml doc (bump)

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.
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2005-12-15 19:58
(Received via mailing list)
is there know way to do this

   require "rexml/document"

   include REXML

   Text::new " i < know & what i'm doing "

it seems not...

-a
9035814d8b0ac979bf1c8f46f1f04140?d=identicon&s=25 Patrick Gundlach (Guest)
on 2005-12-16 00:13
(Received via mailing list)
Hi,

> is there know way to do this
>
>    require "rexml/document"
>
>    include REXML
>
>    Text::new " i < know & what i'm doing "
>
> it seems not...

I am not sure, what you want to do, but perhaps

Text.unnormalize(" i < know & what i'm doing ") is the answer?

REXML won't let this into the element hierarchy, afaik.

Patrick
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2005-12-16 03:05
(Received via mailing list)
On Fri, 16 Dec 2005, Patrick Gundlach wrote:

>> it seems not...
>
> I am not sure, what you want to do, but perhaps
>
> Text.unnormalize(" i < know & what i'm doing ") is the answer?
>
> REXML won't let this into the element hierarchy, afaik.

it will - you just have to trick it:

   element.text =
     ::REXML::Text::new(
       string_we_want_untouched,
       respect_whitespace=true,
       parent=nil,
       raw=true,
       entity_filter=nil,
       illegal=%r/.^/m           # match nothing!
     )

sean, if you're reading this a feature in the api to allow this would be
great.

cheers.

-a
5c7bdd14d6885c8275eaf78be41d120a?d=identicon&s=25 Eero Saynatkari (Guest)
on 2005-12-16 04:27
(Received via mailing list)
On 2005.12.16 03:57, ara.t.howard@noaa.gov wrote:
>    Text::new " i < know & what i'm doing "
>
> it seems not...

Perhaps it is time to try Builder or htree? :)

> -a


E
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2005-12-16 05:36
(Received via mailing list)
On Dec 15, 2005, at 5:47 PM, ara.t.howard@noaa.gov wrote:

>>>    Text::new " i < know & what i'm doing "
>
> sean, if you're reading this a feature in the api to allow this
> would be great.
>
> cheers.
>
> -a
>

Ahh thats what the non matching regex was for...

Cheers-

-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2005-12-16 06:39
(Received via mailing list)
On Fri, 16 Dec 2005, Eero Saynatkari wrote:

>>
>>    Text::new " i < know & what i'm doing "
>>
>> it seems not...
>
> Perhaps it is time to try Builder or htree? :)

i can't stand the builder api.  htree is good - but i'm not looking for
a
template engine - does it provide hooks to generate html without using
templates.  the code i'm working on attm can do things like this:

     [ahoward@localhost xx-0.0.0]$ cat a.rb
     require "xx"
     class Table < ::Array
       include XX::XHTML

       def to_xhtml
         xhtml__{

           html__{
             head__{ title__{ "table demo" } }

             h1__(:style => :sweet){ "this is a table " }

             h__{ "<malformed html & open tags" }

             table__(:width => 42, :height => 42){
               each{|row| tr__{ row.each{|cell| td__ cell } } }
             }
           }

         }.pretty
       end
     end

     puts Table[ %w( 0 1 2 ), %w( a b c ) ].to_xhtml


     [ahoward@localhost xx-0.0.0]$ ruby -I./lib a.rb
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
       <head>
         <title>table demo</title>
       </head>
       <h1 style='sweet'>this is a table </h1><malformed html & open
tags<table height='42' width='42'>
         <tr>
           <td>0</td>
           <td>1</td>
           <td>2</td>
         </tr>
         <tr>
           <td>a</td>
           <td>b</td>
           <td>c</td>
         </tr>
       </table>
     </html>


coming soon to a store near you ;-)

regards.

-a
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2005-12-16 06:42
(Received via mailing list)
On Fri, 16 Dec 2005, Ezra Zygmuntowicz wrote:

> Ahh thats what the non matching regex was for...

caught in the act... mine worked.. but it wasn't nice looking ;-)

-a
5c7bdd14d6885c8275eaf78be41d120a?d=identicon&s=25 Eero Saynatkari (Guest)
on 2005-12-16 06:51
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2005.12.16 14:38, ara.t.howard@noaa.gov wrote:
> >>
> templates.  the code i'm working on attm can do things like this:
>              head__{ title__{ "table demo" } }
>          }.pretty
>          <title>table demo</title>
>            <td>c</td>
>          </tr>
>        </table>
>      </html>
>
>
> coming soon to a store near you ;-)

Very nice! (Well, sans underscores:)

Will you make libxml2[1] an alternative backend? It is quite
a bit faster, which may or may not be important to people.

> regards.
>
> -a


E

[1] http://xml-tools.rubyforge.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDol3YxvA1l6h+MUMRApOaAJwNvEboVkzD+rSI6XPu9wQNWXdRqgCghsH5
fk5nmlI2wRb2dOhff/o8lR8=
=uORR
-----END PGP SIGNATURE-----
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2005-12-16 07:09
(Received via mailing list)
On Fri, 16 Dec 2005, Eero Saynatkari wrote:

>> coming soon to a store near you ;-)
>
> Very nice! (Well, sans underscores:)

glad you like the look of it.  i struggled with the underscore thing and
here's how i got there:


   - wanted access to instance data.  ergo mixin.  ergo can't be
clobbering the
     objects methods with a billion others.

   - didn't want a 'blanket' method missing.  i wanted to a way to say
that
     only 'tag' methods would be handled in method_missing - not
everything.
     otherwise

       syntax_error 42

     makes

       <syntax_error>42</syntax_error>

     fine for small docs.  not for big ones.  mine works like

       def method_missing m, *a, &b
         if m.to_s =~ %r/_$/
           ...
         else
           ...
         end
       end

     so only some methods (those with __) get routed to method_missing

   - needed to address methods/tag like 'p', 'a', 'i' - which can easily
be
     methods and/or local vars

   - wanted a way to skim the code and be able to tell which methods
were
     generating tags and which were not

   - wanted a way to bounce on the % key in vi and balance tags... well
that
     one doesn't have to do with underscores i guess...


anyhow.  i hope people will row to see that being able to __safely__
mixin
these kinds of html generation methods, still being able to find syntax
errors, and being able to quickly tell markup methods from others makes
it
o.k.  my boss and i struggled with it - but it was the best approach in
the
end when considering the above.

> Will you make libxml2[1] an alternative backend?

i'd be happy to look at it... send me a link if it's not on raa or
rubyforge...

> It is quite a bit faster, which may or may not be important to people.

it is.  this will be used on dynamic websites.

> [1] http://xml-tools.rubyforge.org

oh.  didn't see that at first ;-)

cheers.

-a
This topic is locked and can not be replied to.