From: Aaron Patterson Date: 2009-01-13T10:27:01+09:00 Subject: Re: Markaby -> Nokogiri Issue On Tue, Jan 13, 2009 at 02:13:13AM +0900, Trans wrote: > I was using: > > Markaby::Builder.new(&block) > > And it was working fine except it wouldn't let me use non-standard > attributes on an img tag, which blows. I couldn't find any way to > deactivate this strictness, so I decided to try Nokogiri instead: > > Nokogiri::HTML::Builder.new(&block) > > Unfortunately this doesn't work at all, b/c it turns out Nokogiri does > not seem to be using #instance_eval on the block. Without doing so I > don't see how it can be at all useful. For example in my case I have > method called #body: > > def body(&block) > Nokogiri::HTML::Builder.new do > body(&block) > end > end It does use instance_eval, but it also checks the context in which it was instantiated to see if it responds to that method before creating a new node. That way your builder can have access to methods outside of the builder. > By not using instance_eval Nokogiri doesn't recognize 'body' as a tag, > but tries to call the method again, resulting in an infinite loop. So > I think this is a bug in Nokogiri's builder. No. This was a requested feature. I gladly accept patches though! :-) > In the mean time, can anyone offer a work around? Or is there a way to > turn off "strict-mode" for Markaby. You should be able to do this: def body(&block) Nokogiri::HTML::Builder.new do insert(Nokogiri::XML::Node.new('body', @doc), &block) end end Hope that helps! -- Aaron Patterson http://tenderlovemaking.com/