From: Jamis Buck Date: 2005-03-03T09:02:34+09:00 Subject: Re: Erb: terminating a script? On Mar 2, 2005, at 4:02 PM, Lloyd Zusman wrote: >> Have you tried doing 'return'? Or perhaps 'break'? I haven't tried >> these >> myself, so I don't know if they will work or not. Just throwing out >> some >> ideas. > [snip] > Original line in ErbHandler#do_GET ... > > res.body = evaluate(ERB.new(data), req, res) > > Replaced with ... > > res.body = evaluate(ERB.new('<% catch(:quit) { %>' + > data + > '<% } %>'), req, res) > > Then, I can exit by doing a '<% throw :quit %>' from anywhere in the > page. And any text that's specified before the 'throw' appears in the > resulting text. > > The following also yields the same results: > > res.body = evaluate(ERB.new('<% lambda { %>' + data + '<% }.call > %>') > req, res) > > In this case, I can exit early by using either '<% break %>' or > '<% return %>'. I like this one better, and this is what I have > just now implemented in my application. Excellent work, Lloyd. Thanks for sharing! > Because of this, it seems to me that it would be beneficial if Erb were > to always put a lambda-call block around the text that gets evaluated. > > I'm in favor of this enhancement going into a subsequent release, and > I'll soon submit a patch. > > Thoughts or opinions? I'd vote for it. :) - Jamis