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
-
#copy_content_from ⇒ Object
Returns the value of attribute copy_content_from.
-
#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
- #duplicate_content_from(page_id) ⇒ 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
- #shallow_copy ⇒ Object
- #should_generate_new_friendly_id? ⇒ Boolean
- #site ⇒ Object
- #to_liquid ⇒ Object
- #url ⇒ Object
Instance Attribute Details
#copy_content_from ⇒ Object
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_context ⇒ Object (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 |
#publish ⇒ Object
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_options ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/smithy/page.rb', line 27 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
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 54 |
# File 'app/models/smithy/page.rb', line 46 def duplicate_content_from(page_id) page_id = page_id.id if page_id.is_a?(Smithy::Page) 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
56 57 58 59 60 |
# File 'app/models/smithy/page.rb', line 56 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('/').downcase end |
#published? ⇒ Boolean
66 67 68 |
# File 'app/models/smithy/page.rb', line 66 def published? self.published_at? end |
#render(liquid_context) ⇒ Object
70 71 72 73 |
# File 'app/models/smithy/page.rb', line 70 def render(liquid_context) @liquid_context = liquid_context self.template.liquid_template.render(liquid_context) end |
#render_container(container_name) ⇒ Object
75 76 77 78 79 80 |
# File 'app/models/smithy/page.rb', line 75 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_copy ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'app/models/smithy/page.rb', line 82 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
62 63 64 |
# File 'app/models/smithy/page.rb', line 62 def should_generate_new_friendly_id? title_changed? || permalink_changed? end |
#site ⇒ Object
92 93 94 |
# File 'app/models/smithy/page.rb', line 92 def site @site ||= Smithy::Site.instance end |
#to_liquid ⇒ Object
96 97 98 |
# File 'app/models/smithy/page.rb', line 96 def to_liquid Smithy::Liquid::Drops::Page.new(self) end |
#url ⇒ Object
100 101 102 |
# File 'app/models/smithy/page.rb', line 100 def url self.external_link.present? ? self.external_link : self.path end |