Class: Spree::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spree/page.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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

Returns:

  • (Boolean)


47
48
49
# File 'app/models/spree/page.rb', line 47

def matches?(_path)
  (root? && _path == "/") || (!root? && _path.match(path))
end

#meta_titleObject



34
35
36
37
# File 'app/models/spree/page.rb', line 34

def meta_title
  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

Returns:

  • (Boolean)


51
52
53
# File 'app/models/spree/page.rb', line 51

def root?
  self.path == "/"
end

#to_paramObject



29
30
31
32
# File 'app/models/spree/page.rb', line 29

def to_param
  return "_home_" if path == "/"
  path.sub(/^\/*/, "")
end