details.rb 1.28 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
Sylvester Keil's avatar
Sylvester Keil committed
6 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 24 25 26 27 28 29 30

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

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

				data['entry']['bibtex'] = entry.to_s
33 34
			end
			
Sylvester Keil's avatar
Sylvester Keil committed
35 36 37
    end

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

      attr_reader :config
      
      def generate(site)
44
        @site, @config = site, Scholar.defaults.merge(site.config['scholar'] || {})
45

46 47 48
        if generate_details?
          entries.each do |entry|
            details = Details.new(site, site.source, details_path, entry)
Sylvester Keil's avatar
Sylvester Keil committed
49 50 51 52 53 54 55 56
            details.render(site.layouts, site.site_payload)
            details.write(site.dest)
            
            site.pages << details
          end
          
        end
      end
57
			
Sylvester Keil's avatar
Sylvester Keil committed
58 59 60 61 62
    end


  end
end