From 498d4252e3e3bc7533a4093a9e76ec4cfef6bb4a Mon Sep 17 00:00:00 2001 From: "Gun.io Whitespace Robot" Date: Sat, 17 Dec 2011 01:50:36 -0500 Subject: [PATCH] Remove whitespace [Gun.io WhitespaceBot] --- CHANGELOG | 60 +++++------ COPYING | 6 +- README | 8 +- Rakefile | 28 ++--- book/02_getting_started | 80 +++++++------- book/51_upgrading | 22 ++-- extras/rdoc/generator/singledarkfish.rb | 56 +++++----- .../generator/template/flipbook/js/camping.js | 22 ++-- .../generator/template/flipbook/page.rhtml | 2 +- .../rdoc/generator/template/flipbook/rdoc.css | 4 +- .../generator/template/flipbook/readme.rhtml | 2 +- .../template/flipbook/reference.rhtml | 10 +- .../generator/template/flipbook/toc.rhtml | 2 +- lib/camping-unabridged.rb | 100 +++++++++--------- lib/camping/ar.rb | 4 +- lib/camping/mab.rb | 2 +- lib/camping/reloader.rb | 52 ++++----- lib/camping/server.rb | 70 ++++++------ lib/camping/session.rb | 4 +- setup.rb | 8 +- test/app_markup.rb | 10 +- test/app_route_generating.rb | 2 +- test/app_sessions.rb | 8 +- test/app_simple.rb | 34 +++--- test/apps/forms.rb | 4 +- test/apps/forward_to_other_controller.rb | 24 ++--- test/test_helper.rb | 14 +-- 27 files changed, 319 insertions(+), 319 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b93a4850..e6af1424 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,7 +4,7 @@ * @state is now an alias of @env['rack.session'] * Camping.use injects a Rack middleware. * Update Flipbook to RDoc 2.4 -* Removed old examples. +* Removed old examples. * Updated examples/blog.rb * Camping::Apps returns! * Session-cookies now timeout naturally (thanks jenna!) @@ -24,7 +24,7 @@ r404 : called when a controller was not found r500 : called on uncaught exception r501 : called on undefined method - + All of those can be overridden at your taste. * Markaby no longer required. Like AR, is it autoloaded on (Mab) usage. @@ -36,42 +36,42 @@ = 1.5 === 3rd Oct, 2006 -* Camping::Apps stores an array of classes for all loaded apps. +* Camping::Apps stores an array of classes for all loaded apps. * bin/camping can be given a directory. Like: camping examples/ -* Console mode -- thank zimbatm. Use: camping -C yourapp.rb +* Console mode -- thank zimbatm. Use: camping -C yourapp.rb * Call controllers with Camping.method_missing. Tepee.get(:Index) #=> (Response) - Blog.post(:Delete, id) #=> (Response) + Blog.post(:Delete, id) #=> (Response) - Blog.post(:Login, :input => {'username' => 'admin', 'password' => 'camping'}) - #=> # + Blog.post(:Login, :input => {'username' => 'admin', 'password' => 'camping'}) + #=> # - Blog.get(:Info, :env => {:HTTP_HOST => 'wagon'}) - #=> #'wagon'} ...> + Blog.get(:Info, :env => {:HTTP_HOST => 'wagon'}) + #=> #'wagon'} ...> -* Using \r\n instead of \n on output. FastCGI has these needs. -* ActiveRecord no longer required or installed. -* If you refer to Models::Base, however, ActiveRecord will be loaded with autoload. (see lib/camping/db.rb) +* Using \r\n instead of \n on output. FastCGI has these needs. +* ActiveRecord no longer required or installed. +* If you refer to Models::Base, however, ActiveRecord will be loaded with autoload. (see lib/camping/db.rb) * new Camping::FastCGI.serve which will serve a whole directory of apps - (see http://code.whytheluckystiff.net/camping/wiki/TheCampingServer) -* ~/.campingrc can contain database connection info if you want your default to be something other than SQLite. - - database: - adapter: mysql - username: camping - socket: /tmp/mysql.sock - password: NOFORESTFIRES - database: camping - -* controllers are now *ordered*. uses the inherited hook to keep track of all - classes created with R. those classes are scanned, in order, when a request is - made. any other controllers are handled first. so if you plan on overriding the - urls method, be sure to subclass from R(). -* Console mode will load .irbrc in the working directory, if present. - (for example, in my ~/git/balloon directory, i have this in the .irbrc: - include Balloon::Models - when camping -C balloon.rb gets run, the models all get included in main.) + (see http://code.whytheluckystiff.net/camping/wiki/TheCampingServer) +* ~/.campingrc can contain database connection info if you want your default to be something other than SQLite. + + database: + adapter: mysql + username: camping + socket: /tmp/mysql.sock + password: NOFORESTFIRES + database: camping + +* controllers are now *ordered*. uses the inherited hook to keep track of all + classes created with R. those classes are scanned, in order, when a request is + made. any other controllers are handled first. so if you plan on overriding the + urls method, be sure to subclass from R(). +* Console mode will load .irbrc in the working directory, if present. + (for example, in my ~/git/balloon directory, i have this in the .irbrc: + include Balloon::Models + when camping -C balloon.rb gets run, the models all get included in main.) * And, of course, many other bugfixes from myself and the loyal+kind zimbatm... * Markaby updated to 0.5. (See its CHANGELOG.) diff --git a/COPYING b/COPYING index 94b6b84b..8647e4b4 100644 --- a/COPYING +++ b/COPYING @@ -6,13 +6,13 @@ deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README b/README index ab8a6223..c8e08b6d 100644 --- a/README +++ b/README @@ -14,7 +14,7 @@ got it going. A skeletal Camping blog could look like this: require 'camping' - + Camping.goes :Blog module Blog::Models @@ -49,7 +49,7 @@ A skeletal Camping blog could look like this: end end end - + == Installation Interested yet? Luckily it's quite easy to install Camping. We'll be using @@ -69,7 +69,7 @@ need to install +markaby+, and if you're going to use the database you need gem install markaby gem install activerecord - + == Learning First of all, you should read {the first chapters}[link:book/01_introduction.html] @@ -81,7 +81,7 @@ documentation for all the different parts of Camping. useful tricks that we've collected over the years. Don't be afraid to share your own discoveries; the more, the better! -And if there's anything you're wondering about, don't be shy, but rather +And if there's anything you're wondering about, don't be shy, but rather subscribe to {the mailing list}[http://rubyforge.org/mailman/listinfo/camping-list] and ask there. We also have an IRC channel over at Freenode, so if you feel like chatting with us, you should join {#camping @ irc.freenode.net}[http://java.freenode.net/?channel=camping]. diff --git a/Rakefile b/Rakefile index 589b352d..f6ca7989 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ VERS = ENV['VERSION'] || (REV.zero? ? BRANCH : [BRANCH, REV] * '.') CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log', '.*.pt'] RDOC_OPTS = ["--line-numbers", "--quiet", "--main", "README"] - + ## Packaging spec = Gem::Specification.new do |s| @@ -38,14 +38,14 @@ spec = s.required_ruby_version = '>= 1.8.2' s.files = %w(COPYING README Rakefile) + - Dir.glob("{bin,doc,test,lib,extras,book}/**/*") + + Dir.glob("{bin,doc,test,lib,extras,book}/**/*") + Dir.glob("ext/**/*.{h,c,rb}") + Dir.glob("examples/**/*.rb") + Dir.glob("tools/*.rb") s.require_path = "lib" s.bindir = "bin" - end + end omni = Gem::Specification.new do |s| @@ -61,7 +61,7 @@ omni = s.add_dependency('mongrel') s.add_dependency('RedCloth') end - + ## RDoc begin @@ -85,16 +85,16 @@ Rake::RDocTask.new(:docs) do |rdoc| puts "** Camping needs RDoc 2.4 in order to use the Flipbook template." end end - + rdoc.inline_source = false # --inline-source is deprecated rdoc.rdoc_dir = 'doc' rdoc.title = "Camping, a Microframework" rdoc.rdoc_files.add ['README', 'lib/camping-unabridged.rb', 'lib/camping/**/*.rb', 'book/*'] end - + task :rubygems_docs do require 'rubygems/doc_manager' - + def spec.installation_path; '.' end def spec.full_gem_path; '.' end manager = Gem::DocManager.new(spec) @@ -135,15 +135,15 @@ task :diff do require 'ruby_parser' u = Tempfile.new('unabridged') m = Tempfile.new('mural') - + u << Ruby2Ruby.new.process(RubyParser.new.parse(File.read("lib/camping.rb"))) m << Ruby2Ruby.new.process(RubyParser.new.parse(File.read("lib/camping-unabridged.rb"))) - + u.flush m.flush - + sh "diff -u #{u.path} #{m.path} | less" - + u.delete m.delete end @@ -159,11 +159,11 @@ namespace :check do require 'ruby_parser' u = RubyParser.new.parse(File.read("lib/camping-unabridged.rb")) m = RubyParser.new.parse(File.read("lib/camping.rb")) - + u.reject! do |sexp| sexp.is_a?(Sexp) and sexp[1] == s(:gvar, :$LOADED_FEATURES) end - + unless u == m STDERR.puts "camping.rb and camping-unabridged.rb are not synchronized." error = true @@ -194,7 +194,7 @@ namespace :check do i += 1 end end - + task :exit do exit 1 if error end diff --git a/book/02_getting_started b/book/02_getting_started index 199c3c49..977cfeba 100644 --- a/book/02_getting_started +++ b/book/02_getting_started @@ -1,7 +1,7 @@ = Getting Started Start a new text file called nuts.rb. Here's what you put inside: - + Camping.goes :Nuts Save it. Then, open a command prompt in the same directory. You'll want to @@ -19,7 +19,7 @@ machine. Open your browser and visit http://localhost:3301/. Your browser window should show: Camping Problem! - + / Not found No problem with that. The Camping Server is running, but it doesn't know what @@ -75,7 +75,7 @@ application. Replace the module Nuts::Controllers with: p "The current time is: #{@time}" end end - + Save the file and refresh your browser window and it should show a message like: @@ -110,7 +110,7 @@ simplest ones first. "You got here by: /welcome/to/my/site" end end - + class Digits < R '/nuts/(\d+)' def get(number) "You got here by: /nuts/#{number}" @@ -122,15 +122,15 @@ simplest ones first. "You got here by: /gorp/#{everything_else_than_a_slash}" end end - + class DigitsAndEverything < R '/nuts/(\d+)/([^/]+)' def get(number, everything) "You got here by: /nuts/#{number}/#{everything}" end end end - -Add this to nuts.rb and try if you can hit all of the controllers. + +Add this to nuts.rb and try if you can hit all of the controllers. Also notice how everything inside a parenthesis gets passed into the method, and is ready at your disposal. @@ -145,32 +145,32 @@ This just in: "You got here by: /" end end - + class WelcomeToMySite def get "You got here by: /welcome/to/my/site" end end - + class NutsN def get(number) "You got here by: /nuts/#{number}" end end - + class GorpX def get(everything_else_than_a_slash) "You got here by: /gorp/#{everything_else_than_a_slash}" end end - + class NutsNX def get(number, everything) "You got here by: /nuts/#{number}/#{everything}" end end end - + Drop the < R-part and it attemps to read your mind. It won't always succeed, but it can simplify your application once in a while. @@ -187,7 +187,7 @@ Let's start over again. class Page < Base end end - + Obviously, this won't do anything, since we don't have any controllers, but let's rather have a look at we _do_ have. @@ -197,13 +197,13 @@ for your users and one for your blog posts? Well, I think you already know how to do it. However, our model is missing something essential: a skeleton. - + Camping.goes :Nuts - + module Nuts::Models class Page < Base end - + class BasicFields < V 1.0 def self.up create_table Page.table_name do |t| @@ -213,13 +213,13 @@ However, our model is missing something essential: a skeleton. t.timestamps end end - + def self.down drop_table Page.table_name end end end - + Now we have our first version of our model. It says: If you want to migrate up to version one, @@ -229,10 +229,10 @@ Now we have our first version of our model. It says: "content" which is a larger text, "created_at" which is the time it was created, "updated_at" which is the previous time it was updated. - + If you want to migrate down from version one, remove the skeleton for the Page model. - + This is called a _migration_. Whenever you want to change or add new models you simply add a new migration below, where you increase the version number. All of these migrations builds upon each other like LEGO blocks. Now we just need to tell Camping to use our migration. Write this at the bottom of nuts.rb @@ -245,7 +245,7 @@ When The Camping Server boots up, it will automatically call Nuts.create. You can put all kind of startup-code here, but right now we only want to create our skeleton (or upgrade if needed). Start The Camping Server again and observe: - + $ camping nuts.rb ** Starting Mongrel on 0.0.0.0:3301 -- create_table("nuts_schema_infos") @@ -254,7 +254,7 @@ Server again and observe: -- create_table(:nuts_pages) -> 0.0033s == Nuts::Models::BasicFields: migrated (0.0038s) ========================== - + Restart it, and enjoy the silence. There's no point of re-creating the skeleton this time. @@ -268,13 +268,13 @@ Let's explore how our model works by going into the _console_ $ camping -C nuts.rb ** Starting console >> - + Now it's waiting for your input, and will give you the answer when you press Enter. Here's what I did, leaving out the boring answers. You should add your own pages. >> Page = Nuts::Models::Page - + >> hiking = Page.new(:title => "Hiking") >> hiking.content = "You can also set the values like this." >> hiking.save @@ -287,16 +287,16 @@ own pages. >> page.content >> page.created_at >> page.updated_at - + >> Page.find_by_title("Fishing") => nil - + ## Page.create automatically saves the page for you. >> Page.create(:title => "Fishing", :content => "Go fish!") - + >> Page.count => 2 - + Now I have two pages: One about hiking and one about fishing. == Wrapping it up @@ -312,7 +312,7 @@ Update nuts.rb so it also contains something like this: render :list end end - + class PageX def get(title) @page = Page.find_by_title(title) @@ -338,15 +338,15 @@ Update nuts.rb so it also contains something like this: self << @page.content end end - + Here we meet our first _helper_: R(PageX, page.title) - + This is the reversed router and it generates a URL based on a controller. Camping ships with a few, but very useful, helpers and you can easily add your owns. Have a look at Camping::Helpers for how you use these. - + There's a lot of improvements you could do here. Let me suggest: * Show when the page was created and last updated. @@ -354,7 +354,7 @@ There's a lot of improvements you could do here. Let me suggest: * What should the front page show? * Add a layout. * Jazz it up a bit. - + == The last touch We have one major flaw in our little application. You can't edit or add new @@ -369,19 +369,19 @@ pages. Let's see if we can fix that: redirect PageXEdit, title end end - + def post(title) # If it doesn't exist, initialize it: @page = Page.find_or_initialize_by_title(title) # This is the same as: # @page = Page.find_by_title(title) || Page.new(:title => title) - + @page.content = @input.content @page.save redirect PageX, title end end - + class PageXEdit def get(title) @page = Page.find_or_initialize_by_title(title) @@ -389,7 +389,7 @@ pages. Let's see if we can fix that: end end end - + The core of this code lies in the new post method in the PageX controller. When someone types an address or follows a link, they'll end up at the get method, but you can easily create a form which rather sends @@ -405,7 +405,7 @@ forms and those in the URL (/posts?page=50). Here's an edit-view, but you can probably do better. See if you can integrate all of this with what you already have. - + module Nuts::Views def edit h1 @page.title @@ -414,12 +414,12 @@ integrate all of this with what you already have. :rows => 10, :cols => 50 br - + input :type => :submit, :value => "Submit!" end end end - + == Phew. diff --git a/book/51_upgrading b/book/51_upgrading index d9785645..8c144c4f 100644 --- a/book/51_upgrading +++ b/book/51_upgrading @@ -14,7 +14,7 @@ choice. In earlier versions of Camping, you loaded database support by: require 'camping/db' - + Actually, this loaded a very thin layer on top of ActiveRecord, and in the future we want to experiment with other libraries. Therefore you should now simply remove the line, and instead just inherit from Base right away. This @@ -25,11 +25,11 @@ We also encourage you to use Model.table_name instead of ## Don't require anything: # require 'camping/db' - + module Nuts::Models ## Just inherit Base: class Page < Base; end - + ## Migrations have to come *after* the models: class CreateTheBasics < V 0.1 def self.up @@ -37,7 +37,7 @@ We also encourage you to use Model.table_name instead of ... end end - + def self.down drop_table Page.table_name end @@ -54,23 +54,23 @@ required, and see Camping::Session more details. module Nuts ## Include Camping::Session as before: include Camping::Session - + ## But also define a secret: secret "Very secret text, which no-one else should know!" end - + def Nuts.create ## And remove the following line: # Camping::Models::Session.create_schema end - + === Error handling Camping now uses three methods in order to handle errors. These replaces the old classes NotFound and ServerError. * Camping::Base#r404 is called when a route can't be found. -* Camping::Base#r501 is called when a route is found, but doesn't respond to +* Camping::Base#r501 is called when a route is found, but doesn't respond to the method. * Camping::Base#r500 is called when an error happens. @@ -80,14 +80,14 @@ You can override these in your application: def r404(path) "Sorry, but I can't find #{path}." end - + def r501(method) "Sorry, but I can't respond to #{method}." end - + def r500(klass, method, ex) "Sorry, but #{klass}##{method} failed with #{ex}." end end - + It should be noted that this might change in the future. diff --git a/extras/rdoc/generator/singledarkfish.rb b/extras/rdoc/generator/singledarkfish.rb index 4819985d..4ea8076b 100644 --- a/extras/rdoc/generator/singledarkfish.rb +++ b/extras/rdoc/generator/singledarkfish.rb @@ -17,34 +17,34 @@ # # Darkfish RDoc HTML Generator -# +# # $Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $ # # == Author/s # * Michael Granger (ged@FaerieMUD.org) -# +# # == Contributors # * Mahlon E. Smith (mahlon@martini.nu) # * Eric Hodel (drbrain@segment7.net) -# +# # == License -# +# # Copyright (c) 2007, 2008, Michael Granger. All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: -# +# # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. -# +# # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# +# # * Neither the name of the author/s, nor the names of the project's # contributors may be used to endorse or promote products derived from this # software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -55,10 +55,10 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# +# class RDoc::Generator::SingleDarkfish < RDoc::Generator::Darkfish RDoc::RDoc.add_generator( self ) - + RDoc::Context.instance_eval do org = instance_method(:http_url) define_method(:http_url) do |prefix| @@ -69,7 +69,7 @@ class RDoc::Generator::SingleDarkfish < RDoc::Generator::Darkfish end end end - + RDoc::AnyMethod.instance_eval do org = instance_method(:path) define_method(:path) do @@ -80,7 +80,7 @@ class RDoc::Generator::SingleDarkfish < RDoc::Generator::Darkfish end end end - + def self.current? RDoc::RDoc.current.generator.class.ancestors.include?(self) end @@ -113,15 +113,15 @@ def initialize( options ) ###### public ###### - + def class_dir '/api.html#class-' - end - + end + def template(name) "#{name}.rhtml" end - + ### Build the initial indices and output objects ### based on an array of TopLevel objects containing ### the extracted information. @@ -133,7 +133,7 @@ def generate( top_levels ) @methods = @classes.map { |m| m.method_list }.flatten.sort @modsort = get_sorted_module_list( @classes ) - # Now actually write the output + # Now actually write the output write_style_sheet generate_thing(:readme, 'index.html') generate_thing(:reference, 'api.html') @@ -143,7 +143,7 @@ def generate( top_levels ) debug_msg "%s: %s\n %s" % [ err.class.name, err.message, err.backtrace.join("\n ") ] raise end - + def generate_book chapters.each do |file| templatefile = @template_dir + template(:page) @@ -152,7 +152,7 @@ def generate_book render_template(templatefile, binding, outfile) end end - + def generate_thing(name, to) debug_msg "Rendering #{name}..." @@ -163,7 +163,7 @@ def generate_thing(name, to) render_template(templatefile, binding, outfile) end - + def methods_for(klass) klass.methods_by_type.each do |type, visibilities| next if visibilities.empty? @@ -175,28 +175,28 @@ def methods_for(klass) end end end - + ## For book.rhtml - + def chapters @chapters ||= @files.select do |file| next unless file.full_name =~ /^book\// - + (class << file; self; end).class_eval { attr_accessor :title, :content, :toc, :id } file.toc = [] file.content = file.description file.title = file.content[%r{

(.*?)

}, 1] - + file.content.gsub!(%r{

(.*?)

}) do |match| arr = [make_id($1), $1] file.toc << arr '

%s

' % arr end - - true + + true end end - + def make_id(title) title.downcase.gsub(/\s/, '-').gsub(/[^\w-]+/, '') end diff --git a/extras/rdoc/generator/template/flipbook/js/camping.js b/extras/rdoc/generator/template/flipbook/js/camping.js index 72b72b95..97a939a5 100644 --- a/extras/rdoc/generator/template/flipbook/js/camping.js +++ b/extras/rdoc/generator/template/flipbook/js/camping.js @@ -12,14 +12,14 @@ $(function() { } return false; }); - + if ($('.ref')[0]) { - - $('.mod').hide(); + + $('.mod').hide(); $('.method').hide(); - + var hash = window.location.hash.replace(/--$/, ''); - + if (hash.substring(0, 2) == "#M") { // Show the method and the section m(hash).show(); @@ -30,12 +30,12 @@ $(function() { // Show the first section. s("h2:first").show(); } - + // We need to scroll! if (hash != window.location.hash) { window.location.hash = hash; } - + $('a[href*="#class-"]').click(function() { var link = this.href; var id = link.substring(link.indexOf("#")); @@ -49,7 +49,7 @@ $(function() { s(id).show(); } }); - + $('a[href*="#M"]').click(function() { var link = this.href; var id = link.substring(link.indexOf("#")); @@ -63,17 +63,17 @@ $(function() { m(id).show(); } }); - + // #M0001 -> $(the section + the method body) function m(name) { var base = $(name); return base.parent().add(base.next()); } - + // #class-something -> $(the section below) function s(name) { return $(name).next(); } } - + }); \ No newline at end of file diff --git a/extras/rdoc/generator/template/flipbook/page.rhtml b/extras/rdoc/generator/template/flipbook/page.rhtml index f83ea1fa..18054481 100644 --- a/extras/rdoc/generator/template/flipbook/page.rhtml +++ b/extras/rdoc/generator/template/flipbook/page.rhtml @@ -17,7 +17,7 @@

Camping <%= VERS %>

- +
diff --git a/extras/rdoc/generator/template/flipbook/rdoc.css b/extras/rdoc/generator/template/flipbook/rdoc.css index f7ddc8bd..f58fc927 100644 --- a/extras/rdoc/generator/template/flipbook/rdoc.css +++ b/extras/rdoc/generator/template/flipbook/rdoc.css @@ -73,9 +73,9 @@ h2.ruled { padding-top: 35px; border-top: solid 1px #AA5; } .ref h2 a { background-color: #eee; color: black; - display: block; + display: block; text-align: left; - text-decoration: none; + text-decoration: none; padding: 0.5em 1em; } diff --git a/extras/rdoc/generator/template/flipbook/readme.rhtml b/extras/rdoc/generator/template/flipbook/readme.rhtml index aef6f3ca..8331e0a2 100644 --- a/extras/rdoc/generator/template/flipbook/readme.rhtml +++ b/extras/rdoc/generator/template/flipbook/readme.rhtml @@ -16,7 +16,7 @@

Camping <%= VERS %>

- +
diff --git a/extras/rdoc/generator/template/flipbook/reference.rhtml b/extras/rdoc/generator/template/flipbook/reference.rhtml index 4f688d98..80989788 100644 --- a/extras/rdoc/generator/template/flipbook/reference.rhtml +++ b/extras/rdoc/generator/template/flipbook/reference.rhtml @@ -16,14 +16,14 @@

Camping <%= VERS %>

- +

<%= Time.now %>

Camping, the Reference

- - <% @modsort.each_with_index do |klass, index| %> + + <% @modsort.each_with_index do |klass, index| %>

<%= klass.type.capitalize %> @@ -38,13 +38,13 @@ <% end %>

- +
<%= klass.description.gsub(/<(\/?)h(\d)>/) do # replace

with

and so. "<#{$1}h#{$2.to_i + 1}>" end %> - +

Methods

<% methods_for(klass) do |method, type, visibility| %>

diff --git a/extras/rdoc/generator/template/flipbook/toc.rhtml b/extras/rdoc/generator/template/flipbook/toc.rhtml index 68482527..2df622c6 100644 --- a/extras/rdoc/generator/template/flipbook/toc.rhtml +++ b/extras/rdoc/generator/template/flipbook/toc.rhtml @@ -16,7 +16,7 @@

Camping <%= VERS %>

- +
diff --git a/lib/camping-unabridged.rb b/lib/camping-unabridged.rb index 3e99b1bd..4801691e 100644 --- a/lib/camping-unabridged.rb +++ b/lib/camping-unabridged.rb @@ -22,7 +22,7 @@ def meta_def(m,&b) #:nodoc: # If you're new to Camping, you should probably start by reading the first # chapters of {The Camping Book}[file:book/01_introduction.html#toc]. -# +# # Okay. So, the important thing to remember is that Camping.goes :Nuts # copies the Camping module into Nuts. This means that you should never use # any of these methods/classes on the Camping module, but rather on your own @@ -37,10 +37,10 @@ def meta_def(m,&b) #:nodoc: # # Camping also ships with: # -# * Camping::Session adds states to your app. +# * Camping::Session adds states to your app. # * Camping::Server starts up your app in development. # * Camping::Reloader automatically reloads your apps when a file has changed. -# +# # More importantly, Camping also installs The Camping Server, # please see Camping::Server. module Camping @@ -52,7 +52,7 @@ module Camping Apps = [] # An object-like Hash. # All Camping query string and cookie variables are loaded as this. - # + # # To access the query string, for instance, use the @input variable. # # module Blog::Controllers @@ -82,7 +82,7 @@ def method_missing(m,*a) end undef id, type if ?? == 63 end - + # Helpers contains methods available in your controllers and views. You may # add methods of your own to this module, including many helper methods from # Rails. This is analogous to Rails' ApplicationHelper module. @@ -98,7 +98,7 @@ def method_missing(m,*a) # # Often the helpers depends on other helpers, so you would have to look up # the dependencies too. FormTagHelper for instance required the - # content_tag provided by TagHelper. + # content_tag provided by TagHelper. # # require 'action_view/helpers/form_tag_helper' # @@ -108,7 +108,7 @@ def method_missing(m,*a) # end # # == Return a response immediately - # If you need to return a response inside a helper, you can use throw :halt. + # If you need to return a response inside a helper, you can use throw :halt. # # module Nuts::Helpers # def requires_login! @@ -118,7 +118,7 @@ def method_missing(m,*a) # end # end # end - # + # # module Nuts::Controllers # class Admin # def get @@ -184,7 +184,7 @@ def R(c,*g) p,h=/\(.+?\)/,g.grep(Hash) g-=h raise "bad route" unless u = c.urls.find{|x| - break x if x.scan(p).size == g.size && + break x if x.scan(p).size == g.size && /^#{x}\/?$/ =~ (x=g.inject(x){|x,a| x.sub p,U.escape((a.to_param rescue a))}.gsub(/\\(.)/){$1}) } @@ -199,7 +199,7 @@ def R(c,*g) # self / R(Edit, 1) #=> "/blog/edit/1" # def /(p); p[0] == ?/ ? @root + p : p end - + # Builds a URL route to a controller or a path, returning a URI object. # This way you'll get the hostname and the port number, a complete URL. # @@ -238,12 +238,12 @@ def URL c='/',*a module Base attr_accessor :env, :request, :root, :input, :cookies, :state, :status, :headers, :body - + T = {} L = :layout - + # Finds a template, returning either: - # + # # false # => Could not find template # true # => Found template in Views # instance of Tilt # => Found template in a file @@ -252,11 +252,11 @@ def lookup(n) t = Views.method_defined?(k) || (f = Dir[[O[:views] || "views", "#{n}.*"]*'/'][0]) && Template.new(f, O[f[/\.(\w+)$/, 1].to_sym] || {}) - + O[:dynamic_templates] ? t : T[k] = t end end - + # Display a view, calling it by its method name +v+. If a layout # method is found in Camping::Views, it will be used to wrap the HTML. # @@ -282,7 +282,7 @@ def render(v, *a, &b) # You can directly return HTML form your controller for quick debugging # by calling this method and pass some Markaby to it. - # + # # module Nuts::Controllers # class Info # def get; mab{ code @headers.inspect } end @@ -293,7 +293,7 @@ def render(v, *a, &b) def mab(&b) (@mab ||= Mab.new({},self)).capture(&b) end - + # A quick means of setting this controller's status, body and headers # based on a Rack response: # @@ -357,7 +357,7 @@ def r404(p) # send_email_alert(klass, method, exception) # render :server_error # end - # end + # end def r500(k,m,e) raise e end @@ -367,7 +367,7 @@ def r500(k,m,e) def r501(m) P % "#{m.upcase} not implemented" end - + # Turn a controller into a Rack response. This is designed to be used to # pipe controllers into the r method. A great way to forward your # requests! @@ -389,8 +389,8 @@ def to_a end r.to_a end - - def initialize(env, m) #:nodoc: + + def initialize(env, m) #:nodoc: r = @request = Rack::Request.new(@env = env) @root, @input, @cookies, @state, @headers, @status, @method = @@ -398,7 +398,7 @@ def initialize(env, m) #:nodoc: H[@old_cookies = r.cookies], H[r.session], {}, m =~ /r(\d+)/ ? $1.to_i : 200, m end - + def n(h) # :nodoc: if Hash === h h.inject(H[]) do |m, (k, v)| @@ -414,12 +414,12 @@ def n(h) # :nodoc: # Some magic in Camping can be performed by overriding this method. def service(*a) r = catch(:halt){send(@method, *a)} - @body ||= r + @body ||= r self end end - - + + # Controllers receive the requests and sends a response back to the client. # A controller is simply a class which must implement the HTTP methods it # wants to accept: @@ -430,23 +430,23 @@ def service(*a) # "Hello World" # end # end - # + # # class Posts # def post - # Post.create(@input) + # Post.create(@input) # redirect Index # end - # end + # end # end - # + # # == Defining a controller - # + # # There are two ways to define controllers: Just defining a class and let # Camping figure out the route, or add the route explicitly using R. - # + # # If you don't use R, Camping will first split the controller name up by # words (HelloWorld => Hello and World). Then it would do the following: - # + # # * Replace Index with / # * Replace X with ([^/]+) # * Replace N with (\\\d+) @@ -459,16 +459,16 @@ def service(*a) #++ # # Here's a few examples: - # + # # Index # => / # PostN # => /post/(\d+) # PageX # => /page/([^/]+) # Pages # => /pages - # + # # == The request - # + # # You have these variables which describes the request: - # + # # * @env contains the environment as defined in http://rack.rubyforge.org/doc/SPEC.html # * @request is Rack::Request.new(@env) # * @root is the path where the app is mounted @@ -479,7 +479,7 @@ def service(*a) # == The response # # You can change these variables to your needs: - # + # # * @status is the HTTP status (defaults to 200) # * @headers is a hash with the headers # * @body is the body (a string or something which responds to #each) @@ -508,9 +508,9 @@ class << self def r #:nodoc: @r end - + # Add routes to a controller class by piling them into the R method. - # + # # The route is a regexp which will match the request path. Anything # enclosed in parenthesis will be sent to the method as arguments. # @@ -555,7 +555,7 @@ def D(p, m) N = H.new { |_,x| x.downcase }.merge! "N" => '(\d+)', "X" => '([^/]+)', "Index" => '' # The route maker, this is called by Camping internally, you shouldn't - # need to call it. + # need to call it. # # Still, it's worth know what this method does. Since Ruby doesn't keep # track of class creation order, we're keeping an internal list of the @@ -594,13 +594,13 @@ class << self # # module Nuts::Controllers; ... end # module Nuts::Models; ... end - # module Nuts::Views; ... end + # module Nuts::Views; ... end # # All the applications will be available in Camping::Apps. def goes(m) Apps << eval(S.gsub(/Camping/,m.to_s), TOPLEVEL_BINDING) end - + # Ruby web servers use this method to enter the Camping realm. The +e+ # argument is the environment variables hash as per the Rack specification. # And array with [status, headers, body] is expected at the output. @@ -641,7 +641,7 @@ def method_missing(m, c, *a) h.each { |i, v| k.send("#{i}=", v) } k.service(*a) end - + # Injects a middleware: # # module Blog @@ -652,14 +652,14 @@ def use(*a, &b) m = a.shift.new(method(:call), *a, &b) meta_def(:call) { |e| m.call(e) } end - + # A hash where you can set different settings. def options O end - + # Shortcut for setting options: - # + # # module Blog # set :secret, "Hello!" # end @@ -667,7 +667,7 @@ def set(k, v) O[k] = v end end - + # Views is an empty module for storing methods which create HTML. The HTML # is described using the Markaby language. # @@ -679,7 +679,7 @@ def set(k, v) # def index # p "Welcome to my blog" # end - # + # # def show # h1 @post.title # self << @post.content @@ -704,7 +704,7 @@ def set(k, v) # end # end module Views; include X, Helpers end - + # Models is an empty Ruby module for housing model classes derived # from ActiveRecord::Base. As a shortcut, you may derive from Base # which is an alias for ActiveRecord::Base. @@ -733,7 +733,7 @@ module Views; include X, Helpers end module Models autoload :Base,'camping/ar' end - + autoload :Mab, 'camping/mab' autoload :Template, 'camping/template' C diff --git a/lib/camping/ar.rb b/lib/camping/ar.rb index ed08ac01..e2446771 100644 --- a/lib/camping/ar.rb +++ b/lib/camping/ar.rb @@ -56,7 +56,7 @@ def self.create_schema(opts = {}) # When you finally need a non-destructive table change adding a migration with a positive # number will run as expected, but will preclude further automatic table creation. :( def self.Base(opts={}, &block) - @final = -2 if @final.nil? + @final = -2 if @final.nil? v = V -1.0/(1+(@migrations ||= []).size) Class.new(Base) do @abstract_class = true @@ -64,7 +64,7 @@ def self.Base(opts={}, &block) meta_def(:inherited) do |model| # We only need a migration when our direct descendant comes to be. # when people use ActiveRecord's inheritence-to-put-subtypes-in-one-table - # feature, this function will get called on our direct descendant (because it + # feature, this function will get called on our direct descendant (because it # inherited this function). Since @V is a class-instance variable, we've # only set it in our magic Base-derivative. # diff --git a/lib/camping/mab.rb b/lib/camping/mab.rb index f873c8f3..e5f85d6c 100644 --- a/lib/camping/mab.rb +++ b/lib/camping/mab.rb @@ -12,7 +12,7 @@ class MissingLibrary < Exception #:nodoc: all # path. class Mab < Markaby::Builder attr_reader :builder - + include Views def tag!(*g,&b) h=g[-1] diff --git a/lib/camping/reloader.rb b/lib/camping/reloader.rb index b67a53bc..39b85459 100644 --- a/lib/camping/reloader.rb +++ b/lib/camping/reloader.rb @@ -33,13 +33,13 @@ module Camping # You can also give Reloader more than one script. class Reloader attr_reader :scripts, :apps - + # This class is doing all the hard work; however, it only works on # single files. Reloader just wraps up support for multiple scripts # and hides away some methods you normally won't need. class Script # :nodoc: attr_reader :apps, :file, :dir, :extras - + def initialize(file, callback = nil) @file = File.expand_path(file) @dir = File.dirname(@file) @@ -49,13 +49,13 @@ def initialize(file, callback = nil) @apps = {} @callback = callback end - + # Loads the apps availble in this script. Use apps to get # the loaded apps. def load_apps all_requires = $LOADED_FEATURES.dup all_apps = Camping::Apps.dup - + begin load(@file) rescue Exception => e @@ -64,31 +64,31 @@ def load_apps puts e.backtrace puts "!! Error loading #{@file}, see backtrace above" end - + @requires = ($LOADED_FEATURES - all_requires).map do |req| full = full_path(req) full if full == @file or full.index(@extras) == 0 end - + @mtime = mtime - + new_apps = (Camping::Apps - all_apps) old_apps = @apps.dup - + @apps = new_apps.inject({}) do |hash, app| key = app.name.to_sym hash[key] = app - + if !old_apps.include?(key) @callback.call(app) if @callback app.create if app.respond_to?(:create) end hash end - + self end - + # Removes all the apps defined in this script. def remove_apps @apps.each do |name, app| @@ -96,7 +96,7 @@ def remove_apps Object.send :remove_const, name end end - + # Reloads the file if needed. No harm is done by calling this multiple # times, so feel free call just to be sure. def reload! @@ -104,24 +104,24 @@ def reload! remove_apps load_apps end - + # Checks if both scripts watches the same file. def ==(other) @file == other.file end - + private - + def mtime (@requires + [@file]).compact.map do |fname| File.mtime(fname) end.reject{|t| t > Time.now }.max end - - # Figures out the full path of a required file. + + # Figures out the full path of a required file. def full_path(req) dir = $LOAD_PATH.detect { |l| File.exists?(File.join(l, req)) } - if dir + if dir File.join(File.expand_path(dir), req) else req @@ -137,42 +137,42 @@ def initialize(*scripts) @apps = {} update(*scripts) end - + def on_reload(&blk) @callback = blk end - + # Updates the reloader to only use the scripts provided: # # reloader.update("examples/blog.rb", "examples/wiki.rb") def update(*scripts) old_scripts = @scripts.dup clear - + @scripts = scripts.map do |script| file = File.expand_path(script) old_scripts.detect { |s| s.file == file } or Script.new(script, @callback) end - + reload! end - + # Removes all the scripts from the reloader. def clear @scripts = [] @apps = {} end - + # Returns the script which provided the given app. def script(app) @scripts.each do |script| return script if script.apps.values.include?(app) end - + false end - + # Simply calls reload! on all the Script objects. def reload! @apps = {} diff --git a/lib/camping/server.rb b/lib/camping/server.rb index 7445e473..c9c31ff5 100644 --- a/lib/camping/server.rb +++ b/lib/camping/server.rb @@ -7,7 +7,7 @@ # # Camping includes a pretty nifty server which is built for development. # It follows these rules: -# +# # * Load all Camping apps in a directory or a file. # * Load new apps that appear in that directory or that file. # * Mount those apps according to their name. (e.g. Blog is mounted at /blog.) @@ -36,39 +36,39 @@ class Options DB = nil RC = nil end - + HOME = File.expand_path(home) + '/' - + def parse!(args) args = args.dup options = {} - + opt_parser = OptionParser.new("", 24, ' ') do |opts| opts.banner = "Usage: camping app1.rb app2.rb..." opts.define_head "#{File.basename($0)}, the microframework ON-button for ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]" opts.separator "" opts.separator "Specific options:" - + opts.on("-h", "--host HOSTNAME", "Host for web server to bind to (default is all IPs)") { |v| options[:Host] = v } - + opts.on("-p", "--port NUM", "Port for web server (defaults to 3301)") { |v| options[:Port] = v } - + db = DB.sub(HOME, '~/') if DB opts.on("-d", "--database FILE", "SQLite3 database path (defaults to #{db ? db : ''})") { |db_path| options[:database] = db_path } - + opts.on("-C", "--console", "Run in console mode with IRB") { options[:server] = "console" } - + server_list = ["mongrel", "webrick", "console"] opts.on("-s", "--server NAME", "Server to force (#{server_list.join(', ')})") { |v| options[:server] = v } opts.separator "" opts.separator "Common options:" - + # No argument, shows at tail. This will print an options summary. # Try it and see! opts.on_tail("-?", "--help", "Show this message") do @@ -82,19 +82,19 @@ def parse!(args) exit end end - + opt_parser.parse!(args) - + if args.empty? puts opt_parser exit end - + options[:scripts] = args options end end - + def initialize(*) super @reloader = Camping::Reloader.new @@ -102,7 +102,7 @@ def initialize(*) if !app.options.has_key?(:dynamic_templates) app.options[:dynamic_templates] = true end - + if !Camping::Models.autoload?(:Base) && options[:database] Camping::Models::Base.establish_connection( :adapter => 'sqlite3', @@ -111,7 +111,7 @@ def initialize(*) end end end - + def opt_parser Options.new end @@ -122,7 +122,7 @@ def default_options :database => Options::DB }) end - + def middleware h = super h["development"].unshift [XSendfile] @@ -144,7 +144,7 @@ def start super end end - + def find_scripts scripts = options[:scripts].map do |path| if File.file?(path) @@ -153,18 +153,18 @@ def find_scripts Dir[File.join(path, '*.rb')] end end.flatten.compact - + @reloader.update(*scripts) end - + def reload! find_scripts end - + def app self end - + def call(env) reload! apps = @reloader.apps @@ -186,24 +186,24 @@ def call(env) return [200, {'Content-Type' => 'text/plain', 'X-Sendfile' => @reloader.script(app).file}, []] end end - + index_page(apps) end end - + def index_page(apps) [200, {'Content-Type' => 'text/html'}, [TEMPLATE.result(binding)]] end - + SOURCE = <<-HTML You are Camping