forked from technoweenie/mephisto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drop_filters.rb
44 lines (35 loc) · 1.58 KB
/
drop_filters.rb
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
module DropFilters
def section(path)
@context['site'].find_section(path)
end
def child_sections(path_or_section)
path = path_or_section.is_a?(SectionDrop) ? path_or_section['path'] : path_or_section
@context['site'].find_child_sections(path)
end
def descendant_sections(path_or_section)
path = path_or_section.is_a?(SectionDrop) ? path_or_section['path'] : path_or_section
@context['site'].find_descendant_sections(path)
end
def latest_articles(site_or_section, limit = nil)
site_or_section.latest_articles(limit || site_or_section['articles_per_page'])
end
def latest_article(section)
latest_articles(section, 1).first
end
def latest_comments(site, limit = nil)
site.latest_comments(limit || site['articles_per_page'])
end
def monthly_articles(section, date = nil)
date = parse_date(date)
section.source.articles.find_all_in_month(date.year, date.month).collect! { |a| a.to_liquid :site => @context['site'].source, :mode => :single }
end
def tagged_articles(tags)
@context['site'].source.articles.find(:all, :include => :tags, :conditions => ['tags.name in (?)', Tag.parse(tags)], :order => 'contents.created_at desc').collect!(&:to_liquid)
end
def assets_by_type(type)
@context['site'].source.assets.find_all_by_content_types([type.to_sym], :all, :order => 'created_at desc').collect!(&:to_liquid)
end
def tagged_assets(tags)
@context['site'].source.assets.find(:all, :include => :tags, :conditions => ['tags.name in (?)', Tag.parse(tags)], :order => 'assets.created_at desc').collect!(&:to_liquid)
end
end