Jamis Buck <jamis_buck@byu.edu> writes:
William Ramirez Wrote:
A<br>
B<br>
<% WHAT GOES HERE TO END THE SCRIPT? %>
C<br>
D<br>
What do use for "WHAT GOES HERE ..." in order to cause the
processing to end after A and B print out?
Just doing some quick reading, you may want to try exit or exit!, if
you haven't already. If you have, what happened? Did it still output C
and D?
Apparently they're very similar, however, exit! ignores exception
handling, at_exit functions, and finalizers.
I did call exit, and it terminated the entire web server. I forgot to
mention that I'm running Erb inside of ErbHandler within a webrick
FileHandler instance, not within a stand-alone CGI. I'm sorry for
having left out that key piece of information in my original query.
The same thing happened with the "exit!" method.
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.
Yes, I have tried them.
Using 'return', I get this error:
ERROR ThreadError: return can't jump across threads
Using 'break', I get this one:
undefined method `result' for #<String:0x850bddc>
However, following up on the idea I mentioned in my previous message, I
did the following ... and it works:
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.
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?
···
On Mar 2, 2005, at 12:19 PM, Lloyd Zusman wrote:
On Wed, 2 Mar 2005 21:32:28 +0900, Lloyd Zusman <ljz@asfast.com> >>> wrote:
--
Lloyd Zusman
ljz@asfast.com
God bless you.