forked from refinery/refinerycms
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ContentPage into ContentPagePresenter and ContentPresenter
- Loading branch information
1 parent
6643c6d
commit 498d45e
Showing
5 changed files
with
88 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Refinery | ||
module Pages | ||
class ContentPagePresenter < ContentPresenter | ||
def self.build_for_page(page, page_title) | ||
self.new(page, page_title) | ||
end | ||
|
||
def initialize(page, page_title) | ||
super() | ||
add_default_title_section(page_title) if page_title.present? | ||
add_page_parts(page.parts) if page | ||
add_default_post_page_sections | ||
end | ||
|
||
private | ||
|
||
def add_default_title_section(title) | ||
add_section SectionPresenter.new(:id => :body_content_title, :fallback_html => title, :title => true) | ||
end | ||
|
||
def add_default_post_page_sections | ||
add_section_if_missing(:id => :body_content_left) | ||
add_section_if_missing(:id => :body_content_right) | ||
end | ||
|
||
def add_page_parts(parts) | ||
parts.each do |part| | ||
add_section SectionPresenter.from_page_part(part) | ||
end | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "spec_helper" | ||
|
||
module Refinery | ||
module Pages | ||
describe ContentPagePresenter do | ||
let(:part) { double(PagePart, :body => 'part_body', :title => 'A Wonderful Page Part') } | ||
let(:part2) { double(PagePart, :body => 'part_body2', :title => 'Another Wonderful Page Part') } | ||
let(:title) { 'This Great Page' } | ||
|
||
describe "when building for page" do | ||
let(:page_with_one_part) { double(Page, :parts => [part]) } | ||
|
||
it "adds page title section before page parts" do | ||
content = ContentPagePresenter.build_for_page(page_with_one_part, title) | ||
content.get_section(0).fallback_html.should == title | ||
end | ||
|
||
it "adds a section for each page part" do | ||
page = double(Page, :parts => [part, part2]) | ||
content = ContentPagePresenter.build_for_page(page, title) | ||
content.get_section(1).fallback_html.should == 'part_body' | ||
content.get_section(2).fallback_html.should == 'part_body2' | ||
end | ||
|
||
it "adds body content left and right after page parts" do | ||
content = ContentPagePresenter.build_for_page(page_with_one_part, title) | ||
content.get_section(2).id.should == :body_content_left | ||
content.get_section(3).id.should == :body_content_right | ||
end | ||
|
||
it "doesnt add page parts if page is nil" do | ||
content = ContentPagePresenter.build_for_page(nil, title) | ||
content.get_section(1).id.should == :body_content_left | ||
end | ||
|
||
it "doesnt add title if it is blank" do | ||
content = ContentPagePresenter.build_for_page(nil, '') | ||
content.get_section(0).id.should == :body_content_left | ||
end | ||
end | ||
end | ||
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