details.rb 1.31 KB
Newer Older
Sylvester Keil's avatar
Sylvester Keil committed
1 2 3 4
module Jekyll
  class Scholar

    class Details < Page
5
      include Scholar::Utilities
6

Sylvester Keil's avatar
Sylvester Keil committed
7 8
      def initialize(site, base, dir, entry)
        @site, @base, @dir = site, base, dir
9

Sylvester Keil's avatar
Sylvester Keil committed
10
        @config = Scholar.defaults.merge(site.config['scholar'] || {})
11

12
        @name = details_file_for(entry)
Sylvester Keil's avatar
Sylvester Keil committed
13 14 15

        process(@name)
        read_yaml(File.join(base, '_layouts'), config['details_layout'])
16

17
        liquidify(entry)
Sylvester Keil's avatar
Sylvester Keil committed
18
      end
19

20 21 22 23
      private

      def liquidify(entry)
        data['entry'] = {}
24

25 26 27 28 29
        data['entry']['key'] = entry.key
        data['entry']['type'] = entry.type

        entry.fields.each do |key, value|
          data['entry'][key.to_s] = value.to_s
30
        end
31

32 33 34
        data['entry']['bibtex'] = entry.to_s
      end

Sylvester Keil's avatar
Sylvester Keil committed
35 36 37
    end

    class DetailsGenerator < Generator
38
      include Scholar::Utilities
39
      
Sylvester Keil's avatar
Sylvester Keil committed
40
      safe true
41
      priority :high
Sylvester Keil's avatar
Sylvester Keil committed
42 43

      attr_reader :config
44

Sylvester Keil's avatar
Sylvester Keil committed
45
      def generate(site)
46
        @site, @config = site, Scholar.defaults.merge(site.config['scholar'] || {})
47

48 49
        if generate_details?
          entries.each do |entry|
50
            details = Details.new(site, site.source, File.join('', details_path), entry)
Sylvester Keil's avatar
Sylvester Keil committed
51 52
            details.render(site.layouts, site.site_payload)
            details.write(site.dest)
53

Sylvester Keil's avatar
Sylvester Keil committed
54 55
            site.pages << details
          end
56

Sylvester Keil's avatar
Sylvester Keil committed
57 58
        end
      end
59

Sylvester Keil's avatar
Sylvester Keil committed
60 61 62 63 64
    end


  end
end