Changeset 156

Show
Ignore:
Timestamp:
08/31/2006 12:49:31 (2 years ago)
Author:
why
Message:
  • examples/: updates from zimbatm's patch #80 -- tepee is all glossy now i guess.
Location:
trunk/examples
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/blog.rb

    r153 r156  
    22 
    33$:.unshift File.dirname(__FILE__) + "/../../lib" 
    4 require 'rubygems' 
    5 require_gem 'camping', '>=1.4' 
     4require 'camping' 
    65require 'camping/session' 
    76   
     
    271270end 
    272271 
    273 if __FILE__ == $0 
    274   begin 
    275     require 'mongrel/camping' 
    276   rescue LoadError => e 
    277     abort "** Try running `camping #$0' instead." 
    278   end 
    279  
    280   Blog::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'examples.db' 
    281   Blog::Models::Base.logger = Logger.new('camping.log') 
    282   Blog::Models::Base.threaded_connections=false 
    283   Blog.create 
    284  
    285   server = Mongrel::Camping::start("0.0.0.0",3002,"/blog",Blog) 
    286   puts "** Blog example is running at http://localhost:3002/blog" 
    287   puts "** Default username is `admin', password is `camping'" 
    288   server.run.join 
    289 end 
  • trunk/examples/campsh.rb

    r146 r156  
    108108        def get(name, version = nil) 
    109109            unless @cmd = Command.find_by_name(name) 
    110                 redirect(Edit, page_name) 
     110                redirect(Edit, name) 
    111111                return 
    112112            end 
     
    629629end 
    630630 
    631 if __FILE__ == $0 
    632   begin 
    633     require 'mongrel/camping' 
    634   rescue LoadError => e 
    635     abort "** Try running `camping #$0' instead." 
    636   end 
    637  
    638   CampSh::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'examples.db' 
    639   CampSh::Models::Base.logger = Logger.new('camping.log') 
    640   CampSh::Models::Base.threaded_connections=false 
    641   CampSh.create 
    642  
    643   server = Mongrel::Camping::start("0.0.0.0",3002,"/campsh",CampSh) 
    644   puts "** CampSh example is running at http://localhost:3002/campsh" 
    645   server.run.join 
    646 end 
  • trunk/examples/tepee.rb

    r149 r156  
    3434  class Index < R '/' 
    3535    def get 
    36       redirect Show, 'home_page' 
    37     end 
    38   end 
    39  
    40   class List < R '/list' 
    41     def get 
    42       @pages = Page.find :all, :order => 'title' 
    43       render :list 
    44     end 
    45   end 
    46  
    47   class Show < R '/s/(\w+)', '/s/(\w+)/(\d+)' 
     36      redirect Show, 'home' 
     37    end 
     38  end 
     39 
     40  class Show < R '/(\w+)', '/(\w+)/(\d+)' 
    4841    def get page_name, version = nil 
    4942      redirect(Edit, page_name, 1) and return unless @page = Page.find_by_title(page_name) 
     
    5346  end 
    5447 
    55   class Edit < R '/e/(\w+)/(\d+)', '/e/(\w+)' 
     48  class Edit < R '/(\w+)/edit', '/(\w+)/(\d+)/edit'  
    5649    def get page_name, version = nil 
    5750      @page = Page.find_or_create_by_title(page_name) 
     
    6255    def post page_name 
    6356      Page.find_or_create_by_title(page_name).update_attributes :body => input.post_body and redirect Show, page_name 
     57    end 
     58  end 
     59 
     60  class Versions < R '/(\w+)/versions' 
     61    def get page_name 
     62      @page = Page.find_or_create_by_title(page_name) 
     63      @versions = @page.versions 
     64      render :versions 
     65    end 
     66  end 
     67 
     68  class List < R '/all/list' 
     69    def get 
     70      @pages = Page.find :all, :order => 'title' 
     71      render :list 
     72    end 
     73  end 
     74 
     75  class Stylesheet < R '/css/tepee.css' 
     76    def get 
     77@headers['Content-Type'] = 'text/css' 
     78File.read(__FILE__).gsub(/.*__END__/m, '') 
    6479    end 
    6580  end 
     
    7186      head do 
    7287        title 'test' 
     88        link :href=>R(Stylesheet), :rel=>'stylesheet', :type=>'text/css'  
    7389      end 
    7490      style <<-END, :type => 'text/css' 
     
    87103          small do 
    88104            span "welcome to " ; a 'tepee', :href => "http://code.whytheluckystiff.net/svn/camping/trunk/examples/tepee.rb" 
    89             span '. go ' ;       a 'home',  :href => R(Show, 'home_page') 
     105            span '. go ' ;       a 'home',  :href => R(Show, 'home') 
    90106            span '. list all ' ; a 'pages', :href => R(List) 
    91107          end 
     
    102118    div { _markup @version.body } 
    103119    p.actions do  
    104       a 'edit',    :href => R(Edit, @version.title, @version.version) 
    105       a 'back',    :href => R(Show, @version.title, @version.version-1) unless @version.version == 1 
    106       a 'next',    :href => R(Show, @version.title, @version.version+1) unless @version.version == @page.version 
    107       a 'current', :href => R(Show, @version.title)                     unless @version.version == @page.version 
     120      _button 'edit',      :href => R(Edit, @version.title, @version.version)  
     121      _button 'back',      :href => R(Show, @version.title, @version.version-1) unless @version.version == 1  
     122      _button 'next',      :href => R(Show, @version.title, @version.version+1) unless @version.version == @page.version  
     123      _button 'current',   :href => R(Show, @version.title)                     unless @version.version == @page.version  
     124      _button 'versions',  :href => R(Versions, @page.title)  
    108125    end 
    109126  end 
    110127 
    111128  def edit 
     129    h1 @page.title  
    112130    form :method => 'post', :action => R(Edit, @page.title) do 
    113131      p do 
    114         label 'Body' ; br 
    115132        textarea @page.body, :name => 'post_body', :rows => 50, :cols => 100 
    116133      end 
    117        
    118       p do 
    119         input :type => 'submit' 
    120         a 'cancel', :href => R(Show, @page.title, @page.version) 
    121       end 
    122     end 
     134      input :type => 'submit', :value=>'change'  
     135    end 
     136    _button 'cancel', :href => R(Show, @page.title, @page.version)  
     137    a 'syntax', :href => 'http://hobix.com/textile/', :target=>'_blank'  
    123138  end 
    124139 
     
    126141    h1 'all pages' 
    127142    ul { @pages.each { |p| li { a p.title, :href => R(Show, p.title) } } } 
     143  end 
     144 
     145  def versions 
     146    h1 @page.title 
     147    ul do 
     148      @versions.each do |page| 
     149        li do 
     150          span page.version 
     151          _button 'show',   :href => R(Show, page.title, page.version) 
     152          _button 'edit',   :href => R(Edit, page.title, page.version) 
     153        end 
     154      end 
     155    end 
     156  end 
     157 
     158  def _button(text, options={}) 
     159    form :method=>:get, :action=>options[:href] do 
     160      input :type=>'submit', :name=>'submit', :value=>text 
     161    end 
    128162  end 
    129163 
     
    147181  Tepee::Models.create_schema :assume => (Tepee::Models::Page.table_exists? ? 1.0 : 0.0) 
    148182end 
    149  
    150 if __FILE__ == $0 
    151   begin 
    152     require 'mongrel/camping' 
    153   rescue LoadError => e 
    154     abort "** Try running `camping #$0' instead." 
    155   end 
    156  
    157   Tepee::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'examples.db' 
    158   Tepee::Models::Base.logger = Logger.new('camping.log') 
    159   Tepee::Models::Base.threaded_connections=false 
    160   Tepee.create 
    161    
    162   server = Mongrel::Camping::start("0.0.0.0",3001,"/tepee",Tepee) 
    163   puts "** Tepee example is running at http://localhost:3000/tepee" 
    164   server.run.join 
    165 end 
     183__END__ 
     184/** focus **/ 
     185/* 
     186a:hover:active { 
     187  color: #10bae0; 
     188} 
     189 
     190a:not(:hover):active { 
     191  color: #0000ff; 
     192} 
     193 
     194*:focus { 
     195  -moz-outline: 2px solid #10bae0 !important; 
     196  -moz-outline-offset: 1px !important; 
     197  -moz-outline-radius: 3px !important; 
     198} 
     199 
     200button:focus, 
     201input[type="reset"]:focus, 
     202input[type="button"]:focus, 
     203input[type="submit"]:focus, 
     204input[type="file"] > input[type="button"]:focus { 
     205  -moz-outline-radius: 5px !important; 
     206} 
     207 
     208button:focus::-moz-focus-inner { 
     209  border-color: transparent !important; 
     210} 
     211 
     212button::-moz-focus-inner, 
     213input[type="reset"]::-moz-focus-inner, 
     214input[type="button"]::-moz-focus-inner, 
     215input[type="submit"]::-moz-focus-inner, 
     216input[type="file"] > input[type="button"]::-moz-focus-inner { 
     217  border: 1px dotted transparent !important; 
     218} 
     219textarea:focus, button:focus, select:focus, input:focus { 
     220  -moz-outline-offset: -1px !important; 
     221} 
     222input[type="radio"]:focus { 
     223  -moz-outline-radius: 12px; 
     224  -moz-outline-offset: 0px !important; 
     225} 
     226a:focus { 
     227  -moz-outline-offset: 0px !important; 
     228} 
     229*/ 
     230form { display: inline; } 
     231 
     232/** Gradient **/ 
     233small, pre, textarea, textfield, button, input, select { 
     234   color: #4B4B4C !important; 
     235   background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAAeCAMAAAAxfD/2AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAAtUExURfT09PLy8vHx8fv7+/j4+PX19fn5+fr6+vf39/z8/Pb29vPz8/39/f7+/v///0c8Y4oAAAA5SURBVHjaXMZJDgAgCMDAuouA/3+uHPRiMmlKzmhCFRorLOakVnpnDEpBBDHM8ODs/bz372+PAAMAXIQCfD6uIDsAAAAASUVORK5CYII=) !important; 
     236   background-color: #FFF !important; 
     237   background-repeat: repeat-x !important; 
     238   border: 1px solid #CCC !important; 
     239} 
     240 
     241button, input { margin: 3px; } 
     242