Module: Cms::Behaviors::Publishing::InstanceMethods
- Defined in:
- lib/cms/behaviors/publishing.rb
Instance Method Summary collapse
- #live? ⇒ Boolean
- #publish ⇒ Object
-
#publish! ⇒ Object
Force the publishing of this block.
- #publish_for_non_versioned ⇒ Object
- #publishable? ⇒ Boolean
- #status ⇒ Object
- #status_name ⇒ Object
Instance Method Details
#live? ⇒ Boolean
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cms/behaviors/publishing.rb', line 136 def live? if self.class.versioned? if (respond_to?(:latest_version) && self.latest_version) version == latest_version && published? else live_version.version == draft.version && published? end else true end end |
#publish ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/cms/behaviors/publishing.rb', line 63 def publish publish! true rescue Exception => e logger.warn("Could not publish, #{e.class}: #{e.}\n#{e.backtrace.join("\n")}") false end |
#publish! ⇒ Object
Force the publishing of this block.
Warning: The behavior of calling the following on an existing block:
block.save_on_publish
block.save!
Is different than calling:
block.publish!
And it probably shouldn’t be. Try to merge the ‘else’ with the ‘Versioning#create_or_update’ method to eliminate duplication
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/cms/behaviors/publishing.rb', line 81 def publish! if new_record? self.publish_on_save = true save! else # Do this for publishing existing blocks. transaction do if self.class.versioned? d = draft # We only need to publish if this isn't already published # or the draft version is greater than the live version if !self.published? || d.version > self.version d.update_attributes(:published => true) # copy values from the draft to the main record quoted_attributes = d.send(:arel_attributes_values, false, false, self.class.versioned_columns) #the values from the draft MAY have a relation of the versioned module #as opposed to the actual class itself #eg Page::Version, and not Page #so remap to the actual arel_table´ #I haven't figured out why this is, but I know it happens when you call save! on Page #during seeding of data if self.class.arel_table.name != quoted_attributes.keys[0].relation.name quoted_attributes = quoted_attributes.inject({}){|hash, pair| hash[self.class.arel_table[pair[0].name]] = pair[1]; hash} end # Doing the SQL ourselves to avoid callbacks self.class.unscoped.where(self.class.arel_table[self.class.primary_key].eq(id)).arel.update(quoted_attributes) end else connection.update( "UPDATE #{self.class.quoted_table_name} " + "SET published = #{connection.quote(true, self.class.columns_hash["published"])} " + "WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quote_value(id)}", "#{self.class.name.demodulize} Publish" ) end after_publish if respond_to?(:after_publish) end self.published = true end end |
#publish_for_non_versioned ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/cms/behaviors/publishing.rb', line 54 def publish_for_non_versioned unless self.class.versioned? if @publish_on_save publish @publish_on_save = nil end end end |
#publishable? ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'lib/cms/behaviors/publishing.rb', line 46 def publishable? if self.class.connectable? new_record? ? connect_to_page_id.blank? : connected_page_count < 1 else true end end |
#status ⇒ Object
127 128 129 130 |
# File 'lib/cms/behaviors/publishing.rb', line 127 def status return @status if @status @status = live? ? :published : :draft end |
#status_name ⇒ Object
132 133 134 |
# File 'lib/cms/behaviors/publishing.rb', line 132 def status_name status.to_s.titleize end |