/
check.rb
43 lines (31 loc) · 1001 Bytes
/
check.rb
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
# encoding: utf-8
module Nanoc::Extra::Checking
class OutputDirNotFoundError < Nanoc::Errors::Generic
def initialize(directory_path)
super("Unable to run check against output directory at “#{directory_path}”: directory does not exist.")
end
end
class Check
extend Nanoc::PluginRegistry::PluginMethods
attr_reader :site
attr_reader :issues
def initialize(site)
@site = site
@issues = Set.new
end
def run
raise NotImplementedError.new('Nanoc::Extra::Checking::Check subclasses must implement #run')
end
def add_issue(desc, params = {})
subject = params.fetch(:subject, nil)
@issues << Issue.new(desc, subject, self.class)
end
def output_filenames
output_dir = @site.config[:output_dir]
unless File.exist(output_dir)
raise Nanoc::Extra::Checking::OutputDirNotFoundError.new(output_dir)
end
Dir[output_dir + '/**/*'].select { |f| File.file?(f) }
end
end
end