Migrated from trying-to-understand-drops v2

bkerley
2010-08-12 13:45:54 -07:00
parent 7ed88664fb
commit 90dd24d808
+63 -63
@@ -5,72 +5,72 @@ Perhaps someone can comment on what the different drops are doing and their purp
Here are the 'drops'
class UserDrop < BaseDrop
liquid_attributes << :login << :email
end
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.nil? || @source.excerpt_html.empty? ? nil : @source.excerpt_html),
'accept_comments' => @source.accept_comments?,
'is_page_home' => (options[:page] == true)
class UserDrop < BaseDrop
liquid_attributes << :login << :email
end
def author
@author ||= liquify(@source.user).first
end
def comments
@comments ||= liquify(*@source.comments.reject(&:new_record?))
end
class ArticleDrop < BaseDrop
include Mephisto::Liquid::UrlMethods
def sections
@sections ||= @source.sections.inject([]) { |all, s| s.home? ? all : all << s.to_liquid } # your days are numbered, home section!
@sections ||= liquify(*@source.sections) { |s| s.home? ? nil : s.to_liquid }
end
timezone_dates :published_at, :updated_at
liquid_attributes << :title << :permalink << :comments_count
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))
end
def comments_feed_url
@comments_feed_url ||= url + '/comments.xml'
end
def changes_feed_url
@changes_feed_url ||= url + '/changes.xml'
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
def initialize(source, options = {})
super source
@options = options
@liquid.update \
'body' => @source.body_html,
'excerpt' => (@source.excerpt_html.nil? || @source.excerpt_html.empty? ? nil : @source.excerpt_html),
'accept_comments' => @source.accept_comments?,
'is_page_home' => (options[:page] == true)
end
end
def author
@author ||= liquify(@source.user).first
end
def comments
@comments ||= liquify(*@source.comments.reject(&:new_record?))
end
def sections
@sections ||= @source.sections.inject([]) { |all, s| s.home? ? all : all << s.to_liquid } # your days are numbered, home section!
@sections ||= liquify(*@source.sections) { |s| s.home? ? nil : s.to_liquid }
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))
end
def comments_feed_url
@comments_feed_url ||= url + '/comments.xml'
end
def changes_feed_url
@changes_feed_url ||= url + '/changes.xml'
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