All Page to be passed in a :body attribute
This :body attribute will then be used when creating the default body PagePart
This commit is contained in:
parent
36ab2f0066
commit
925c7fff8d
@ -6,9 +6,11 @@ module Models
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
before_validation do |p|
|
||||||
before_create { |p| p.parts << PagePart.build_body_part if p.parts.empty? }
|
if p.parts.empty?
|
||||||
|
p.parts << PagePart.build_body_part(p.try(:body))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
|
@ -24,10 +24,10 @@ class PagePart
|
|||||||
"{% capture content_for_#{self.slug} %}#{self.value}{% endcapture %}"
|
"{% capture content_for_#{self.slug} %}#{self.value}{% endcapture %}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build_body_part
|
def self.build_body_part(body_content = nil)
|
||||||
self.new({
|
self.new({
|
||||||
:name => I18n.t('attributes.defaults.page_parts.name'),
|
:name => I18n.t('attributes.defaults.page_parts.name'),
|
||||||
:value => I18n.t('attributes.defaults.pages.other.body'),
|
:value => body_content || I18n.t('attributes.defaults.pages.other.body'),
|
||||||
:slug => 'layout'
|
:slug => 'layout'
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -334,6 +334,32 @@ describe Page do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe "creating a new page" do
|
||||||
|
|
||||||
|
context "with a body" do
|
||||||
|
before do
|
||||||
|
@site = Factory(:site, :subdomain => "somethingweird")
|
||||||
|
@page = Page.create({
|
||||||
|
:slug => "some_slug",
|
||||||
|
:title => "Page Title",
|
||||||
|
:body => "Page Body",
|
||||||
|
:published => true,
|
||||||
|
:site => @site
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be valid" do
|
||||||
|
@page.should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should render the passed in body attribute of the page" do
|
||||||
|
@page.render(Liquid::Context.new).should == "PageBody"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
describe 'templatized extension' do
|
describe 'templatized extension' do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
Loading…
Reference in New Issue
Block a user