details.rb 1.39 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
        data['entry']['key'] = entry.key
        data['entry']['type'] = entry.type

Artem Shinkarov's avatar
Artem Shinkarov committed
28
        data['entry']['bibtex'] = entry.to_s
29

30
        entry.fields.each do |key, value|
31 32
          value = value.convert(*bibtex_filters) unless bibtex_filters.empty?
          data['entry'][key.to_s] = value.to_s
33
        end
34

35 36
      end

Sylvester Keil's avatar
Sylvester Keil committed
37 38 39
    end

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

      attr_reader :config
46

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

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

Sylvester Keil's avatar
Sylvester Keil committed
56 57
            site.pages << details
          end
58

Sylvester Keil's avatar
Sylvester Keil committed
59 60
        end
      end
61

Sylvester Keil's avatar
Sylvester Keil committed
62 63 64 65 66
    end


  end
end