Changeset 117

Show
Ignore:
Timestamp:
01/17/2007 20:33:23 (22 months ago)
Author:
why
Message:
  • tippytippytepee/tepee.rb: allow the wiki page to set headers. if a wiki page isn't text/html, skip the layout. Web.get allows wiki pages to fetch over HTTP.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/tippytippytepee/tepee.rb

    r116 r117  
    22require 'sandbox' 
    33$:.unshift File.dirname(__FILE__) + "/../../lib" 
    4 %w(rubygems redcloth camping acts_as_versioned).each { |lib| require lib } 
     4%w(open-uri rubygems json redcloth camping acts_as_versioned).each { |lib| require lib } 
    55 
    66Camping.goes :Tepee 
     7 
     8module Web 
     9  def self.get(url) 
     10    JSON.parse(URI.parse(url).read) 
     11  end 
     12end 
    713 
    814module Tepee::Models 
     
    3541Tepee::Box.load "support.rb" 
    3642Tepee::Box.ref Tepee::Models::Page 
     43Tepee::Box.ref Web 
    3744Tepee::Box.import HashWithIndifferentAccess 
    3845 
     
    8996module Tepee::Views 
    9097  def layout 
    91     html do 
    92       head do 
    93         title 'test' 
    94         link :href=>R(Stylesheet), :rel=>'stylesheet', :type=>'text/css'  
    95       end 
    96       style <<-END, :type => 'text/css' 
    97         body { 
    98           font-family: verdana, arial, sans-serif; 
    99         } 
    100         h1, h2, h3, h4, h5 { 
    101           font-weight: normal; 
    102         } 
    103         p.actions a { 
    104           margin-right: 6px; 
    105         } 
    106       END 
    107       body do 
    108         p do 
    109           small do 
    110             span "welcome to " ; a 'tepee', :href => "http://code.whytheluckystiff.net/svn/camping/trunk/examples/tepee.rb" 
    111             span '. go ' ;       a 'home',  :href => R(Show, 'home') 
    112             span '. list all ' ; a 'pages', :href => R(List) 
     98    unless @no_layout 
     99      html do 
     100        head do 
     101          title 'test' 
     102          link :href=>R(Stylesheet), :rel=>'stylesheet', :type=>'text/css'  
     103        end 
     104        style <<-END, :type => 'text/css' 
     105          body { 
     106            font-family: verdana, arial, sans-serif; 
     107          } 
     108          h1, h2, h3, h4, h5 { 
     109            font-weight: normal; 
     110          } 
     111          p.actions a { 
     112            margin-right: 6px; 
     113          } 
     114        END 
     115        body do 
     116          p do 
     117            small do 
     118              span "welcome to " ; a 'tepee', :href => "http://code.whytheluckystiff.net/svn/camping/trunk/examples/tepee.rb" 
     119              span '. go ' ;       a 'home',  :href => R(Show, 'home') 
     120              span '. list all ' ; a 'pages', :href => R(List) 
     121            end 
     122          end 
     123          div.content do 
     124            self << yield 
    113125          end 
    114126        end 
    115         div.content do 
    116           self << yield 
    117         end 
    118       end 
     127      end 
     128    else 
     129      self << yield 
    119130    end 
    120131  end 
    121132 
    122133  def show 
    123     h1 @page.title 
    124     div { _markup @version.body } 
    125     if @boxx 
    126       div.error! @boxx 
    127     end 
    128     p.actions do  
    129       _button 'edit',      :href => R(Edit, @version.title, @version.version)  
    130       _button 'back',      :href => R(Show, @version.title, @version.version-1) unless @version.version == 1  
    131       _button 'next',      :href => R(Show, @version.title, @version.version+1) unless @version.version == @page.version  
    132       _button 'current',   :href => R(Show, @version.title)                     unless @version.version == @page.version  
    133       _button 'versions',  :href => R(Versions, @page.title)  
     134    m = _markup @version.body 
     135    unless @no_layout 
     136      h1 @page.title 
     137      div { m } 
     138      if @boxx 
     139        div.error! @boxx 
     140      end 
     141      p.actions do  
     142        _button 'edit',      :href => R(Edit, @version.title, @version.version)  
     143        _button 'back',      :href => R(Show, @version.title, @version.version-1) unless @version.version == 1  
     144        _button 'next',      :href => R(Show, @version.title, @version.version+1) unless @version.version == @page.version  
     145        _button 'current',   :href => R(Show, @version.title)                     unless @version.version == @page.version  
     146        _button 'versions',  :href => R(Versions, @page.title)  
     147      end 
     148    else 
     149      self << m 
    134150    end 
    135151  end 
     
    149165  def list 
    150166    h1 'all pages' 
    151     ul { @pages.each { |p| li { a p.title, :href => R(Show, p.title) } } } 
     167    ul { @pages.each { |p|  
     168      li { a(p.title, :href => R(Show, p.title)) + " [" + a("edit", :href => R(Edit, p.title)) + "]" } 
     169    } } 
    152170  end 
    153171 
     
    191209 
    192210  def _eval str 
     211    @no_layout = false 
    193212    @boxx = nil 
    194213    begin 
     214      str.gsub!(/^@\s+([\w\-]+):\s+(.+)$/) do 
     215        @headers[$1] = $2.strip; '' 
     216      end 
     217      if @headers['Content-Type'] != 'text/html' 
     218        @no_layout = true 
     219      end 
    195220      str = Tepee::Box.eval %{ 
    196221        Markaby::Builder.new(:env => #{_dump(@env)}, :input => #{_dump(@input)}) do 
     222          def puts(txt); self << txt; end 
    197223          ERbLight.new(#{str.dump}).result(binding) 
    198224        end.to_s 
     
    200226    rescue Sandbox::Exception => @boxx 
    201227    end 
    202     RedCloth.new(str, [ :hard_breaks ]).to_html 
     228    # RedCloth.new(str, [ :hard_breaks ]).to_html 
    203229  end 
    204230end