Class: Spree::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::Page
- Defined in:
- app/models/spree/page.rb
Class Method Summary collapse
Instance Method Summary collapse
- #for_context(context) ⇒ Object
- #has_context?(context) ⇒ Boolean
- #matches?(_path) ⇒ Boolean
- #meta_title ⇒ Object
- #path=(value) ⇒ Object
- #root? ⇒ Boolean
- #to_param ⇒ Object
Class Method Details
.find_by_path(_path) ⇒ Object
5 6 7 8 |
# File 'app/models/spree/page.rb', line 5 def find_by_path(_path) return super('/') if _path == "_home_" && self.exists?(:path => "/") super _path.to_s.sub(/^\/*/, "/").gsub("--", "/") end |
Instance Method Details
#for_context(context) ⇒ Object
39 40 41 |
# File 'app/models/spree/page.rb', line 39 def for_context(context) contents.where(:context => context) end |
#has_context?(context) ⇒ Boolean
43 44 45 |
# File 'app/models/spree/page.rb', line 43 def has_context?(context) contents.where(:context => context).count end |
#matches?(_path) ⇒ Boolean
47 48 49 |
# File 'app/models/spree/page.rb', line 47 def matches?(_path) (root? && _path == "/") || (!root? && _path.match(path)) end |
#meta_title ⇒ Object
34 35 36 37 |
# File 'app/models/spree/page.rb', line 34 def val = read_attribute(:meta_title) val.blank? ? title : val end |
#path=(value) ⇒ Object
55 56 57 58 59 |
# File 'app/models/spree/page.rb', line 55 def path=(value) value = value.to_s.strip value.gsub!(/[\/\-\_]+$/, "") unless value == "/" write_attribute :path, value end |
#root? ⇒ Boolean
51 52 53 |
# File 'app/models/spree/page.rb', line 51 def root? self.path == "/" end |
#to_param ⇒ Object
29 30 31 32 |
# File 'app/models/spree/page.rb', line 29 def to_param return "_home_" if path == "/" path.sub(/^\/*/, "") end |