Alex Nesbitt
2006-Jul-14 16:27 UTC
[Rails] how to get builder 2.0 to escape attributes in rxml
I am using rxml to produce opml files and need to escape ampersands in the attributes. builder 2.0 docs found at builder.rubyforge.org show the following xml = Builder::XmlMarkup.new xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There") xml.target! => <sample escaped="This&That" unescaped="Here&There"/> I tried to install and repeat this result, but attributes are not escaping Here is the gem install and the attempt to test escaping attributes: C:\rails>"c:\ruby\bin\ruby.exe" "c:\ruby\bin\gem" install builder --version 2.0 Attempting local installation of ''builder'' Local gem file not found: builder*.gem Attempting remote installation of ''builder'' Successfully installed builder-2.0.0 Installing RDoc documentation for builder-2.0.0... C:\rails>cd buildertest C:\rails\buildertest>ruby script/console Loading development environment.>> xml = Builder::XmlMarkup.new=> <inspect/>>> xml.sample(:escaped=>"this & that")=> "<inspect/><sample escaped=\"this & that\"/>">> exitDoes anybody know what could be wrong? -- Posted via ruby-forum.com.
Zack Chandler
2006-Jul-18 18:28 UTC
[Rails] how to get builder 2.0 to escape attributes in rxml
Alex, Alex, Use builder''s << operator to append text without escaping markup. Example xml.<< ''This&That'' See also my blog post on using this in rxml templates: depixelate.com/articles/2006/07/18/quick-tip-rails-partials-in-rss-feeds See also the docs: caboo.se/doc/classes/Builder/XmlBase.html#M004081 Hope this helps, Zack On 7/14/06, Alex Nesbitt <digitalpodcast@gmail.com> wrote:> I am using rxml to produce opml files and need to escape ampersands in > the attributes. > > builder 2.0 docs found at builder.rubyforge.org show the > following > > xml = Builder::XmlMarkup.new > xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There") > xml.target! => > <sample escaped="This&That" unescaped="Here&There"/> > > I tried to install and repeat this result, but attributes are not > escaping > > Here is the gem install and the attempt to test escaping attributes: > > C:\rails>"c:\ruby\bin\ruby.exe" "c:\ruby\bin\gem" install builder > --version 2.0 > > Attempting local installation of ''builder'' > Local gem file not found: builder*.gem > Attempting remote installation of ''builder'' > Successfully installed builder-2.0.0 > Installing RDoc documentation for builder-2.0.0... > > C:\rails>cd buildertest > > C:\rails\buildertest>ruby script/console > Loading development environment. > >> xml = Builder::XmlMarkup.new > => <inspect/> > >> xml.sample(:escaped=>"this & that") > => "<inspect/><sample escaped=\"this & that\"/>" > >> exit > > Does anybody know what could be wrong? > > -- > Posted via ruby-forum.com. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > lists.rubyonrails.org/mailman/listinfo/rails >
Alex Nesbitt
2006-Jul-22 19:57 UTC
[Rails] Re: how to get builder 2.0 to escape attributes in rxml
Thanks for the reponse Zack, but my problem is the opposite. I need Builder to escape the markup and it''s not doing it for some reason. When I use buidler this is what I get C:\rails\buildertest>ruby script/console Loading development environment.>> xml = Builder::XmlMarkup.new=> <inspect/>>> xml.sample(:escaped=>"this & that")=> "<inspect/><sample escaped=\"this & that\"/>">> exitIf you look at the markup you can see that what is supposed to be escaped is not. I am running builder 2.0 and the specs say that it should escape attributes, but for some reason it doesn''t seem to be working. Any idea what might be wrong? Zack Chandler wrote:> Alex, > Alex, > > Use builder''s << operator to append text without escaping markup. > > Example > xml.<< ''This&That'' > > See also my blog post on using this in rxml templates: > depixelate.com/articles/2006/07/18/quick-tip-rails-partials-in-rss-feeds > > See also the docs: > caboo.se/doc/classes/Builder/XmlBase.html#M004081 > > Hope this helps, > Zack-- Posted via ruby-forum.com.