aboutsummaryrefslogtreecommitdiff
blob: 3955c3afe8156c94512043aa6588ff2283848d3a (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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].txt').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['number'] <=> b['number'] }
    end
  end

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

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

      data['permalink'] = "/glep/#{@name}"
      data['layout'] = 'glep'
      data['nav1'] = 'inside-gentoo'
      data['nav2'] = 'gleps'

      lines = File.readlines(File.join(@base, GLEPGenerator::GLEP_DIR, name))
      while not lines.empty?
        line = lines.shift
        @number = $1.to_i if line =~ /^GLEP: (.*)$/
        @title = $1 if line =~ /^Title: (.*)$/
        @version = $1 if line =~ /^Version: (.*)$/
        @lastmodified = $1 if line =~ /^Last-Modified: (.*)$/
        @author = $1 if line =~ /^Author: (.*)$/
        @discussionsto = $1 if line =~ /^Discussions-To: (.*)$/
        @status = $1 if line =~ /^Status: (.*)$/
        @type = $1 if line =~ /^Type: (.*)$/
        @contenttype = $1 if line =~ /^Content-Type: (.*)$/
        @requires = $1 if line =~ /^Requires: (.*)$/
        @created = $1 if line =~ /^Created: (.*)$/
        @posthistory = $1 if line =~ /^Post-History: (.*)$/
        @replaces = $1 if line =~ /^Replaces: (.*)$/
        @replacedby = $1 if line =~ /^Replaced-By: (.*)$/
        break if line.chomp.empty?
      end
      @content = RbST.new(".. contents::\n..\n\n" + lines.join('')).to_html(
        'initial-header-level' => 2)

      glep_data = {
        'number' => @number,
        'title' => @title,
        'version' => @version,
        'lastmodified' => @lastmodified,
        'author' => @author,
        'discussionsto' => @discussionsto,
        'status' => @status,
        'type' => @type,
        'contenttype' => @contenttype,
        'requires' => @requires,
        'created' => @created,
        'posthistory' => @posthistory,
        'replaces' => @replaces,
        'replacedby' => @replacedby,
      }

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