details.rb 1.47 KB
Newer Older
Sylvester Keil's avatar
Sylvester Keil committed
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
module Jekyll
  class Scholar

    class Details < Page
      
      attr_reader :config
      
      def initialize(site, base, dir, entry)
        @site, @base, @dir = site, base, dir
        
        @config = Scholar.defaults.merge(site.config['scholar'] || {})
        
        @name = [entry.key, 'html'].join('.')

        process(@name)
        read_yaml(File.join(base, '_layouts'), config['details_layout'])
        
        data['entry'] = entry
      end
    end

    class DetailsGenerator < Generator
      safe true

      attr_reader :config
      
      def generate(site)
        if site.config['scholar'] && site.layouts.key?(site.config['scholar']['details_layout'])
          
          @config = Scholar.defaults.merge(site.config['scholar'] || {})
          
          bibliography['@*'].each do |entry|
            details = Detauls.new(site, site.source, config['details_dir'], entry)
            details.render(site.layouts, site.site_payload)
            details.write(site.dest)
            
            site.pages << details
          end
          
        end
      end

      private
      
      def bibliography
        @bibliography ||= BibTeX.open(extend_path(file), :filter => :latex)
      end          
      
      def extend_path(name)
        if name.nil? || name.empty?
          name = config['bibliography']
        end
        
        p = File.join(config['source'], name)
        p << '.bib' unless File.exists?(p)
        p
      end      
    end


  end
end