app/models/page.rb in puffer_pages-0.0.11 vs app/models/page.rb in puffer_pages-0.0.12
- old
+ new
@@ -8,16 +8,13 @@
def self.statuses
%w(draft hidden published)
end
- def self.root
- roots.first
- end
-
def self.find_page location
- page = Page.find_by_location location
+ page = PufferPages.single_section_page_path ?
+ Page.find_by_slug(location) : Page.find_by_location(location)
raise ActiveRecord::RecordNotFound if page.nil? || page.draft?
page
end
has_many :page_parts, :order => "name = '#{PufferPages.primary_page_part_name}' desc, name", :dependent => :destroy
@@ -26,11 +23,11 @@
validates_presence_of :name
validate do |page|
page.errors.add(:layout_name, :blank) unless page.inherited_layout_name.present?
end
- validates_uniqueness_of :slug, :scope => :parent_id
+ validates_uniqueness_of :slug, :scope => (:parent_id unless PufferPages.single_section_page_path)
validates_format_of :slug,
:with => /\A([\w]+[\w-]*(\.[\w]+)?|\*)\Z/,
:message => :slug_format,
:unless => :root?
validates_format_of :slug,
@@ -63,10 +60,14 @@
statuses.each do |status_name|
define_method "#{status_name}?" do status == status_name end
end
+ def to_location
+ PufferPages.single_section_page_path ? slug : location
+ end
+
def render(drops_or_context)
if inherited_layout
@template = Liquid::Template.parse(inherited_layout.body)
tracker.cleanup @template.render(drops_or_context, :registers => {:tracker => tracker, :page => self, :file_system => PufferPages::Liquid::FileSystem.new})
else
@@ -93,11 +94,11 @@
def render_layout
inherited_layout ? false : inherited_layout_name
end
def inherited_page_parts
- scope = PagePart.where(:page_parts => {:page_id => self_and_ancestors.map(&:id)}).joins(:page).order("page_parts.name = '#{PufferPages.primary_page_part_name}' desc, page_parts.name, pages.lft desc").uniq_by &:name
+ PagePart.where(:page_parts => {:page_id => self_and_ancestors.map(&:id)}).joins(:page).order("page_parts.name = '#{PufferPages.primary_page_part_name}' desc, page_parts.name, pages.lft desc").uniq_by &:name
end
def part name
inherited_page_parts.detect {|part| part.name == name}
end
@@ -106,8 +107,12 @@
self.location.include?('*')
end
def content_type
Rack::Mime.mime_type(File.extname(slug), 'text/html')
+ end
+
+ def self_and_children
+ [self] + children
end
end