[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Markaby -> Nokogiri Issue

Trans

1/12/2009 5:13:00 PM

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

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.

In the mean time, can anyone offer a work around? Or is there a way to
turn off "strict-mode" for Markaby.

Thanks,
T.


6 Answers

Kel Varnsen

4/15/2008 1:02:00 PM

0

On Apr 15, 7:54 am, Gogarty <Goga...@Clongowes.edu.ie> wrote:
> In article
> <5b100176-06e1-4cb8-af55-4029e8f10...@a23g2000hsc.googlegroups.com>,
> KelVarnsenAu...@aol.com says...
>
>
>
>
>
> >On Apr 14, 6:13 pm, Salad <o...@vinegar.com> wrote:
> >> Barack Hamas Osama wrote:
> >> > "Salad" <o...@vinegar.com> wrote in message
> >> >news:qIOdndgUqvlbDZ7VnZ2dnUVZ_rjinZ2d@earthlink.com...
>
> >> >>Barack Hamas Osama wrote:
>
> >> >>>http://americanresearch...
>
> >> >>I guess Barrack said the truth.
>
> >> >>Howard Dean, 4 years ago, said it was time to get beyond guns, gods, and
> >> >>gays.
>
> >> >>Not in PA, by your post.
>
> >> >>BTW, the jobs aren't coming back.
>
> >> > =================
>
> >> > You mean like the buggy whip makers and Typewriter makers jobs that were
> >> > replaced by Auto manufacturing and computer manufacturing jobs? Or should
> >> > the Govt be subsidizing those Typewriter manufacturers and buggy whip
> >> > manufactursers to keep making things americans dont buy anymore?
>
> >> I used to travel between Harrisburg and College Station and other areas
> >> of PA while heading towards upstate New York. There's some real pretty
> >> towns. Without jobs. I remember feeling so sad for these people
> >> without work and talking to my friends about the great highway system we
> >> have and how the large nationals could offsource some work to these
> >> towns nearby instead of overseas.
>
> >> So I understand that as a right winger you hate those people and make
> >> stupid disparaging remarks about your fellow Americans.
>
> >> How come you live in a country you hate?
>
> >Where is College Station in PA.? Never heard of it.
>
> That's where Penn State U.'s main campus is.

No Junior I'm afraid you're incorrect, it's University Park aka as
State College. College Station is where Texas A&M is which I should
know.

Salad

4/15/2008 3:10:00 PM

0

Kel Varnsen wrote:

> On Apr 15, 7:54 am, Gogarty <Goga...@Clongowes.edu.ie> wrote:
>
>>In article
>><5b100176-06e1-4cb8-af55-4029e8f10...@a23g2000hsc.googlegroups.com>,
>>KelVarnsenAu...@aol.com says...
>>
>>
>>
>>
>>
>>
>>>On Apr 14, 6:13 pm, Salad <o...@vinegar.com> wrote:
>>>
>>>>Barack Hamas Osama wrote:
>>>>
>>>>>"Salad" <o...@vinegar.com> wrote in message
>>>>>news:qIOdndgUqvlbDZ7VnZ2dnUVZ_rjinZ2d@earthlink.com...
>>
>>>>>>Barack Hamas Osama wrote:
>>
>>>>>>>http://americanresearch...
>>
>>>>>>I guess Barrack said the truth.
>>
>>>>>>Howard Dean, 4 years ago, said it was time to get beyond guns, gods, and
>>>>>>gays.
>>
>>>>>>Not in PA, by your post.
>>
>>>>>>BTW, the jobs aren't coming back.
>>
>>>>>=================
>>
>>>>>You mean like the buggy whip makers and Typewriter makers jobs that were
>>>>>replaced by Auto manufacturing and computer manufacturing jobs? Or should
>>>>>the Govt be subsidizing those Typewriter manufacturers and buggy whip
>>>>>manufactursers to keep making things americans dont buy anymore?
>>
>>>>I used to travel between Harrisburg and College Station and other areas
>>>>of PA while heading towards upstate New York. There's some real pretty
>>>>towns. Without jobs. I remember feeling so sad for these people
>>>>without work and talking to my friends about the great highway system we
>>>>have and how the large nationals could offsource some work to these
>>>>towns nearby instead of overseas.
>>
>>>>So I understand that as a right winger you hate those people and make
>>>>stupid disparaging remarks about your fellow Americans.
>>
>>>>How come you live in a country you hate?
>>
>>>Where is College Station in PA.? Never heard of it.
>>
>>That's where Penn State U.'s main campus is.
>
>
> No Junior I'm afraid you're incorrect, it's University Park aka as
> State College. College Station is where Texas A&M is which I should
> know.

I'll mention my mixup to my friend from Altoona. BTW, there's a really
nice movie called Diamond Men that takes place in that area. I fell in
love with Bess Armstrong after viewing it.

Should have known better. I lived in Houston, hung out in Seguin,
should have remembered the where/what of College Station.

Kel Varnsen

4/16/2008 12:21:00 PM

0

On Apr 15, 11:10 am, Salad <o...@vinegar.com> wrote:
> Kel Varnsen wrote:
> > On Apr 15, 7:54 am, Gogarty <Goga...@Clongowes.edu.ie> wrote:
>
> >>In article
> >><5b100176-06e1-4cb8-af55-4029e8f10...@a23g2000hsc.googlegroups.com>,
> >>KelVarnsenAu...@aol.com says...
>
> >>>On Apr 14, 6:13 pm, Salad <o...@vinegar.com> wrote:
>
> >>>>Barack Hamas Osama wrote:
>
> >>>>>"Salad" <o...@vinegar.com> wrote in message
> >>>>>news:qIOdndgUqvlbDZ7VnZ2dnUVZ_rjinZ2d@earthlink.com...
>
> >>>>>>Barack Hamas Osama wrote:
>
> >>>>>>>http://americanresearch...
>
> >>>>>>I guess Barrack said the truth.
>
> >>>>>>Howard Dean, 4 years ago, said it was time to get beyond guns, gods, and
> >>>>>>gays.
>
> >>>>>>Not in PA, by your post.
>
> >>>>>>BTW, the jobs aren't coming back.
>
> >>>>>=================
>
> >>>>>You mean like the buggy whip makers and Typewriter makers jobs that were
> >>>>>replaced by Auto manufacturing and computer manufacturing jobs? Or should
> >>>>>the Govt be subsidizing those Typewriter manufacturers and buggy whip
> >>>>>manufactursers to keep making things americans dont buy anymore?
>
> >>>>I used to travel between Harrisburg and College Station and other areas
> >>>>of PA while heading towards upstate New York. There's some real pretty
> >>>>towns. Without jobs. I remember feeling so sad for these people
> >>>>without work and talking to my friends about the great highway system we
> >>>>have and how the large nationals could offsource some work to these
> >>>>towns nearby instead of overseas.
>
> >>>>So I understand that as a right winger you hate those people and make
> >>>>stupid disparaging remarks about your fellow Americans.
>
> >>>>How come you live in a country you hate?
>
> >>>Where is College Station in PA.? Never heard of it.
>
> >>That's where Penn State U.'s main campus is.
>
> > No Junior I'm afraid you're incorrect, it's University Park aka as
> > State College. College Station is where Texas A&M is which I should
> > know.
>
> I'll mention my mixup to my friend from Altoona. BTW, there's a really
> nice movie called Diamond Men that takes place in that area. I fell in
> love with Bess Armstrong after viewing it.
>
> Should have known better. I lived in Houston, hung out in Seguin,
> should have remembered the where/what of College Station.

Go up to the horseshoe curve. It's a relic of days gone by. At one
time my family owned 3 car dealerships in the area when downtown
Altoona was still alive and prospering. Today, it's dead due to the
flight to the shopping malls outside of town.

Kel Varnsen

4/16/2008 12:25:00 PM

0

On Apr 15, 11:18 am, Gogarty <Goga...@Clongowes.edu.ie> wrote:
> In article
> <987bed52-5355-4ca0-a85b-607f2db98...@f63g2000hsf.googlegroups.com>,
> KelVarnsenAu...@aol.com says...
>
>
>
>
>
> >On Apr 15, 7:54 am, Gogarty <Goga...@Clongowes.edu.ie> wrote:
> >> In article
> >> <5b100176-06e1-4cb8-af55-4029e8f10...@a23g2000hsc.googlegroups.com>,
> >> KelVarnsenAu...@aol.com says...
>
> >> >On Apr 14, 6:13 pm, Salad <o...@vinegar.com> wrote:
> >> >> Barack Hamas Osama wrote:
> >> >> > "Salad" <o...@vinegar.com> wrote in message
> >> >> >news:qIOdndgUqvlbDZ7VnZ2dnUVZ_rjinZ2d@earthlink.com...
>
> >> >> >>Barack Hamas Osama wrote:
>
> >> >> >>>http://americanresearch...
>
> >> >> >>I guess Barrack said the truth.
>
> >> >> >>Howard Dean, 4 years ago, said it was time to get beyond guns, gods,
> and
> >> >> >>gays.
>
> >> >> >>Not in PA, by your post.
>
> >> >> >>BTW, the jobs aren't coming back.
>
> >> >> > =================
>
> >> >> > You mean like the buggy whip makers and Typewriter makers jobs that
> were
> >> >> > replaced by Auto manufacturing and computer manufacturing jobs? Or
> should
> >> >> > the Govt be subsidizing those Typewriter manufacturers and buggy
> whip
> >> >> > manufactursers to keep making things americans dont buy anymore?
>
> >> >> I used to travel between Harrisburg and College Station and other areas
> >> >> of PA while heading towards upstate New York. There's some real pretty
> >> >> towns. Without jobs. I remember feeling so sad for these people
> >> >> without work and talking to my friends about the great highway system we
> >> >> have and how the large nationals could offsource some work to these
> >> >> towns nearby instead of overseas.
>
> >> >> So I understand that as a right winger you hate those people and make
> >> >> stupid disparaging remarks about your fellow Americans.
>
> >> >> How come you live in a country you hate?
>
> >> >Where is College Station in PA.? Never heard of it.
>
> >> That's where Penn State U.'s main campus is.
>
> >No Junior I'm afraid you're incorrect, it's University Park aka as
> >State College. College Station is where Texas A&M is which I should
> >know.
>
> Oops! You are absolutely right and I certainly should know better having spent
> much time in both College Station, TX, and University Park, PA.
>
> Junior? Regrettably, 'fraid not.

We owned a car dealership out on Atherton road years and years ago.
We have season tickets to Beaver Stadium PSU football games and we
often watch both boys and girls play basketball in the Bryce Jordan
Center. When I schooled up their in the late 70's and early 80's
getting my B.S. in Business and then MBA later on PSU was far
different back then. I use to play ball at Rec Hall and lived in the
East dorms. Now you have the Penn Stater complex and the new offices
at Beaver Stadium. We moved all our operations into philly and NJ. I
also worked for a time at the Weis store out by Waupelani drive. Aw
memories!

Aaron Patterson

1/13/2009 1:27:00 AM

0

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://tenderlovem...

Trans

1/13/2009 2:16:00 AM

0



On Jan 12, 8:27=A0pm, Aaron Patterson <aa...@tenderlovemaking.com>
wrote:
> On Tue, Jan 13, 2009 at 02:13:13AM +0900, Trans wrote:
> > I was using:
>
> > =A0 =A0 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:
>
> > =A0 =A0 =A0 =A0 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:
>
> > =A0 =A0 def body(&block)
> > =A0 =A0 =A0 =A0 Nokogiri::HTML::Builder.new do
> > =A0 =A0 =A0 =A0 =A0 body(&block)
> > =A0 =A0 =A0 =A0 end
> > =A0 =A0 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. =A0That 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! :-)

Ah, I see. I'm used to Markaby --when I needed to access an outside
method I first assign it to a local variable, then use the local var
in the block. I can see the advantage of accessing methods directly,
but it's also one of those things that can be a little worrisome b/c
if I add a method to the same scope, for instance say I add a 'def pre
()' or include a module, I may inadvertently cause unexpected markup.
That seems to me a bit too fragile. If you agree, I am willing to take
a look at making a patch.


> > 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:
>
> =A0 def body(&block)
> =A0 =A0 Nokogiri::HTML::Builder.new do
> =A0 =A0 =A0 insert(Nokogiri::XML::Node.new('body', @doc), &block)
> =A0 =A0 end
> =A0 end

Thanks! Looks like that'll go it.

T.