[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fossil-users
Subject:    Re: [fossil-users] custom pages structure/impl: RFC
From:       Stephan Beal <sgbeal () googlemail ! com>
Date:       2012-07-15 8:44:34
Message-ID: CAKd4nAhCt6T+Y4ba=B=KZF01p-=mQrSujnsKxxFj9gS_MHgHeg () mail ! gmail ! com
[Download RAW message or body]

On Sun, Jul 15, 2012 at 10:39 AM, Stephan Beal <sgbeal@googlemail.com>wrote:

> Which reminds me: now that th1 can access get/post args, the header,
> footer, and any docs/pages/commands we make th1-aware can behave more
> dynamically. For example:
>

th1 offers a cool "catch" feature which we can use to make the script more
robust. Combined with the "ob" API we can use it to implement an "all or
nothing" display behaviour which discards the contents if an error is
thrown from a script:


ob start
catch {

> set foo [argv getint foo "" 0]
> if { 0 == $foo } {
>   ... default behaviour
> } else {
>   render_doc doc_$foo
> }
>
   return 0
} err
set content [ob get end]
if { 0 == $err } {
  puts $content
}else {
  puts "Error: $err"
}

with that in place, any error generated in the catch block will be safely
propagated back out and none of the generated content will be displayed -
it is instead replaced by an error message. The "ob" parts capture all the
output and let us decide at the end if we want to display them or not.

-- 
----- stephan beal
http://wanderinghorse.net/home/stephan/
http://gplus.to/sgbeal

[Attachment #3 (text/html)]

<div class="gmail_quote">On Sun, Jul 15, 2012 at 10:39 AM, Stephan Beal <span \
dir="ltr">&lt;<a href="mailto:sgbeal@googlemail.com" \
target="_blank">sgbeal@googlemail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <div class="gmail_quote"><div class="im">Which reminds me: \
now that th1 can access get/post args, the header, footer, and any \
docs/pages/commands we make th1-aware can behave more dynamically. For \
example:</div></div></blockquote> <div><br></div><div>th1 offers a cool \
&quot;catch&quot; feature which we can use to make the script more robust. Combined \
with the &quot;ob&quot; API we can use it to implement an &quot;all or nothing&quot; \
display behaviour which discards the contents if an error is thrown from a \
script:</div> <div><br></div><div><br></div><div>ob start</div><div>catch { \
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div class="gmail_quote"><div>set foo [argv getint foo \
&quot;&quot; 0]</div> <div>if { 0 == $foo } {</div><div>  ... default \
behaviour</div><div>} else {</div><div>  render_doc doc_$foo</div> \
<div>}</div></div></blockquote><div>   return 0 </div><div>} err</div><div>set \
content [ob get end]</div><div>if { 0 == $err } {</div><div>  puts \
$content</div><div>}else {</div><div>  puts &quot;Error: $err&quot;</div><div> \
}</div><div><br></div></div><div>with that in place, any error generated in the catch \
block will be safely propagated back out and none of the generated content will be \
displayed - it is instead replaced by an error message. The &quot;ob&quot; parts \
capture all the output and let us decide at the end if we want to display them or \
not.</div> <div><br></div>-- <br>----- stephan beal<br><a \
href="http://wanderinghorse.net/home/stephan/" \
target="_blank">http://wanderinghorse.net/home/stephan/</a><div><a \
href="http://gplus.to/sgbeal" target="_blank">http://gplus.to/sgbeal</a></div> <br>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic