Changeset 146
- Timestamp:
- 08/15/2006 13:33:54 (2 years ago)
- Location:
- trunk
- Files:
-
- 6 modified
-
Rakefile (modified) (1 diff)
-
examples/README (modified) (1 diff)
-
examples/blog.rb (modified) (2 diffs)
-
examples/campsh.rb (modified) (4 diffs)
-
examples/tepee.rb (modified) (3 diffs)
-
lib/camping/db.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Rakefile
r134 r146 8 8 NAME = "camping" 9 9 REV = File.read(".svn/entries")[/committed-rev="(\d+)"/, 1] rescue nil 10 VERS = "1.4" + (REV ? ".#{REV}" : "")10 VERS = ENV['VERSION'] || ("1.4" + (REV ? ".#{REV}" : "")) 11 11 CLEAN.include ['**/.*.sw?', '*.gem', '.config'] 12 12 RDOC_OPTS = ['--quiet', '--title', "Camping, the Documentation", -
trunk/examples/README
r113 r146 2 2 3 3 From this directory, run: `camping .` 4 5 NOTE: You'll need the active_record and acts_as_versioned gems installed. -
trunk/examples/blog.rb
r134 r146 13 13 14 14 module Blog::Models 15 def self.schema(&block)16 @@schema = block if block_given?17 @@schema18 end19 20 15 class Post < Base; belongs_to :user; end 21 16 class Comment < Base; belongs_to :user; end 22 17 class User < Base; end 23 end 24 25 Blog::Models.schema do 26 create_table :blog_posts, :force => true do |t| 27 t.column :id, :integer, :null => false 28 t.column :user_id, :integer, :null => false 29 t.column :title, :string, :limit => 255 30 t.column :body, :text 31 end 32 create_table :blog_users, :force => true do |t| 33 t.column :id, :integer, :null => false 34 t.column :username, :string 35 t.column :password, :string 36 end 37 create_table :blog_comments, :force => true do |t| 38 t.column :id, :integer, :null => false 39 t.column :post_id, :integer, :null => false 40 t.column :username, :string 41 t.column :body, :text 42 end 43 execute "INSERT INTO blog_users (username, password) VALUES ('admin', 'camping')" 18 19 class CreateTheBasics < V 1.0 20 def self.up 21 create_table :blog_posts, :force => true do |t| 22 t.column :id, :integer, :null => false 23 t.column :user_id, :integer, :null => false 24 t.column :title, :string, :limit => 255 25 t.column :body, :text 26 end 27 create_table :blog_users, :force => true do |t| 28 t.column :id, :integer, :null => false 29 t.column :username, :string 30 t.column :password, :string 31 end 32 create_table :blog_comments, :force => true do |t| 33 t.column :id, :integer, :null => false 34 t.column :post_id, :integer, :null => false 35 t.column :username, :string 36 t.column :body, :text 37 end 38 User.create :username => 'admin', :password => 'camping' 39 end 40 def self.down 41 drop_table :blog_posts 42 drop_table :blog_users 43 drop_table :blog_comments 44 end 45 end 44 46 end 45 47 … … 267 269 def Blog.create 268 270 Camping::Models::Session.create_schema 269 unless Blog::Models::Post.table_exists? 270 ActiveRecord::Schema.define(&Blog::Models.schema) 271 end 271 Blog::Models.create_schema :assume => (Blog::Models::Post.table_exists? ? 1.0 : 0.0) 272 272 end 273 273 -
trunk/examples/campsh.rb
r112 r146 23 23 24 24 def self.create 25 unless CampSh::Models::Command.table_exists? 26 ActiveRecord::Schema.define do 27 create_table :campsh_commands, :force => true do |t| 28 t.column :id, :integer, :null => false 29 t.column :author, :string, :limit => 40 30 t.column :name, :string, :limit => 255 31 t.column :created_at, :datetime 32 t.column :doc, :text 33 t.column :code, :text 34 end 35 CampSh::Models::Command.create_versioned_table 36 end 37 end 25 Models.create_schema :assume => (Models::Command.table_exists? ? 1.0 : 0.0) 38 26 end 39 27 end … … 44 32 validates_presence_of :author 45 33 acts_as_versioned 34 end 35 class CreateBasics < V 1.0 36 def self.up 37 create_table :campsh_commands, :force => true do |t| 38 t.column :id, :integer, :null => false 39 t.column :author, :string, :limit => 40 40 t.column :name, :string, :limit => 255 41 t.column :created_at, :datetime 42 t.column :doc, :text 43 t.column :code, :text 44 end 45 Command.create_versioned_table 46 Command.reset_column_information 47 end 48 def self.down 49 drop_table :campsh_commands 50 Command.drop_versioned_table 51 end 46 52 end 47 53 end … … 128 134 @cmd = @cmd.versions.find_by_version(version) unless version.nil? or version == @cmd.version.to_s 129 135 @title = "Editing #{name}" 130 @author = cookies.cmd_author orCampSh::ANON136 @author = @cookies.cmd_author || CampSh::ANON 131 137 render :edit 132 138 end 133 139 def post(name) 134 if input.author != CampSh::ANON 135 cookies.cmd_author = input.author 136 end 140 @cookies.cmd_author = input.command.author 137 141 Command.find_or_create_by_name(name).update_attributes(input.command) 138 142 redirect Show, name … … 560 564 :class => "navlink", :accesskey => "E" 561 565 unless @version.version == 1 566 text " | " 562 567 a 'Back in time', :href => R(Show, @version.name, @version.version-1) 563 568 end 564 569 unless @version.version == @cmd.version 570 text " | " 565 571 a 'Next', :href => R(Show, @version.name, @version.version+1) 572 text " | " 566 573 a 'Current', :href => R(Show, @version.name) 567 574 end 568 small "(#{ @cmd.version.size } revisions)" 575 if @cmd.versions.size > 1 576 small "(#{ @cmd.versions.size } revisions)" 577 end 569 578 end 570 579 end -
trunk/examples/tepee.rb
r121 r146 6 6 7 7 module Tepee::Models 8 def self.schema(&block) 9 @@schema = block if block_given? 10 @@schema 11 end 12 8 13 9 class Page < Base 14 10 PAGE_LINK = /\[\[([^\]|]*)[|]?([^\]]*)\]\]/ … … 17 13 acts_as_versioned 18 14 end 19 end20 15 21 Tepee::Models.schema do 22 create_table :tepee_pages, :force => true do |t| 23 t.column :title, :string, :limit => 255 24 t.column :body, :text 16 class CreateTepee < V 1.0 17 def self.up 18 create_table :tepee_pages, :force => true do |t| 19 t.column :title, :string, :limit => 255 20 t.column :body, :text 21 end 22 Page.create_versioned_table 23 Page.reset_column_information 24 end 25 def self.down 26 drop_table :tepee_pages 27 Page.drop_versioned_table 28 end 25 29 end 26 Tepee::Models::Page.create_versioned_table 30 27 31 end 28 32 … … 130 134 131 135 def Tepee.create 132 unless Tepee::Models::Page.table_exists? 133 ActiveRecord::Schema.define(&Tepee::Models.schema) 134 Tepee::Models::Page.reset_column_information 135 end 136 Tepee::Models.create_schema :assume => (Tepee::Models::Page.table_exists? ? 1.0 : 0.0) 136 137 end 137 138 -
trunk/lib/camping/db.rb
r145 r146 25 25 end 26 26 27 def self.create_schema 27 def self.create_schema(opts = {}) 28 opts[:assume] ||= 0 29 opts[:version] ||= @final 28 30 if @migrations 29 31 unless SchemaInfo.table_exists? … … 35 37 end 36 38 37 si = SchemaInfo.find(:first) || SchemaInfo.new(:version => 0)39 si = SchemaInfo.find(:first) || SchemaInfo.new(:version => opts[:assume]) 38 40 @migrations.each do |k| 39 41 k.migrate(:up) if si.version < k.version 40 42 end 41 si.update_attributes(:version => @final)43 si.update_attributes(:version => opts[:version]) 42 44 end 43 45 end
