class Ruhoh::Resources::Pages::CollectionView
Public Instance Methods
all()
click to toggle source
# File lib/ruhoh/resources/pages/collection_view.rb, line 11 def all ruhoh.cache.get("#{ resource_name }-all") || ruhoh.cache.set("#{ resource_name }-all", dictionary.each_value.find_all { |model| File.basename(File.dirname(model.id)) != "drafts" }.sort ) end
collated()
click to toggle source
Internal: Create a collated pages data structure.
pages - Required [Array]
Must be sorted chronologically beforehand.
@returns collated pages: [{ ‘year’: year,
'months' : [{ 'month' : month, 'pages': [{}, {}, ..] }, ..] }, ..]
# File lib/ruhoh/resources/pages/collection_view.rb, line 40 def collated collated = [] pages = all pages.each_with_index do |page, i| thisYear = page['date'].strftime('%Y') thisMonth = page['date'].strftime('%B') if (i-1 >= 0) prevYear = pages[i-1]['date'].strftime('%Y') prevMonth = pages[i-1]['date'].strftime('%B') end if(prevYear == thisYear) if(prevMonth == thisMonth) collated.last['months'].last[resource_name] << page['id'] # append to last year & month else collated.last['months'] << { 'month' => thisMonth, resource_name => [page['id']] } # create new month end else collated << { 'year' => thisYear, 'months' => [{ 'month' => thisMonth, resource_name => [page['id']] }] } # create new year & month end end collated end
drafts()
click to toggle source
# File lib/ruhoh/resources/pages/collection_view.rb, line 19 def drafts dictionary.each_value.find_all { |model| File.basename(File.dirname(model.id)) == "drafts" }.sort end
latest()
click to toggle source
# File lib/ruhoh/resources/pages/collection_view.rb, line 25 def latest latest = config['latest'] latest ||= 10 (latest.to_i > 0) ? all[0, latest.to_i] : all end