Class: Content
- Defined in:
- app/models/content.rb
Defined Under Namespace
Classes: Version
Instance Attribute Summary collapse
-
#draft ⇒ Object
Returns the value of attribute draft.
Class Method Summary collapse
Instance Method Summary collapse
- #author_id=(author_id) ⇒ Object
- #cache_key(*timestamp_names) ⇒ Object
- #category_titles ⇒ Object
- #cells_updated_at ⇒ Object
- #draft? ⇒ Boolean
- #just_published? ⇒ Boolean
- #owner ⇒ Object
- #owners ⇒ Object
- #pending? ⇒ Boolean
- #published? ⇒ Boolean
- #published_at=(published_at) ⇒ Object
- #published_at?(date) ⇒ Boolean
- #published_month ⇒ Object
- #published_year ⇒ Object
- #state ⇒ Object
- #to_param ⇒ Object
Instance Attribute Details
#draft ⇒ Object
Returns the value of attribute draft.
106 107 108 |
# File 'app/models/content.rb', line 106 def draft @draft end |
Class Method Details
.primary ⇒ Object
57 58 59 |
# File 'app/models/content.rb', line 57 def primary published.first end |
Instance Method Details
#author_id=(author_id) ⇒ Object
111 112 113 114 |
# File 'app/models/content.rb', line 111 def () # FIXME this is only needed because belongs_to_cacheable can't be non-polymorphic, yet self. = User.find() if end |
#cache_key(*timestamp_names) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/content.rb', line 66 def cache_key(*) if new_record? "#{model_name.cache_key}/new" else = [:updated_at, :cells_updated_at] if .none? = .map { |attr| send(attr) }.compact.map(&:to_time).max = .utc.to_s() "#{model_name.cache_key}/#{id}-#{}" end end |
#category_titles ⇒ Object
102 103 104 |
# File 'app/models/content.rb', line 102 def category_titles categories.collect(&:title) end |
#cells_updated_at ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/content.rb', line 77 def cells_updated_at if defined?(OutputFilter::Cells) OutputFilter::Cells.new(nil).send(:cells, body_html).values.map do |name, state, attrs| attrs = HashWithIndifferentAccess.new(attrs) cell = "#{name.camelize}Cell".constantize.new args = [state] attrs.delete "class" # ignore styling class attrs[:format] = :timestamp args << attrs unless attrs.empty? begin cell.render_state *args rescue ArgumentError end end.select { |response| response.is_a?(Time) }.max end end |
#draft? ⇒ Boolean
124 125 126 |
# File 'app/models/content.rb', line 124 def draft? published_at.nil? end |
#just_published? ⇒ Boolean
144 145 146 |
# File 'app/models/content.rb', line 144 def just_published? published? && published_at_changed? end |
#owner ⇒ Object
98 99 100 |
# File 'app/models/content.rb', line 98 def owner section end |
#owners ⇒ Object
94 95 96 |
# File 'app/models/content.rb', line 94 def owners owner.owners << owner end |
#pending? ⇒ Boolean
128 129 130 |
# File 'app/models/content.rb', line 128 def pending? !published? end |
#published? ⇒ Boolean
132 133 134 |
# File 'app/models/content.rb', line 132 def published? !published_at.nil? && published_at <= Time.zone.now end |
#published_at=(published_at) ⇒ Object
107 108 109 |
# File 'app/models/content.rb', line 107 def published_at=(published_at) write_attribute(:published_at, draft.to_i == 1 ? nil : published_at) end |
#published_at?(date) ⇒ Boolean
136 137 138 |
# File 'app/models/content.rb', line 136 def published_at?(date) published? && date == [:year, :month, :day].map { |key| published_at.send(key).to_s } end |
#published_month ⇒ Object
120 121 122 |
# File 'app/models/content.rb', line 120 def published_month Time.local(published_at.year, published_at.month, 1) end |
#published_year ⇒ Object
116 117 118 |
# File 'app/models/content.rb', line 116 def published_year Time.local(published_at.year, 1, 1) end |
#state ⇒ Object
140 141 142 |
# File 'app/models/content.rb', line 140 def state pending? ? :pending : :published end |
#to_param ⇒ Object
62 63 64 |
# File 'app/models/content.rb', line 62 def to_param permalink end |