lib/ecrire/app/models/post.rb in ecrire-0.30.3 vs lib/ecrire/app/models/post.rb in ecrire-0.31.0
- old
+ new
@@ -16,10 +16,12 @@
# +search_by_title+: Return all post that have a title that match
# the key you provide
#
#
class Post < ActiveRecord::Base
+ Content = Struct.new(:raw, :html)
+
has_one :header, class_name: Image
has_many :titles, -> { order "titles.created_at DESC" }
scope :published, lambda { status("published") }
scope :drafted, lambda { status("drafted") }
@@ -125,10 +127,13 @@
#
# This method should be used when trying to render the body of a post
# to a page in HTML.
#
def content
- (self.compiled_content || super || '').html_safe
+ @content ||= begin
+ content = read_attribute('content')
+ Content.new(content.fetch('raw', ''), content.fetch('html', ''))
+ end
end
##
# Returns the compiled excerpt for this post.
# The excerpt is based on content but only returns text.