WIP stack with page

arnaud sellenet committed Jun 10, 2014
commit 8db8d36286a98ca6e3087ccb26fa5274722bc9e2
Showing 7 changed files with 61 additions and 27 deletions
locomotive/steam/entities/page.rb b/lib/locomotive/steam/entities/page.rb +18 -17
@@ @@ -50,7 +50,8 @@ module Locomotive
# @return [ Boolean ] True if the redirect_url property is set
#
def redirect?
- !self.redirect_url.blank?
+ false
+ #!self.redirect_url.blank?
end
# Depth of the page in the site tree.
@@ @@ -71,31 +72,31 @@ module Locomotive
#
# @param [ String ] fullpath The fullpath
#
- def fullpath_with_setting_slug=(fullpath)
- if fullpath && self.slug.nil?
- self.slug = File.basename(fullpath)
- end
+ # def fullpath_with_setting_slug=(fullpath)
+ # if fullpath && self.slug.nil?
+ # self.slug = File.basename(fullpath)
+ # end
- self.fullpath_without_setting_slug = fullpath
- end
+ # self.fullpath_without_setting_slug = fullpath
+ # end
- alias_method_chain :fullpath=, :setting_slug
+ # alias_method_chain :fullpath=, :setting_slug
# Modified setter in order to set inheritance fields from parent
#
# @param [ String ] fullpath The fullpath
#
- def parent_with_inheritance=(parent)
- self.templatized_from_parent = parent.templatized?
+ # def parent_with_inheritance=(parent)
+ # self.templatized_from_parent = parent.templatized?
- # copy properties from the parent
- %w(templatized content_type).each do |name|
- self.send(:"#{name}=", parent.send(name.to_sym))
- end
+ # # copy properties from the parent
+ # %w(templatized content_type).each do |name|
+ # self.send(:"#{name}=", parent.send(name.to_sym))
+ # end
- self.parent_without_inheritance = parent
- end
- alias_method_chain :parent=, :inheritance
+ # self.parent_without_inheritance = parent
+ # end
+ # alias_method_chain :parent=, :inheritance
# Return the fullpath dasherized and with the "*" character
# for the slug of templatized page.
locomotive/steam/mapper.rb b/lib/locomotive/steam/mapper.rb +24 -2
@@ @@ -21,10 +21,32 @@ end
collection :pages do
entity Locomotive::Steam::Entities::Page
repository Locomotive::Steam::Repositories::PagesRepository
- attribute :fullpath
- attribute :position
+
attribute :site, association: :sites
attribute :content_type, association: :content_types
+ attribute :parent, association: :pages
+ attribute :title, localized: true
+ attribute :slug, localized: true
+ attribute :fullpath, localized: true
+ attribute :redirect_url, localized: true
+ attribute :redirect_type, default: 301
+ attribute :template, localized: true
+ attribute :handle
+ attribute :listed, default: false
+ attribute :searchable
+ attribute :templatized, default: false
+ attribute :content_type
+ attribute :published, default: true
+ attribute :cache_strategy
+ attribute :response_type
+ attribute :position
+
+ attribute :seo_title, localized: true
+ attribute :meta_keywords, localized: true
+ attribute :meta_description, localized: true
+
+ attribute :editable_elements, type: :array, class_name: 'Locomotive::Mounter::Models::EditableElement'
+
end
collection :content_types do
locomotive/steam/middlewares/page.rb b/lib/locomotive/steam/middlewares/page.rb +4 -5
@@ @@ -17,18 +17,17 @@ module Locomotive::Steam
protected
def set_page!(env)
- page = self.fetch_page
-
+ page = self.fetch_page env['steam.locale']
if page
- self.log "Found page \"#{page.title}\" [#{page.safe_fullpath}]"
+ self.log "Found page \"#{page.title}\" [#{page.fullpath}]"
end
env['steam.page'] = page
end
- def fetch_page
+ def fetch_page locale
matchers = self.path_combinations(self.path)
-
+ Locomotive::Models[:pages].current_locale = locale
pages = Locomotive::Models[:pages].matching_paths(matchers)
if pages.size > 1
locomotive/steam/middlewares/renderer.rb b/lib/locomotive/steam/middlewares/renderer.rb +1 -0
@@ @@ -27,6 +27,7 @@ module Locomotive::Steam
def render_page
context = self.locomotive_context
begin
+
render(page, context)
rescue Exception => e
locomotive/steam/middlewares/stack.rb b/lib/locomotive/steam/middlewares/stack.rb +1 -1
@@ @@ -63,4 +63,4 @@ module Locomotive
end
end
- end
\ No newline at end of file
+ end
spec/support/helpers.rb +2 -2
@@ @@ -1,5 +1,6 @@
require 'locomotive/common'
require 'locomotive/models'
+ require 'locomotive/adapters/memory_adapter'
require_relative '../../lib/locomotive/steam/initializers'
require_relative '../../lib/locomotive/steam/loaders/yml_loader'
@@ @@ -14,8 +15,7 @@ module Spec
def mapper
@mapper ||= begin
adapter = Locomotive::Adapters::MemoryAdapter
- mapper = Locomotive::Mapper.load_from_file! adapter, File.join(File.expand_path('lib/locomotive/steam/mapper.rb'))
- mapper.load!
+ Locomotive::Mapper.load_from_file! adapter, File.join(File.expand_path('lib/locomotive/steam/mapper.rb'))
end
end
spec/unit/repositories/pages_spec.rb +11 -0
@@ @@ -0,0 +1,11 @@
+ require 'spec_helper'
+
+ describe 'Locomotive::Steam::Repository::PagesRepository' do
+
+ describe '#[]' do
+ end
+
+ describe '#matching_path' do
+ end
+
+ end