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.
Moved ruby code from _content_page template into helper methods (with…
… specs). Also added some comments to the newly introduced classes.
- Loading branch information
1 parent
e865d86
commit 49b741a
Showing
11 changed files
with
122 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,2 @@ | ||
<% | ||
# supported variables for this partial and their default values | ||
sections_to_hide = local_assigns[:hide_sections] || [] | ||
content_page = local_assigns[:sections] | ||
allowed_to_use_fallback = !local_assigns[:show_empty_sections] && !local_assigns[:remove_automatic_sections] | ||
|
||
if content_page | ||
if !content_page.is_a?(Refinery::Pages::ContentPagePresenter) | ||
raise ArgumentError.new("Sections passed to the content page partial must be Refinery::Pages::SectionPresenter objects inside a Refinery::Pages::ContentPagePresenter") | ||
end | ||
else | ||
content_page = Refinery::Pages::ContentPagePresenter.new(@page, page_title) | ||
end | ||
|
||
content_page.hide_sections(sections_to_hide) | ||
content_page.fetch_template_overrides {|section_id| content_for(section_id)} | ||
-%> | ||
<section id='body_content' class='<%= content_page.blank_section_css_classes(allowed_to_use_fallback).join(' ') %>'> | ||
<%= content_page.to_html(allowed_to_use_fallback) -%> | ||
</section> | ||
<%= render_content_page(@page, {:hide_sections => local_assigns[:hide_sections], :can_use_fallback => !local_assigns[:show_empty_sections] && !local_assigns[:remove_automatic_sections]}) %> | ||
<%= render :partial => '/refinery/draft_page_message' unless @page.nil? or @page.live? -%> |
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,26 @@ | ||
module ::Refinery | ||
module Pages | ||
module ContentPagesHelper | ||
# Build the html for a Refinery CMS page object by creating a ContentPagePresenter. This is a | ||
# specialised type of ContentPresenter, so the object is then passed to render_content_presenter | ||
# to get it's html. The options are passed to that method, so see render_content_presenter for | ||
# more details. | ||
def render_content_page(page, options = {}) | ||
content_page_presenter = Refinery::Pages::ContentPagePresenter.new(page, page_title) | ||
render_content_presenter(content_page_presenter, options) | ||
end | ||
|
||
# Pass the options into a ContentPresenter object and return it's html. For more | ||
# details see Refinery::Pages::ContentPresenter (and it's subclasses). | ||
# This method also checks for template overrides. Any template rendered by the | ||
# current action may specify content_for a section using the section's id. For this | ||
# reason, sections should not have an ID which you would normally be using for content_for, | ||
# so avoid common layout names such as :header, :footer, etc. | ||
def render_content_presenter(content_page, options = {}) | ||
content_page.hide_sections(options[:hide_sections]) if options[:hide_sections] | ||
content_page.fetch_template_overrides {|section_id| content_for(section_id)} | ||
content_page.to_html(options[:can_use_fallback]) | ||
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
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,14 +1,14 @@ | ||
module Refinery | ||
module Pages | ||
# A type of SectionPresenter which knows how to render a section which displays | ||
# a title. These are much like normal sections except they are wrapped in | ||
# a h1 tag rather than a div. | ||
class TitleSectionPresenter < SectionPresenter | ||
|
||
private | ||
|
||
def wrap_content_in_tag(content) | ||
content_tag(:h1, content, :id => id) | ||
end | ||
|
||
|
||
end | ||
end | ||
end |
44 changes: 44 additions & 0 deletions
44
pages/spec/helpers/refinery/pages/content_pages_helper_spec.rb
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,44 @@ | ||
require 'spec_helper' | ||
|
||
module Refinery | ||
module Pages | ||
describe ContentPagesHelper do | ||
let(:content_presenter) { double(ContentPresenter, :hide_sections => nil, :fetch_template_overrides => nil, :to_html => nil) } | ||
|
||
describe "when rendering content presenter" do | ||
it "asks to content presenter to hide sections if told to" do | ||
content_presenter.should_receive(:hide_sections).with(['foo', 'bar']) | ||
render_content_presenter(content_presenter, :hide_sections => ['foo', 'bar']) | ||
end | ||
|
||
it "attempts to fetch template overrides declared elsewhere via content_for" do | ||
content_presenter.should_receive(:fetch_template_overrides).and_yield(12) | ||
self.should_receive(:content_for).with(12) | ||
render_content_presenter(content_presenter) | ||
end | ||
|
||
it "outputs the html rendered by the content presenter" do | ||
content_presenter.should_receive(:to_html).and_return('foobar') | ||
render_content_presenter(content_presenter).should == 'foobar' | ||
end | ||
|
||
it "passes can_use_fallback option through to html rendering" do | ||
content_presenter.should_receive(:to_html).with(true) | ||
render_content_presenter(content_presenter, :can_use_fallback => true) | ||
end | ||
end | ||
|
||
describe "when rendering page" do | ||
let(:page) { double(Page) } | ||
|
||
it "builds a content page presenter and returns its html" do | ||
self.should_receive(:page_title).and_return('some title') | ||
Refinery::Pages::ContentPagePresenter.should_receive(:new).with(page, 'some title').and_return(content_presenter) | ||
content_presenter.should_receive(:to_html).and_return('barfoo') | ||
|
||
render_content_page(page).should == 'barfoo' | ||
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