Module: Cms::Behaviors::Publishing::InstanceMethods
- Defined in:
- lib/cms/behaviors/publishing.rb
Instance Method Summary collapse
- #live? ⇒ Boolean
- #publish ⇒ Object
- #publish! ⇒ Object
- #publish_for_non_versioned ⇒ Object
- #publishable? ⇒ Boolean
- #status ⇒ Object
- #status_name ⇒ Object
Instance Method Details
#live? ⇒ Boolean
105 106 107 |
# File 'lib/cms/behaviors/publishing.rb', line 105 def live? self.class.versioned? ? live_version.version == draft.version && published? : true end |
#publish ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/cms/behaviors/publishing.rb', line 49 def publish publish! true rescue Exception => e logger.warn("Could not publish, #{e.class}: #{e.}\n#{e.backtrace.join("\n")}") false end |
#publish! ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cms/behaviors/publishing.rb', line 57 def publish! if new_record? self.publish_on_save = true save! else 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(:attributes_with_quotes, false, false, self.class.versioned_columns) # Doing the SQL ourselves to avoid callbacks connection.update( "UPDATE #{self.class.quoted_table_name} " + "SET #{quoted_comma_pair_list(connection, quoted_attributes)} " + "WHERE #{connection.quote_column_name(self.class.primary_key)} = #{quote_value(id)}", "#{self.class.name} Publish" ) 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} Publish" ) end after_publish if respond_to?(:after_publish) end self.published = true end end |
#publish_for_non_versioned ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/cms/behaviors/publishing.rb', line 40 def publish_for_non_versioned unless self.class.versioned? if @publish_on_save publish @publish_on_save = nil end end end |
#publishable? ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/cms/behaviors/publishing.rb', line 32 def publishable? if self.class.connectable? new_record? ? connect_to_page_id.blank? : connected_page_count < 1 else true end end |
#status ⇒ Object
97 98 99 |
# File 'lib/cms/behaviors/publishing.rb', line 97 def status live? ? :published : :draft end |
#status_name ⇒ Object
101 102 103 |
# File 'lib/cms/behaviors/publishing.rb', line 101 def status_name status.to_s.titleize end |