Class: Smithy::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/smithy/page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#copy_content_fromObject

Returns the value of attribute copy_content_from.



24
25
26
# File 'app/models/smithy/page.rb', line 24

def copy_content_from
  @copy_content_from
end

#liquid_contextObject (readonly)

Returns the value of attribute liquid_context.



25
26
27
# File 'app/models/smithy/page.rb', line 25

def liquid_context
  @liquid_context
end

#publishObject

Returns the value of attribute publish.



24
25
26
# File 'app/models/smithy/page.rb', line 24

def publish
  @publish
end

Class Method Details

.page_selector_optionsObject



27
28
29
30
31
32
33
34
35
36
# File 'app/models/smithy/page.rb', line 27

def self.page_selector_options
  items = Array(self.roots)
  result = []
  items.each do |root|
    result += Page.associate_parents(root.self_and_descendants).map do |i|
      ["#{'-' * i.level} #{i.title}", i.url]
    end.compact
  end
  result
end

Instance Method Details

#container?(container_name) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/smithy/page.rb', line 38

def container?(container_name)
  containers.where(:name => container_name).count > 0
end

#contents_for_container_name(container_name) ⇒ Object



42
43
44
# File 'app/models/smithy/page.rb', line 42

def contents_for_container_name(container_name)
  self.contents.publishable.for_container(container_name)
end

#duplicate_content_from(page_id) ⇒ Object



46
47
48
49
50
51
52
53
# File 'app/models/smithy/page.rb', line 46

def duplicate_content_from(page_id)
  page = Page.find(page_id)
  self.contents = page.contents.map(&:amoeba_dup)
  self.contents.each do |content|
    content.content_block = content.content_block.amoeba_dup
  end
  self
end

#normalize_friendly_id(value) ⇒ Object

normalize_friendly_id overrides the default creator for friendly_id



55
56
57
58
59
# File 'app/models/smithy/page.rb', line 55

def normalize_friendly_id(value) # normalize_friendly_id overrides the default creator for friendly_id
  return "/" if self.parent.blank?
  value = self.permalink? ? self.permalink.parameterize : value.to_s.parameterize
  [(self.parent.present? && !self.parent.root? ? self.parent.path : nil), value].join('/')
end

#published?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/smithy/page.rb', line 65

def published?
  self.published_at?
end

#render(liquid_context) ⇒ Object



69
70
71
72
# File 'app/models/smithy/page.rb', line 69

def render(liquid_context)
  @liquid_context = liquid_context
  self.template.liquid_template.render(liquid_context)
end

#render_container(container_name) ⇒ Object



74
75
76
77
78
79
# File 'app/models/smithy/page.rb', line 74

def render_container(container_name)
  return '' unless container?(container_name)
  Rails.cache.fetch(self.container_cache_key(container_name)) do
    self.contents_for_container_name(container_name).map{|c| c.render(liquid_context) }.join("\n\n")
  end
end

#shallow_copyObject



81
82
83
84
85
86
87
88
89
# File 'app/models/smithy/page.rb', line 81

def shallow_copy
  self.dup.tap do |p|
    p.title << " (Copy)"
    p.permalink.clear
    p.browser_title.clear
    p.keywords.clear
    p.description.clear
  end
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/smithy/page.rb', line 61

def should_generate_new_friendly_id?
  title_changed? || permalink_changed?
end

#siteObject



91
92
93
# File 'app/models/smithy/page.rb', line 91

def site
  @site ||= Smithy::Site.instance
end

#to_liquidObject



95
96
97
# File 'app/models/smithy/page.rb', line 95

def to_liquid
  Smithy::Liquid::Drops::Page.new(self)
end

#urlObject



99
100
101
# File 'app/models/smithy/page.rb', line 99

def url
  self.external_link.present? ? self.external_link : self.path
end