Sha256: d39b58344561c5297af63d71c668fc0e888e95028cbe4ee23aaa0d23f354481a

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

# -*- coding: utf-8 -*-
description 'Changelog Aspect'
require 'rss/maker'

Aspect.create(:changelog, cacheable: true, hidden: true) do
  def call(context, page)
    format = context.params[:format]

    url = context.request.base_url
    context.header['Content-Type'] = "application/#{format == 'rss' ? 'rss' : 'atom'}+xml; charset=utf-8"

    per_page = 30
    page_nr = [context.params[:page].to_i, 1].max
    history = page.history((page_nr - 1) * per_page, per_page)

    content = RSS::Maker.make(format == 'rss' ? '2.0' : 'atom') do |feed|
      feed.channel.generator = 'Ōlelo'
      feed.channel.title = Config['title']
      feed.channel.id = feed.channel.link = url + '/' + page.path
      feed.channel.description = Config['title'] + ' Changelog'
      feed.channel.updated = Time.now
      feed.channel.author = Config['title']
      feed.items.do_sort = true
      history.each do |version|
        i = feed.items.new_item
        i.title = version.comment
        i.link = "#{url}/changes/#{version}"
        i.date = version.date
        i.dc_creator = version.author.name
      end
    end
    content.to_s
  end
end

Application.hook :head do
  %{<link rel="alternate" type="application/atom+xml" title="Sitewide Atom Changelog"
href="#{escape_html build_path('/', aspect: 'changelog', format: 'atom')}"/>
<link rel="alternate" type="application/rss+xml" title="Sitewide RSS Changelog"
href="#{escape_html build_path('/', aspect: 'changelog', format: 'rss')}"/>}
end

Application.hook :head do
  %{<link rel="alternate" type="application/atom+xml" title="#{escape_html page.path} Atom Changelog"
href="#{escape_html(build_path(page.path, aspect: 'changelog', format: 'atom'))}"/>
<link rel="alternate" type="application/rss+xml" title="#{escape_html page.path} RSS Changelog"
href="#{escape_html(build_path(page.path, aspect: 'changelog', format: 'rss'))}"/>} if page && !page.new? && !page.root?
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
olelo-0.9.8 plugins/aspects/changelog.rb
olelo-0.9.7 plugins/aspects/changelog.rb
olelo-0.9.6 plugins/aspects/changelog.rb
olelo-0.9.5 plugins/aspects/changelog.rb