summaryrefslogtreecommitdiff
path: root/app/helpers/content_helper.rb
blob: 046a2dbdabbd6ffb9ffd68134a73945016d00d5b (plain)
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
module ContentHelper
  
  def date_for_page page
    page.published_at.to_s(:db) rescue page.created_at.to_s(:db)
  end
  
  def aggregate? content
    options = {}
    
    if content =~ /<aggregate([^<>]*)>/
      tag = $~.to_s
      matched_data = $1.scan(/\w+\=\"[a-zA-Z\s\/_\d]*\"/)
      
      matched_data.each do |data|
        splitted_data = data.split("=")
        options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "")
      end
    end
    
    content.sub(tag, render_collection(options))
  end
  
  def render_collection options
    render(
      :partial => 'content/article', 
      :collection => Page.aggregate(options)
    )
  end
end