Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

67 lines (53 sloc) 1.622 kb
class ArticleDrop < BaseDrop
include Mephisto::Liquid::UrlMethods
timezone_dates :published_at, :updated_at
liquid_attributes << :title << :permalink << :comments_count
def initialize(source, options = {})
super source
@options = options
@liquid.update \
'body' => @source.body_html,
'excerpt' => (@source.excerpt_html.blank? ? nil : @source.excerpt_html),
'accept_comments' => @source.accept_comments?,
'is_page_home' => (options[:page] == true)
end
def author
@author ||= liquify(@source.user).first
end
def comments
@comments ||= liquify(*@source.comments) # .reject(&:new_record?) <-- show new comments as they're built as a preview
end
def sections
@sections ||= liquify(*@source.sections.reject(&:home?))
end
def tags
@tags ||= liquify(*@source.tags)
end
def blog_sections
sections.select { |s| s.source.blog? }
end
def page_sections
sections.select { |s| s.source.paged? }
end
def content
@content ||= body_for_mode(@options[:mode] || :list)
end
def url
@url ||= absolute_url(@site.permalink_for(@source)[1..-1])
end
def comments_feed_url
@comments_feed_url ||= url + '/comments.xml'
end
def changes_feed_url
@changes_feed_url ||= url + '/changes.xml'
end
def assets
@assets ||= liquify(*@source.assets)
end
protected
def body_for_mode(mode)
contents = [before_method(:excerpt), before_method(:body)]
contents.reverse! if mode == :single
contents.detect { |content| !content.blank? }.to_s.strip
end
end
Jump to Line
Something went wrong with that request. Please try again.