Class: Jekyll::OpenProjectHelpers::CollectionDocReader

Inherits:
DataReader
  • Object
show all
Defined in:
lib/jekyll-theme-open-project-helpers/project_data_reader.rb

Instance Method Summary collapse

Instance Method Details

#read(dir, collection) ⇒ Object



19
20
21
# File 'lib/jekyll-theme-open-project-helpers/project_data_reader.rb', line 19

def read(dir, collection)
  read_project_subdir(dir, collection)
end

#read_project_subdir(dir, collection, nested = false) ⇒ Object



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
63
# File 'lib/jekyll-theme-open-project-helpers/project_data_reader.rb', line 23

def read_project_subdir(dir, collection, nested=false)
  return unless File.directory?(dir) && !@entry_filter.symlink?(dir)

  entries = Dir.chdir(dir) do
    Dir["*.{adoc,md,markdown,html,svg,png}"] + Dir["*"].select { |fn| File.directory?(fn) }
  end

  entries.each do |entry|
    path = File.join(dir, entry)

    Jekyll.logger.debug("OPF:", "Reading entry #{path}")

    if File.directory?(path)
      read_project_subdir(path, collection, nested=true)

    elsif nested or (File.basename(entry, '.*') != 'index')
      ext = File.extname(path)
      if ['.adoc', '.md', '.markdown'].include? ext
        doc = NonLiquidDocument.new(path, :site => @site, :collection => collection)
        doc.read

        # Add document to Jekyll document database if it refers to software or spec
        # (as opposed to be some nested document like README)
        if (doc.url.split('/').size == 4) or (doc.url.split('/').size == 5 and collection.label === 'projects')
          Jekyll.logger.debug("OPF:", "Adding document with URL: #{doc.url}")
          collection.docs << doc
        else
          Jekyll.logger.debug("OPF:", "Did NOT add document with URL (nesting level doesn’t match): #{doc.url}")
        end
      else
        Jekyll.logger.debug("OPF:", "Adding static file: #{path}")
        collection.files << Jekyll::StaticFile.new(
          @site,
          @site.source,
          Pathname.new(File.dirname(path)).relative_path_from(Pathname.new(@site.source)).to_s,
          File.basename(path),
          collection)
      end
    end
  end
end