Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
32 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
class Chapter < ActiveRecord::Base | ||
|
||
has_many :sections | ||
use_permalink :title | ||
|
||
def ordinal | ||
number ? "#{number}." : number | ||
end | ||
|
||
def to_param | ||
"#{number}_#{slug}" | ||
end | ||
|
||
def slug | ||
return '' if title.blank? | ||
slug = title.downcase.gsub(/\s/, '_') | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
class Section < ActiveRecord::Base | ||
|
||
belongs_to :chapter | ||
use_permalink :title | ||
|
||
def ordinal | ||
number ? "#{number}." : number | ||
end | ||
|
||
def to_param | ||
"#{slug}" | ||
end | ||
|
||
def slug | ||
return '' if title.blank? | ||
slug = title.downcase.gsub(/\s/, '_') | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
%h2 | ||
= "#{@chapter.number} – #{@chapter.title}" | ||
#book_content | ||
= @chapter.body | ||
~ @chapter.body | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
#book | ||
%h2= @section.title | ||
#book_content | ||
= @section.body | ||
~ @section.body | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AddPermalink < ActiveRecord::Migration | ||
def self.up | ||
add_column :chapters, :permalink, :string | ||
add_column :sections, :permalink, :string | ||
end | ||
|
||
def self.down | ||
remove_column :sections, :permalink | ||
remove_column :chapters, :permalink | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,2 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
|
||
describe Chapter do | ||
before(:each) do | ||
@chapter = Chapter.new(:number => '2') | ||
end | ||
|
||
it "should have to_param method that returns chapter number" do | ||
@chapter.to_param.should == "2_" | ||
end | ||
it "should convert title to slug" do | ||
@chapter.slug.should_not be_nil | ||
end | ||
|
||
end | ||
|
||
describe Chapter, "slug" do | ||
before(:each) do | ||
@chapter = Chapter.new(:number => '2', :title => "Einführung ins Testen") | ||
end | ||
|
||
it "should convert title to slug" do | ||
@chapter.slug.should_not be_nil | ||
end | ||
|
||
it "should convert spaces to _" do | ||
@chapter.slug.should == "einführung_ins_testen" | ||
end | ||
|
||
end |