app/models/page.rb in refinerycms-pages-0.9.9.4 vs app/models/page.rb in refinerycms-pages-0.9.9.5
- old
+ new
@@ -1,10 +1,10 @@
require 'globalize3'
class Page < ActiveRecord::Base
- translates :title, :meta_keywords, :meta_description, :browser_title if self.respond_to?(:translates)
+ translates :title, :meta_keywords, :meta_description, :browser_title, :custom_title if self.respond_to?(:translates)
attr_accessor :locale # to hold temporarily
validates :title, :presence => true
acts_as_nested_set
@@ -175,11 +175,11 @@
if defined?(::Refinery::I18n) and ::Refinery::I18n.enabled?
[Refinery.base_cache_key, ::I18n.locale ,super].join('/')
else
[Refinery.base_cache_key, super].join('/')
end
-
+
end
# Returns true if this page is "published"
def live?
not draft?
@@ -222,24 +222,22 @@
#
# Page.first[:body]
#
# Will return the body page part of the first page.
def [](part_title)
- # don't want to override a super method when trying to call a page part.
- # the way that we call page parts seems flawed, will probably revert to page.parts[:title] in a future release.
- if (super_value = super).blank?
- # self.parts is already eager loaded so we can now just grab the first element matching the title we specified.
- part = self.parts.detect do |part|
- part.title.present? and #protecting against the problem that occurs when have nil title
- part.title == part_title.to_s or
- part.title.downcase.gsub(" ", "_") == part_title.to_s.downcase.gsub(" ", "_")
- end
+ # Allow for calling attributes with [] shorthand (eg page[:parent_id])
+ return super if self.attributes.has_key?(part_title.to_s)
- return part.body unless part.nil?
+ # the way that we call page parts seems flawed, will probably revert to page.parts[:title] in a future release.
+ # self.parts is already eager loaded so we can now just grab the first element matching the title we specified.
+ part = self.parts.detect do |part|
+ part.title.present? and #protecting against the problem that occurs when have nil title
+ part.title == part_title.to_s or
+ part.title.downcase.gsub(" ", "_") == part_title.to_s.downcase.gsub(" ", "_")
end
- super_value
+ part.try(:body)
end
# In the admin area we use a slightly different title to inform the which pages are draft or hidden pages
def title_with_meta
title = [self.title.to_s]
@@ -258,9 +256,10 @@
# Protects generated slugs from title if they are in the list of reserved words
# This applies mostly to plugin-generated pages.
#
# Returns the sluggified string
def normalize_friendly_id(slug_string)
+ slug_string.gsub!('_', '-')
sluggified = super
if self.class.use_marketable_urls? && self.class.friendly_id_config.reserved_words.include?(sluggified)
sluggified << "-page"
end
sluggified