templatized pages can have now sub pages
This commit is contained in:
parent
a8d57794de
commit
ed15c0d6b5
82
Gemfile.lock
82
Gemfile.lock
@ -66,14 +66,14 @@ GEM
|
|||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
RedCloth (4.2.9)
|
RedCloth (4.2.9)
|
||||||
actionmailer (3.2.1)
|
actionmailer (3.2.2)
|
||||||
actionpack (= 3.2.1)
|
actionpack (= 3.2.2)
|
||||||
mail (~> 2.4.0)
|
mail (~> 2.4.0)
|
||||||
actionmailer-with-request (0.3.0)
|
actionmailer-with-request (0.3.0)
|
||||||
rails (>= 3)
|
rails (>= 3)
|
||||||
actionpack (3.2.1)
|
actionpack (3.2.2)
|
||||||
activemodel (= 3.2.1)
|
activemodel (= 3.2.2)
|
||||||
activesupport (= 3.2.1)
|
activesupport (= 3.2.2)
|
||||||
builder (~> 3.0.0)
|
builder (~> 3.0.0)
|
||||||
erubis (~> 2.7.0)
|
erubis (~> 2.7.0)
|
||||||
journey (~> 1.0.1)
|
journey (~> 1.0.1)
|
||||||
@ -81,18 +81,18 @@ GEM
|
|||||||
rack-cache (~> 1.1)
|
rack-cache (~> 1.1)
|
||||||
rack-test (~> 0.6.1)
|
rack-test (~> 0.6.1)
|
||||||
sprockets (~> 2.1.2)
|
sprockets (~> 2.1.2)
|
||||||
activemodel (3.2.1)
|
activemodel (3.2.2)
|
||||||
activesupport (= 3.2.1)
|
activesupport (= 3.2.2)
|
||||||
builder (~> 3.0.0)
|
builder (~> 3.0.0)
|
||||||
activerecord (3.2.1)
|
activerecord (3.2.2)
|
||||||
activemodel (= 3.2.1)
|
activemodel (= 3.2.2)
|
||||||
activesupport (= 3.2.1)
|
activesupport (= 3.2.2)
|
||||||
arel (~> 3.0.0)
|
arel (~> 3.0.2)
|
||||||
tzinfo (~> 0.3.29)
|
tzinfo (~> 0.3.29)
|
||||||
activeresource (3.2.1)
|
activeresource (3.2.2)
|
||||||
activemodel (= 3.2.1)
|
activemodel (= 3.2.2)
|
||||||
activesupport (= 3.2.1)
|
activesupport (= 3.2.2)
|
||||||
activesupport (3.2.1)
|
activesupport (3.2.2)
|
||||||
i18n (~> 0.6)
|
i18n (~> 0.6)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
addressable (2.2.7)
|
addressable (2.2.7)
|
||||||
@ -115,7 +115,7 @@ GEM
|
|||||||
carrierwave-mongoid (0.1.3)
|
carrierwave-mongoid (0.1.3)
|
||||||
carrierwave (>= 0.5.6)
|
carrierwave (>= 0.5.6)
|
||||||
mongoid (~> 2.1)
|
mongoid (~> 2.1)
|
||||||
cells (3.8.2)
|
cells (3.8.3)
|
||||||
actionpack (~> 3.0)
|
actionpack (~> 3.0)
|
||||||
railties (~> 3.0)
|
railties (~> 3.0)
|
||||||
childprocess (0.3.1)
|
childprocess (0.3.1)
|
||||||
@ -140,7 +140,7 @@ GEM
|
|||||||
capybara (>= 1.1.2)
|
capybara (>= 1.1.2)
|
||||||
cucumber (>= 1.1.8)
|
cucumber (>= 1.1.8)
|
||||||
nokogiri (>= 1.5.0)
|
nokogiri (>= 1.5.0)
|
||||||
database_cleaner (0.7.1)
|
database_cleaner (0.7.2)
|
||||||
devise (1.5.3)
|
devise (1.5.3)
|
||||||
bcrypt-ruby (~> 3.0)
|
bcrypt-ruby (~> 3.0)
|
||||||
orm_adapter (~> 0.0.3)
|
orm_adapter (~> 0.0.3)
|
||||||
@ -175,7 +175,7 @@ GEM
|
|||||||
formtastic (2.0.2)
|
formtastic (2.0.2)
|
||||||
rails (~> 3.0)
|
rails (~> 3.0)
|
||||||
fssm (0.2.8.1)
|
fssm (0.2.8.1)
|
||||||
gherkin (2.9.0)
|
gherkin (2.9.1)
|
||||||
json (>= 1.4.6)
|
json (>= 1.4.6)
|
||||||
haml (3.1.4)
|
haml (3.1.4)
|
||||||
highline (1.6.11)
|
highline (1.6.11)
|
||||||
@ -193,8 +193,8 @@ GEM
|
|||||||
actionpack (>= 3.0.0)
|
actionpack (>= 3.0.0)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
railties (>= 3.0.0)
|
railties (>= 3.0.0)
|
||||||
kgio (2.7.2)
|
kgio (2.7.4)
|
||||||
launchy (2.0.5)
|
launchy (2.1.0)
|
||||||
addressable (~> 2.2.6)
|
addressable (~> 2.2.6)
|
||||||
locomotive-aloha-rails (0.20.1.1)
|
locomotive-aloha-rails (0.20.1.1)
|
||||||
actionpack (~> 3.2.1)
|
actionpack (~> 3.2.1)
|
||||||
@ -203,16 +203,16 @@ GEM
|
|||||||
locomotive-tinymce-rails (3.4.7.1)
|
locomotive-tinymce-rails (3.4.7.1)
|
||||||
actionpack (~> 3.2.1)
|
actionpack (~> 3.2.1)
|
||||||
locomotive_liquid (2.2.2)
|
locomotive_liquid (2.2.2)
|
||||||
mail (2.4.1)
|
mail (2.4.4)
|
||||||
i18n (>= 0.4.0)
|
i18n (>= 0.4.0)
|
||||||
mime-types (~> 1.16)
|
mime-types (~> 1.16)
|
||||||
treetop (~> 1.4.8)
|
treetop (~> 1.4.8)
|
||||||
mime-types (1.17.2)
|
mime-types (1.18)
|
||||||
mimetype-fu (0.1.2)
|
mimetype-fu (0.1.2)
|
||||||
mocha (0.9.12)
|
mocha (0.9.12)
|
||||||
mongo (1.5.2)
|
mongo (1.5.2)
|
||||||
bson (= 1.5.2)
|
bson (= 1.5.2)
|
||||||
mongoid (2.4.6)
|
mongoid (2.4.7)
|
||||||
activemodel (~> 3.1)
|
activemodel (~> 3.1)
|
||||||
mongo (~> 1.3)
|
mongo (~> 1.3)
|
||||||
tzinfo (~> 0.3.22)
|
tzinfo (~> 0.3.22)
|
||||||
@ -221,34 +221,34 @@ GEM
|
|||||||
net-scp (1.0.4)
|
net-scp (1.0.4)
|
||||||
net-ssh (>= 1.99.1)
|
net-ssh (>= 1.99.1)
|
||||||
net-ssh (2.3.0)
|
net-ssh (2.3.0)
|
||||||
nokogiri (1.5.0)
|
nokogiri (1.5.2)
|
||||||
orm_adapter (0.0.6)
|
orm_adapter (0.0.7)
|
||||||
pickle (0.4.10)
|
pickle (0.4.10)
|
||||||
cucumber (>= 0.8)
|
cucumber (>= 0.8)
|
||||||
rake
|
rake
|
||||||
polyglot (0.3.3)
|
polyglot (0.3.3)
|
||||||
rack (1.4.1)
|
rack (1.4.1)
|
||||||
rack-cache (1.1)
|
rack-cache (1.2)
|
||||||
rack (>= 0.4)
|
rack (>= 0.4)
|
||||||
rack-ssl (1.3.2)
|
rack-ssl (1.3.2)
|
||||||
rack
|
rack
|
||||||
rack-test (0.6.1)
|
rack-test (0.6.1)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
rails (3.2.1)
|
rails (3.2.2)
|
||||||
actionmailer (= 3.2.1)
|
actionmailer (= 3.2.2)
|
||||||
actionpack (= 3.2.1)
|
actionpack (= 3.2.2)
|
||||||
activerecord (= 3.2.1)
|
activerecord (= 3.2.2)
|
||||||
activeresource (= 3.2.1)
|
activeresource (= 3.2.2)
|
||||||
activesupport (= 3.2.1)
|
activesupport (= 3.2.2)
|
||||||
bundler (~> 1.0)
|
bundler (~> 1.0)
|
||||||
railties (= 3.2.1)
|
railties (= 3.2.2)
|
||||||
rails-backbone (0.6.1)
|
rails-backbone (0.6.1)
|
||||||
coffee-script (~> 2.2.0)
|
coffee-script (~> 2.2.0)
|
||||||
ejs (~> 1.0.0)
|
ejs (~> 1.0.0)
|
||||||
railties (>= 3.1.0)
|
railties (>= 3.1.0)
|
||||||
railties (3.2.1)
|
railties (3.2.2)
|
||||||
actionpack (= 3.2.1)
|
actionpack (= 3.2.2)
|
||||||
activesupport (= 3.2.1)
|
activesupport (= 3.2.2)
|
||||||
rack-ssl (~> 1.3.2)
|
rack-ssl (~> 1.3.2)
|
||||||
rake (>= 0.8.7)
|
rake (>= 0.8.7)
|
||||||
rdoc (~> 3.4)
|
rdoc (~> 3.4)
|
||||||
@ -281,14 +281,14 @@ GEM
|
|||||||
sanitize (2.0.3)
|
sanitize (2.0.3)
|
||||||
nokogiri (>= 1.4.4, < 1.6)
|
nokogiri (>= 1.4.4, < 1.6)
|
||||||
sass (3.1.15)
|
sass (3.1.15)
|
||||||
sass-rails (3.2.4)
|
sass-rails (3.2.5)
|
||||||
railties (~> 3.2.0)
|
railties (~> 3.2.0)
|
||||||
sass (>= 3.1.10)
|
sass (>= 3.1.10)
|
||||||
tilt (~> 1.3)
|
tilt (~> 1.3)
|
||||||
selenium-webdriver (2.19.0)
|
selenium-webdriver (2.20.0)
|
||||||
childprocess (>= 0.2.5)
|
childprocess (>= 0.2.5)
|
||||||
ffi (~> 1.0.9)
|
ffi (~> 1.0)
|
||||||
multi_json (~> 1.0.4)
|
multi_json (~> 1.0)
|
||||||
rubyzip
|
rubyzip
|
||||||
shoulda-matchers (1.0.0)
|
shoulda-matchers (1.0.0)
|
||||||
sprockets (2.1.2)
|
sprockets (2.1.2)
|
||||||
@ -301,7 +301,7 @@ GEM
|
|||||||
treetop (1.4.10)
|
treetop (1.4.10)
|
||||||
polyglot
|
polyglot
|
||||||
polyglot (>= 0.3.1)
|
polyglot (>= 0.3.1)
|
||||||
tzinfo (0.3.31)
|
tzinfo (0.3.32)
|
||||||
uglifier (1.2.3)
|
uglifier (1.2.3)
|
||||||
execjs (>= 0.3.0)
|
execjs (>= 0.3.0)
|
||||||
multi_json (>= 1.0.2)
|
multi_json (>= 1.0.2)
|
||||||
|
@ -3,10 +3,89 @@ module Locomotive
|
|||||||
module Page
|
module Page
|
||||||
module Render
|
module Render
|
||||||
|
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
self.template.render(context)
|
self.template.render(context)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
|
||||||
|
# Given both a site and a path, this method tries
|
||||||
|
# to get the matching page.
|
||||||
|
# If the page is templatized, the related content entry is
|
||||||
|
# associated to the page (page.content_entry stores the entry).
|
||||||
|
# If no page is found, then it returns the 404 one instead.
|
||||||
|
#
|
||||||
|
# @param [ Site ] site The site where to find the page
|
||||||
|
# @param [ String ] path The fullpath got from the request
|
||||||
|
# @param [ Boolean ] logged_in True if someone is logged in Locomotive
|
||||||
|
#
|
||||||
|
# @return [ Page ] The page matching the criteria OR the 404 one if none
|
||||||
|
#
|
||||||
|
def fetch_page_from_path(site, path, logged_in)
|
||||||
|
page = nil
|
||||||
|
|
||||||
|
matching_paths = path == 'index' ? %w(index) : path_combinations(path)
|
||||||
|
|
||||||
|
site.pages.any_in(:fullpath => matching_paths).each do |_page|
|
||||||
|
if !_page.published? && !logged_in
|
||||||
|
next
|
||||||
|
else
|
||||||
|
if _page.templatized?
|
||||||
|
%r(^#{_page.fullpath.gsub('content_type_template', '([^\/]+)')}$) =~ path
|
||||||
|
|
||||||
|
permalink = $1
|
||||||
|
|
||||||
|
_page.content_entry = _page.fetch_target_entry(permalink)
|
||||||
|
|
||||||
|
if _page.content_entry.nil? || (!_page.content_entry.visible? && !logged_in) # content instance not found or not visible
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
page = _page
|
||||||
|
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
page || site.pages.not_found.published.first
|
||||||
|
end
|
||||||
|
|
||||||
|
# Calculate all the combinations possible based on the
|
||||||
|
# fact that one of the segment of the path could be
|
||||||
|
# a content type from a templatized page.
|
||||||
|
# We postulate that there is only one templatized page in a path
|
||||||
|
# (ie: no nested templatized pages)
|
||||||
|
#
|
||||||
|
# @param [ String ] path The path to the page
|
||||||
|
#
|
||||||
|
# @return [ Array ] An array of all the combinations
|
||||||
|
#
|
||||||
|
def path_combinations(path)
|
||||||
|
_path_combinations(path.split('/'))
|
||||||
|
end
|
||||||
|
|
||||||
|
#:nodoc:
|
||||||
|
def _path_combinations(segments, can_include_template = true)
|
||||||
|
return nil if segments.empty?
|
||||||
|
|
||||||
|
segment = segments.shift
|
||||||
|
|
||||||
|
(can_include_template ? [segment, 'content_type_template'] : [segment]).map do |_segment|
|
||||||
|
if (_combinations = _path_combinations(segments.clone, can_include_template && _segment != 'content_type_template'))
|
||||||
|
[*_combinations].map do |_combination|
|
||||||
|
File.join(_segment, _combination)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
[_segment]
|
||||||
|
end
|
||||||
|
end.flatten
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,6 +20,9 @@ module Locomotive
|
|||||||
|
|
||||||
## scopes ##
|
## scopes ##
|
||||||
scope :templatized, :where => { :templatized => true }
|
scope :templatized, :where => { :templatized => true }
|
||||||
|
|
||||||
|
## virtual attributes ##
|
||||||
|
attr_accessor :content_entry
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the class specified by the target_klass_name property
|
# Returns the class specified by the target_klass_name property
|
||||||
|
@ -38,6 +38,10 @@ module Locomotive
|
|||||||
Page.quick_tree(self)
|
Page.quick_tree(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_page(path, logged_in)
|
||||||
|
Locomotive::Page.fetch_page_from_path self, path, logged_in
|
||||||
|
end
|
||||||
|
|
||||||
def accounts
|
def accounts
|
||||||
Account.criteria.in(:_id => self.memberships.map(&:account_id))
|
Account.criteria.in(:_id => self.memberships.map(&:account_id))
|
||||||
end
|
end
|
||||||
|
@ -26,28 +26,7 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
|
|
||||||
def locomotive_page
|
def locomotive_page
|
||||||
page = nil
|
current_site.fetch_page self.locomotive_page_path, current_locomotive_account.present?
|
||||||
path = self.locomotive_page_path
|
|
||||||
|
|
||||||
current_site.pages.any_in(:fullpath => [*path]).each do |_page|
|
|
||||||
if not _page.published? and current_locomotive_account.nil?
|
|
||||||
next
|
|
||||||
else
|
|
||||||
if _page.templatized?
|
|
||||||
@content_entry = _page.fetch_target_entry(File.basename(path.first))
|
|
||||||
|
|
||||||
if @content_entry.nil? || (!@content_entry.visible? && current_locomotive_account.nil?) # content instance not found or not visible
|
|
||||||
next
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
page = _page
|
|
||||||
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
page || not_found_page
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def locomotive_page_path
|
def locomotive_page_path
|
||||||
@ -58,11 +37,6 @@ module Locomotive
|
|||||||
|
|
||||||
path = 'index' if path.blank? || path == '_edit'
|
path = 'index' if path.blank? || path == '_edit'
|
||||||
|
|
||||||
if path != 'index'
|
|
||||||
dirname = File.dirname(path).gsub(/^\.$/, '') # also look for templatized page path
|
|
||||||
path = [path, File.join(dirname, 'content_type_template').gsub(/^\//, '')]
|
|
||||||
end
|
|
||||||
|
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -75,6 +49,7 @@ module Locomotive
|
|||||||
'current_page' => self.params[:page],
|
'current_page' => self.params[:page],
|
||||||
'params' => self.params,
|
'params' => self.params,
|
||||||
'path' => request.path,
|
'path' => request.path,
|
||||||
|
'fullpath' => request.fullpath,
|
||||||
'url' => request.url,
|
'url' => request.url,
|
||||||
'now' => Time.now.utc,
|
'now' => Time.now.utc,
|
||||||
'today' => Date.today,
|
'today' => Date.today,
|
||||||
@ -88,8 +63,8 @@ module Locomotive
|
|||||||
assigns.merge!(flash.to_hash.stringify_keys) # data from public submissions
|
assigns.merge!(flash.to_hash.stringify_keys) # data from public submissions
|
||||||
|
|
||||||
if @page.templatized? # add instance from content type
|
if @page.templatized? # add instance from content type
|
||||||
assigns['entry'] = @content_entry
|
assigns['entry'] = @page.content_entry
|
||||||
assigns[@page.target_entry_name] = @content_entry # just here to help to write readable liquid code
|
assigns[@page.target_entry_name] = @page.content_entry # just here to help to write readable liquid code
|
||||||
end
|
end
|
||||||
|
|
||||||
registers = {
|
registers = {
|
||||||
@ -120,10 +95,6 @@ module Locomotive
|
|||||||
render :text => output, :layout => false, :status => page_status unless performed?
|
render :text => output, :layout => false, :status => page_status unless performed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def not_found_page
|
|
||||||
current_site.pages.not_found.published.first
|
|
||||||
end
|
|
||||||
|
|
||||||
def editing_page?
|
def editing_page?
|
||||||
!!@editing
|
!!@editing
|
||||||
end
|
end
|
||||||
|
@ -95,13 +95,13 @@ describe 'Locomotive rendering system' do
|
|||||||
|
|
||||||
it 'should retrieve it based on the full path' do
|
it 'should retrieve it based on the full path' do
|
||||||
@controller.request.fullpath = '/about_us/team.html'
|
@controller.request.fullpath = '/about_us/team.html'
|
||||||
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{about_us/team about_us/content_type_template} }).returns([@page])
|
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{about_us/team about_us/content_type_template content_type_template/team} }).returns([@page])
|
||||||
@controller.send(:locomotive_page).should_not be_nil
|
@controller.send(:locomotive_page).should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not include the query string' do
|
it 'does not include the query string' do
|
||||||
@controller.request.fullpath = '/about_us/team.html?some=params&we=use'
|
@controller.request.fullpath = '/about_us/team.html?some=params&we=use'
|
||||||
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{about_us/team about_us/content_type_template} }).returns([@page])
|
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{about_us/team about_us/content_type_template content_type_template/team} }).returns([@page])
|
||||||
@controller.send(:locomotive_page).should_not be_nil
|
@controller.send(:locomotive_page).should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -135,13 +135,15 @@ describe 'Locomotive rendering system' do
|
|||||||
@content_entry = @content_type.entries.build(:_visible => true)
|
@content_entry = @content_type.entries.build(:_visible => true)
|
||||||
@page.templatized = true
|
@page.templatized = true
|
||||||
@page.stubs(:fetch_target_entry).returns(@content_entry)
|
@page.stubs(:fetch_target_entry).returns(@content_entry)
|
||||||
|
@page.stubs(:fullpath).returns('/projects/content_type_template')
|
||||||
@controller.request.fullpath = '/projects/edeneo.html'
|
@controller.request.fullpath = '/projects/edeneo.html'
|
||||||
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{projects/edeneo projects/content_type_template} }).returns([@page])
|
@controller.current_site.pages.expects(:any_in).with({ :fullpath => %w{projects/edeneo projects/content_type_template content_type_template/edeneo} }).returns([@page])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the content_entry variable' do
|
it 'sets the content_entry variable' do
|
||||||
@controller.send(:locomotive_page).should_not be_nil
|
page = @controller.send(:locomotive_page)
|
||||||
@controller.instance_variable_get(:@content_entry).should == @content_entry
|
page.should_not be_nil
|
||||||
|
page.content_entry.should == @content_entry
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the 404 page if the instance does not exist' do
|
it 'returns the 404 page if the instance does not exist' do
|
||||||
@ -149,7 +151,6 @@ describe 'Locomotive rendering system' do
|
|||||||
(klass = Locomotive::Page).expects(:published).returns([true])
|
(klass = Locomotive::Page).expects(:published).returns([true])
|
||||||
@controller.current_site.pages.expects(:not_found).returns(klass)
|
@controller.current_site.pages.expects(:not_found).returns(klass)
|
||||||
@controller.send(:locomotive_page).should be_true
|
@controller.send(:locomotive_page).should be_true
|
||||||
@controller.instance_variable_get(:@content_entry).should be_nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the 404 page if the instance is not visible' do
|
it 'returns the 404 page if the instance is not visible' do
|
||||||
|
Loading…
Reference in New Issue
Block a user