Class: Smithy::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Smithy::Page
- Extended by:
- FriendlyId
- Defined in:
- app/models/smithy/page.rb
Instance Attribute Summary collapse
-
#duplicate_page ⇒ Object
Returns the value of attribute duplicate_page.
-
#liquid_context ⇒ Object
readonly
Returns the value of attribute liquid_context.
-
#publish ⇒ Object
Returns the value of attribute publish.
Class Method Summary collapse
Instance Method Summary collapse
- #container?(container_name) ⇒ Boolean
- #contents_for_container_name(container_name) ⇒ Object
-
#normalize_friendly_id(value) ⇒ Object
normalize_friendly_id overrides the default creator for friendly_id.
- #published? ⇒ Boolean
- #render(liquid_context) ⇒ Object
- #render_container(container_name) ⇒ Object
- #should_generate_new_friendly_id? ⇒ Boolean
- #site ⇒ Object
- #to_liquid ⇒ Object
- #url ⇒ Object
Instance Attribute Details
#duplicate_page ⇒ Object
Returns the value of attribute duplicate_page.
25 26 27 |
# File 'app/models/smithy/page.rb', line 25 def duplicate_page @duplicate_page end |
#liquid_context ⇒ Object (readonly)
Returns the value of attribute liquid_context.
26 27 28 |
# File 'app/models/smithy/page.rb', line 26 def liquid_context @liquid_context end |
#publish ⇒ Object
Returns the value of attribute publish.
25 26 27 |
# File 'app/models/smithy/page.rb', line 25 def publish @publish end |
Class Method Details
.page_selector_options ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/smithy/page.rb', line 28 def self. 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
39 40 41 |
# File 'app/models/smithy/page.rb', line 39 def container?(container_name) containers.where(:name => container_name).count > 0 end |
#contents_for_container_name(container_name) ⇒ Object
43 44 45 |
# File 'app/models/smithy/page.rb', line 43 def contents_for_container_name(container_name) self.contents.publishable.for_container(container_name) end |
#normalize_friendly_id(value) ⇒ Object
normalize_friendly_id overrides the default creator for friendly_id
47 48 49 50 51 |
# File 'app/models/smithy/page.rb', line 47 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
57 58 59 |
# File 'app/models/smithy/page.rb', line 57 def published? self.published_at? end |
#render(liquid_context) ⇒ Object
61 62 63 64 |
# File 'app/models/smithy/page.rb', line 61 def render(liquid_context) @liquid_context = liquid_context self.template.liquid_template.render(liquid_context) end |
#render_container(container_name) ⇒ Object
66 67 68 69 70 71 |
# File 'app/models/smithy/page.rb', line 66 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 |
#should_generate_new_friendly_id? ⇒ Boolean
53 54 55 |
# File 'app/models/smithy/page.rb', line 53 def should_generate_new_friendly_id? title_changed? || permalink_changed? end |
#site ⇒ Object
73 74 75 |
# File 'app/models/smithy/page.rb', line 73 def site @site ||= Smithy::Site.instance end |
#to_liquid ⇒ Object
77 78 79 |
# File 'app/models/smithy/page.rb', line 77 def to_liquid Smithy::Liquid::Drops::Page.new(self) end |
#url ⇒ Object
81 82 83 |
# File 'app/models/smithy/page.rb', line 81 def url self.external_link.present? ? self.external_link : self.path end |