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
-
#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
#liquid_context ⇒ Object (readonly)
Returns the value of attribute liquid_context.
24 25 26 |
# File 'app/models/smithy/page.rb', line 24 def liquid_context @liquid_context end |
#publish ⇒ Object
Returns the value of attribute publish.
23 24 25 |
# File 'app/models/smithy/page.rb', line 23 def publish @publish end |
Class Method Details
.page_selector_options ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/smithy/page.rb', line 26 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
37 38 39 |
# File 'app/models/smithy/page.rb', line 37 def container?(container_name) containers.where(:name => container_name).count > 0 end |
#contents_for_container_name(container_name) ⇒ Object
41 42 43 |
# File 'app/models/smithy/page.rb', line 41 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
45 46 47 48 49 |
# File 'app/models/smithy/page.rb', line 45 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
55 56 57 |
# File 'app/models/smithy/page.rb', line 55 def published? self.published_at? end |
#render(liquid_context) ⇒ Object
59 60 61 62 |
# File 'app/models/smithy/page.rb', line 59 def render(liquid_context) @liquid_context = liquid_context self.template.liquid_template.render(liquid_context) end |
#render_container(container_name) ⇒ Object
64 65 66 67 68 69 |
# File 'app/models/smithy/page.rb', line 64 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
51 52 53 |
# File 'app/models/smithy/page.rb', line 51 def should_generate_new_friendly_id? title_changed? || permalink_changed? end |
#site ⇒ Object
71 72 73 |
# File 'app/models/smithy/page.rb', line 71 def site @site ||= Smithy::Site.instance end |
#to_liquid ⇒ Object
75 76 77 |
# File 'app/models/smithy/page.rb', line 75 def to_liquid Smithy::Liquid::Drops::Page.new(self) end |
#url ⇒ Object
79 80 81 |
# File 'app/models/smithy/page.rb', line 79 def url self.external_link.present? ? self.external_link : self.path end |