public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Search Repo:
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
commit  9072b487bf45c5e41e33c66b32d94aea84732d1b
tree    642666d0dd7f9db31e3bc77ec5db8340403adbaf
parent  cf00416fe7212bd60eb4e92d50f90b1991d355cf
mephisto / app / drops / article_drop.rb
100644 67 lines (53 sloc) 1.622 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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