aboutsummaryrefslogtreecommitdiff
blob: 62c7f789a4c9b25e0225efc54fafadd2fd220da8 (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
38
39
40
41
42
43
44
45
46
47
48
49
require 'rbst'

module Gentoo
  class GLEPGenerator < Jekyll::Generator
    GLEP_DIR = 'glep/'

    def generate(site)
      site.data['gleps'] ||= []

      Dir.chdir(GLEP_DIR) do
        Dir.glob('glep-[0-9][0-9][0-9][0-9].rst').reverse_each do |name|
          begin
            site.pages << GLEPPage.new(site, name)
          rescue
            # fail them silently
          end
        end
      end

      site.data['gleps'] = site.data['gleps'].sort { |a, b| a['GLEP'] <=> b['GLEP'] }
    end
  end

  class GLEPPage < Jekyll::Page
    def initialize(site, name)
      @site = site
      @base = @site.source
      @dir = GLEPGenerator::GLEP_DIR
      @name = "#{name.chomp('.rst')}.html"

      process(@name)
      read_yaml(File.join(@base, GLEPGenerator::GLEP_DIR), name)

      data['title'] = "GLEP #{data['GLEP']}: #{data['Title']}"
      data['permalink'] = "/glep/#{@name}"
      data['layout'] = 'glep'
      data['nav1'] = 'inside-gentoo'
      data['nav2'] = 'gleps'
      data['extracss'] = ['glep.css']

      @content = RbST.new(".. contents::\n..\n\n" + @content).to_html(
        'initial-header-level' => 2)

      site.data['gleps'] << data.merge({
        'url' => data['permalink']
      })
    end
  end
end