Class: Fuel::Post

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Includes:
ActionView::Helpers::OutputSafetyHelper
Defined in:
app/models/fuel/post.rb

Defined Under Namespace

Modules: Formats

Instance Method Summary collapse

Instance Method Details

#avatar_urlObject



93
94
95
96
# File 'app/models/fuel/post.rb', line 93

def avatar_url
  return unless author.present?
  author.avatar.url(:medium)
end

#contentObject



73
74
75
# File 'app/models/fuel/post.rb', line 73

def content
  markdown? ? to_html(raw_content) : raw_content
end


89
90
91
# File 'app/models/fuel/post.rb', line 89

def featured_image_url
  featured_image.url(:medium)
end

#html?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'app/models/fuel/post.rb', line 81

def html?
  format == Formats::HTML
end

#is_publishedObject



55
56
57
# File 'app/models/fuel/post.rb', line 55

def is_published
  self.published
end

#markdown?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/fuel/post.rb', line 85

def markdown?
  format == Formats::MARKDOWN
end

#nextObject



39
40
41
# File 'app/models/fuel/post.rb', line 39

def next
  self.class.recent.where("published_at <= ? AND id != ?", published_at, id).first
end

#previousObject



43
44
45
# File 'app/models/fuel/post.rb', line 43

def previous
  self.class.recent.where("published_at >= ? AND id != ?", published_at, id).last
end


59
60
61
# File 'app/models/fuel/post.rb', line 59

def prioritized_featured_image_url(type = :original)
  featured_image_file_name.present? ? featured_image.url(type) : featured_image_url
end

#raw_contentObject



77
78
79
# File 'app/models/fuel/post.rb', line 77

def raw_content
  attributes["content"]
end

#s3_credentialsObject



35
36
37
# File 'app/models/fuel/post.rb', line 35

def s3_credentials
  { :bucket => Fuel.configuration.aws_bucket, :access_key_id => Fuel.configuration.aws_access_key, :secret_access_key => Fuel.configuration.aws_secret_access_key }
end

#save_as_draftObject



51
52
53
# File 'app/models/fuel/post.rb', line 51

def save_as_draft
  self.published = false
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/fuel/post.rb', line 47

def should_generate_new_friendly_id?
  new_record? #Don't generate new id on edit
end

#teaser_contentObject



63
64
65
# File 'app/models/fuel/post.rb', line 63

def teaser_content
  teaser.present? ? teaser : content
end

#to_html(content = raw_content) ⇒ Object



67
68
69
70
71
# File 'app/models/fuel/post.rb', line 67

def to_html(content = raw_content)
  markdown = Redcarpet::Markdown.new(Fuel::Html,
      :autolink => true, :space_after_headers => true, fenced_code_blocks: true, disable_indented_code_blocks: true, tables: true)
  raw markdown.render(content)
end