Changeset 942
- Timestamp:
- 11/10/07 22:32:55 (1 year ago)
- Files:
-
- apps/merki/trunk/app/models/page.rb (modified) (2 diffs)
- apps/merki/trunk/config/dependencies.rb (modified) (1 diff)
- apps/merki/trunk/config/router.rb (modified) (1 diff)
- apps/merki/trunk/spec/models/page_spec.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
apps/merki/trunk/app/models/page.rb
r938 r942 1 require 'cgi' 2 1 3 class Page < DataMapper::Base 2 4 ## props 3 5 property :title, :string 4 6 property :body, :text 7 property :converted_body, :text 5 8 6 9 ## relationships … … 8 11 # belongs_to :author, :class => 'User' 9 12 13 ## callbacks 14 before_save :parse 15 10 16 ## validations 11 17 validates_presence_of :title, :body 18 19 ## class methods 20 21 def self.find_by_slug(slug) 22 find_by_title(CGI.unescape(slug)) 23 end 24 25 26 ## instance methods 27 28 def parse(preprocessed_body = self.body) 29 ## TODO: parse for internal links 30 self.converted_body = RedCloth.new(preprocessed_body).to_html 31 end 32 33 ## Private 34 35 ## Protected 12 36 end 13 37 apps/merki/trunk/config/dependencies.rb
r931 r942 35 35 # dependencies "RedCloth" => "> 3.0", "ruby-aes-cext" => "= 1.0" 36 36 37 dependencies "RedCloth", "merb_helpers" 38 37 39 Merb::Server.after_app_loads do 38 40 ### Add dependencies here that must load after the application loads: apps/merki/trunk/config/router.rb
r930 r942 22 22 puts "Compiling routes.." 23 23 Merb::Router.prepare do |r| 24 # RESTful routes 25 # r.resources :posts 24 r.resources :pages 26 25 27 # Default route, usually you don't want to change this 28 r.default_routes 29 30 # Change this for your home page to be available at / 31 # r.match('/').to(:controller => 'whatever', :action =>'index') 26 r.match('/').to(:controller => 'pages', :action =>'index') 32 27 end apps/merki/trunk/spec/models/page_spec.rb
r941 r942 74 74 75 75 it "should have a converted_body" do 76 pending "Needs implementation"77 76 @page.converted_body = "converted to textile" 78 77 @page.converted_body.should == "converted to textile" … … 80 79 81 80 it "should use textile to convert body to converted_body" do 82 pending "Needs implementation"83 81 @page.body = textile_text 82 @page.parse 84 83 @page.converted_body.should == textile_text_as_html 85 84 end … … 99 98 end 100 99 100 it "should return body as to_text" do 101 pending "Needs implementation" 102 @page.body = lorem_text 103 @page.to_text.should == lorem_text 104 end 105 101 106 it "should be valid with all attributes" do 102 107 @page.attributes = valid_page_attributes … … 113 118 114 119 it "should be able to find Pages by URL slug" do 115 pending "incomplete"116 120 page = mock("Page") 117 121 Page.should_receive(:find_by_title).with("Sample Page").once.
