Skip to content

Commit

Permalink
Implement method dispatch on tepee nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lwu committed Feb 8, 2007
1 parent 6b51e4a commit 02c1688
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions examples/tippytippytepee/tepee.rb
Expand Up @@ -93,6 +93,7 @@ class Show < R '/(\w+)', '/(\w+)/(\d+)'
def get page_name, version = nil
redirect(Edit, page_name, 1) and return unless @page = Page.find_by_title(page_name)
@version = (version.nil? or version == @page.version.to_s) ? @page : @page.versions.find_by_version(version)
@cgi_parameters = CGI::parse(@env.REQUEST_URI.split('?')[-1])
render :show
end
end
Expand Down Expand Up @@ -352,13 +353,26 @@ def _eval str
if @headers['Content-Type'] != 'text/html'
@no_layout = true
end
str_id = @cookies.camping_sid.gsub(/\W/, '')
Tepee::Box.eval %{ session_id = '#{str_id}' }
code = %{
Markaby::Builder.new(:env => #{_dump(@env)}, :input => #{_dump(@input)}) do
instance_vars = {
:env => #{_dump(@env)}, :input => #{_dump(@input)},
:args => #{_dump(@cgi_parameters)},
:session_id => #{_dump(@cookies.camping_sid)}
}
doc = Markaby::Builder.new(instance_vars) do
def puts(txt); self << txt; end
ERbLight.new(#{str.dump}).result(binding)
end.to_s
meth = instance_vars[:args]['method']
if meth.empty?
doc
else
args = OpenStruct.new(instance_vars[:args])
#{@page.title.gsub(/^./) {|c| c.upcase} }.send(meth[0], args)
end
}
@line_zero = Tepee::Box.eval(%{__LINE__}) + code.count("\n") # FIXME
str = Tepee::Box.eval code, :timeout => 10
Expand Down

0 comments on commit 02c1688

Please sign in to comment.