details.rb 1.33 KB
Newer Older
Sylvester Keil's avatar
Sylvester Keil committed
1 2 3 4 5 6 7 8 9
module Jekyll
  class Scholar

    class Details < Page
      
      attr_reader :config
      
      def initialize(site, base, dir, entry)
        @site, @base, @dir = site, base, dir
10

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

Sylvester Keil's avatar
Sylvester Keil committed
13 14 15 16
        @name = [entry.key, 'html'].join('.')

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

Sylvester Keil's avatar
Sylvester Keil committed
18 19 20 21 22 23 24 25 26 27
        data['entry'] = entry
      end
    end

    class DetailsGenerator < Generator
      safe true

      attr_reader :config
      
      def generate(site)
28 29 30 31 32
        @config = Scholar.defaults.merge(site.config['scholar'] || {})

        if site.layouts.key?(File.basename(config['details_layout'], '.html'))
          bibliography.each do |entry|
            details = Details.new(site, site.source, config['details_dir'], entry)
Sylvester Keil's avatar
Sylvester Keil committed
33 34 35 36 37 38 39 40
            details.render(site.layouts, site.site_payload)
            details.write(site.dest)
            
            site.pages << details
          end
          
        end
      end
41
			
Sylvester Keil's avatar
Sylvester Keil committed
42 43 44
      private
      
      def bibliography
45
        @bibliography ||= BibTeX.open(bibliography_path, :filter => :latex)
Sylvester Keil's avatar
Sylvester Keil committed
46 47
      end          
      
48 49
      def bibliography_path
        p = File.join(config['source'], config['bibliography'])
Sylvester Keil's avatar
Sylvester Keil committed
50 51 52 53 54 55 56 57
        p << '.bib' unless File.exists?(p)
        p
      end      
    end


  end
end