class Miniblog::Post
Constants
- LEGACY_TITLE_REGEXP
Attributes
transition[RW]
Public Class Methods
all_posts_json()
click to toggle source
# File app/models/miniblog/post.rb, line 43 def all_posts_json includes(:author). order_by_publish_date.to_json only: [:id, :title, :state, :published_at, :ready_for_review], methods: [:author_email, :published?] end
for_admin_index()
click to toggle source
# File app/models/miniblog/post.rb, line 73 def for_admin_index ordered_by_state.order_by_publish_date end
last_published(number)
click to toggle source
# File app/models/miniblog/post.rb, line 53 def last_published(number) published_and_ordered.limit(number) end
order_by_publish_date()
click to toggle source
# File app/models/miniblog/post.rb, line 57 def order_by_publish_date order('published_at DESC, created_at DESC, id DESC') end
ordered_by_state()
click to toggle source
# File app/models/miniblog/post.rb, line 77 def ordered_by_state order(:state) end
published()
click to toggle source
# File app/models/miniblog/post.rb, line 61 def published where(state: 'published') end
published_and_ordered()
click to toggle source
# File app/models/miniblog/post.rb, line 65 def published_and_ordered published.order_by_publish_date end
scoped_for(user)
click to toggle source
# File app/models/miniblog/post.rb, line 69 def scoped_for(user) user.is_publisher? ? all : user.authored_posts end
Public Instance Methods
allowed_to_update_permalink?()
click to toggle source
INSTANCE METHODS
# File app/models/miniblog/post.rb, line 89 def allowed_to_update_permalink? !self.published? end
day()
click to toggle source
# File app/models/miniblog/post.rb, line 93 def day "%02d" % published_at.day end
formatted_published_date()
click to toggle source
# File app/models/miniblog/post.rb, line 97 def formatted_published_date published_at.strftime("%b %d, %Y") end
html_body()
click to toggle source
# File app/models/miniblog/post.rb, line 101 def html_body @@renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :fenced_code_blocks => true, :space_after_headers => false) @@renderer.render(self.body).html_safe end
month()
click to toggle source
# File app/models/miniblog/post.rb, line 109 def month "%02d" % published_at.month end
publish_if_allowed(transition, user)
click to toggle source
# File app/models/miniblog/post.rb, line 113 def publish_if_allowed(transition, user) if user.is_publisher? self.publisher = user self.send(transition) end end
regenerate_permalink()
click to toggle source
# File app/models/miniblog/post.rb, line 120 def regenerate_permalink self.permalink = title.parameterize end
url_params()
click to toggle source
Use this methods to generate the post url always use with the splat operator
Example:
post_url(*post.url_params)
# File app/models/miniblog/post.rb, line 132 def url_params [self.year, self.month, self.day, self.permalink, 'html'] end