details.rb 1.27 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

Sylvester Keil's avatar
fix #55    
Sylvester Keil committed
12
13
        @name = entry.key.to_s.gsub(/[:\s]+/, '_')
        @name << '.html'
Sylvester Keil's avatar
Sylvester Keil committed
14
15
16

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

18
        data.merge!(reference_data(entry))
19
        data['title'] = data['entry']['title'] if data['entry'].has_key?('title')
20
21
      end

Sylvester Keil's avatar
Sylvester Keil committed
22
23
24
    end

    class DetailsGenerator < Generator
25
      include Scholar::Utilities
26

Sylvester Keil's avatar
Sylvester Keil committed
27
      safe true
28
      priority :high
Sylvester Keil's avatar
Sylvester Keil committed
29
30

      attr_reader :config
31

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

35
36
        if generate_details?
          entries.each do |entry|
37
            details = Details.new(site, site.source, File.join('', details_path), entry)
Sylvester Keil's avatar
Sylvester Keil committed
38
39
            details.render(site.layouts, site.site_payload)
            details.write(site.dest)
40

Sylvester Keil's avatar
Sylvester Keil committed
41
            site.pages << details
42
43
44
45
46

            site.regenerator.add_dependency(
              site.in_source_dir(details.path),
              bibtex_path
            )
Sylvester Keil's avatar
Sylvester Keil committed
47
          end
48

Sylvester Keil's avatar
Sylvester Keil committed
49
50
        end
      end
51

Sylvester Keil's avatar
Sylvester Keil committed
52
53
54
55
    end


  end
56
end