Module: Nanoc::Webpack::Filter::Dependable

Included in:
Nanoc::Webpack::Filter
Defined in:
lib/nanoc/webpack/filter/dependable.rb

Instance Method Summary collapse

Instance Method Details

#dependable(paths:, reject: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/nanoc/webpack/filter/dependable.rb', line 5

def dependable(paths:, reject: nil)
  reject ||= proc {}
  [*paths].flat_map do |path|
    expand(path).flat_map do
      node = File.join(root, _1)
      File.directory?(node) ? dependable(paths: File.join(_1, "*"), reject:) : _1
    end
  end.compact
     .reject(&reject)
end

#expand(path) ⇒ Object



16
17
18
19
20
# File 'lib/nanoc/webpack/filter/dependable.rb', line 16

def expand(path)
  abs_path = File.join(Dir.getwd, root)
  glob_str = File.expand_path(File.join(abs_path, path))
  Dir.glob(glob_str).map { File.join("/", _1.sub(abs_path, "")) }
end

#rootObject



22
23
24
25
26
27
28
# File 'lib/nanoc/webpack/filter/dependable.rb', line 22

def root
  @root ||= begin
    nanoc = Ryo.from(config.each.to_h)
    source = nanoc.data_sources.find(&:content_dir)
    source&.content_dir || "content/"
  end
end