Changeset 156
- Timestamp:
- 08/31/2006 12:49:31 (2 years ago)
- Location:
- trunk/examples
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/blog.rb
r153 r156 2 2 3 3 $:.unshift File.dirname(__FILE__) + "/../../lib" 4 require 'rubygems' 5 require_gem 'camping', '>=1.4' 4 require 'camping' 6 5 require 'camping/session' 7 6 … … 271 270 end 272 271 273 if __FILE__ == $0274 begin275 require 'mongrel/camping'276 rescue LoadError => e277 abort "** Try running `camping #$0' instead."278 end279 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=false283 Blog.create284 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.join289 end -
trunk/examples/campsh.rb
r146 r156 108 108 def get(name, version = nil) 109 109 unless @cmd = Command.find_by_name(name) 110 redirect(Edit, page_name)110 redirect(Edit, name) 111 111 return 112 112 end … … 629 629 end 630 630 631 if __FILE__ == $0632 begin633 require 'mongrel/camping'634 rescue LoadError => e635 abort "** Try running `camping #$0' instead."636 end637 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=false641 CampSh.create642 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.join646 end -
trunk/examples/tepee.rb
r149 r156 34 34 class Index < R '/' 35 35 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+)' 48 41 def get page_name, version = nil 49 42 redirect(Edit, page_name, 1) and return unless @page = Page.find_by_title(page_name) … … 53 46 end 54 47 55 class Edit < R '/ e/(\w+)/(\d+)', '/e/(\w+)'48 class Edit < R '/(\w+)/edit', '/(\w+)/(\d+)/edit' 56 49 def get page_name, version = nil 57 50 @page = Page.find_or_create_by_title(page_name) … … 62 55 def post page_name 63 56 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' 78 File.read(__FILE__).gsub(/.*__END__/m, '') 64 79 end 65 80 end … … 71 86 head do 72 87 title 'test' 88 link :href=>R(Stylesheet), :rel=>'stylesheet', :type=>'text/css' 73 89 end 74 90 style <<-END, :type => 'text/css' … … 87 103 small do 88 104 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') 90 106 span '. list all ' ; a 'pages', :href => R(List) 91 107 end … … 102 118 div { _markup @version.body } 103 119 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) 108 125 end 109 126 end 110 127 111 128 def edit 129 h1 @page.title 112 130 form :method => 'post', :action => R(Edit, @page.title) do 113 131 p do 114 label 'Body' ; br115 132 textarea @page.body, :name => 'post_body', :rows => 50, :cols => 100 116 133 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' 123 138 end 124 139 … … 126 141 h1 'all pages' 127 142 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 128 162 end 129 163 … … 147 181 Tepee::Models.create_schema :assume => (Tepee::Models::Page.table_exists? ? 1.0 : 0.0) 148 182 end 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 /* 186 a:hover:active { 187 color: #10bae0; 188 } 189 190 a: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 200 button:focus, 201 input[type="reset"]:focus, 202 input[type="button"]:focus, 203 input[type="submit"]:focus, 204 input[type="file"] > input[type="button"]:focus { 205 -moz-outline-radius: 5px !important; 206 } 207 208 button:focus::-moz-focus-inner { 209 border-color: transparent !important; 210 } 211 212 button::-moz-focus-inner, 213 input[type="reset"]::-moz-focus-inner, 214 input[type="button"]::-moz-focus-inner, 215 input[type="submit"]::-moz-focus-inner, 216 input[type="file"] > input[type="button"]::-moz-focus-inner { 217 border: 1px dotted transparent !important; 218 } 219 textarea:focus, button:focus, select:focus, input:focus { 220 -moz-outline-offset: -1px !important; 221 } 222 input[type="radio"]:focus { 223 -moz-outline-radius: 12px; 224 -moz-outline-offset: 0px !important; 225 } 226 a:focus { 227 -moz-outline-offset: 0px !important; 228 } 229 */ 230 form { display: inline; } 231 232 /** Gradient **/ 233 small, 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 241 button, input { margin: 3px; } 242
