Class: Polites::Nanoc::DataSource

Inherits:
Nanoc::DataSource
  • Object
show all
Defined in:
lib/polites/nanoc/data_source.rb

Overview

A data source for Nanoc that creates Nanoc content items from Polites files in a particular directory.

Instance Method Summary collapse

Instance Method Details

#itemsObject



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
# File 'lib/polites/nanoc/data_source.rb', line 25

def items
  @input_files.flat_map do |input_file|
    File.open(input_file) do |file|
      sheet = @parser.parse_sheet(file.content)

      inline_file_items = sheet.inline_files.map do |image|
        build_file_item(file.media(image.image), image.image, input_file, image.filename)
      end

      file_items = sheet.attached_files.map do |id|
        build_file_item(file.media(id), id, input_file)
      end

      [
        new_item(
          @formatter.call(sheet),
          {
            keywords: sheet.keywords,
            image: sheet.attached_files.first,
            image_caption: sheet.notes.any? ? @formatter.call(sheet.notes.first) : nil,
            inline_file_items: inline_file_items,
            filename: input_file.to_s,
            mtime: input_file.mtime
          },
          identifier(input_file)
        ),
        *inline_file_items,
        *file_items
      ]
    end
  end
end

#upObject



16
17
18
19
20
21
22
23
# File 'lib/polites/nanoc/data_source.rb', line 16

def up
  @root = Pathname(@config[:path])
  @settings = Settings.from_directory(@root)
  @extension = ".#{@settings['defaultPathExtensions']}"
  @input_files = @root.glob("*#{@extension}")
  @parser = Polites::Parser.new
  @formatter = Polites::HtmlFormatter.new
end