summaryrefslogtreecommitdiff
path: root/helpers/wiki_helpers.rb
blob: 4984095caca69dccc9c1a3fce9c7c3b4f664f07d (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
30
31
32
33
34
35
36
37
require 'date'
require 'addressable/template'

module WikiHelpers

  WikiPageUrl = Addressable::Template.new("http://sublab.org/wiki/ikiwiki.cgi{?page}&do=goto")

  class WikiChanges

    attr_reader :username, :page, :changelog

    def initialize(atts={})
      @username = atts.fetch("username")
      @page = atts.fetch("page")
      @datetime = DateTime.parse(atts.fetch("datetime"))
      @changelog = atts.fetch("changelog", nil)
    end

    def datetime
      @datetime.strftime(CalendarHelpers::FORMATS[:log])
    end

  end

  def wiki_changes
    data.wiki_changes.map do |atts|
      WikiChanges.new(atts)
    end
  end

  # TODO move to link helper module
  def link_to_wiki(name)
    url = WikiPageUrl.expand({page: name}).to_s
    link_to escape_html(name), url
  end

end