Class: Jekyll::PreCommit::Checks::FrontMatterVariableExists

Inherits:
Check
  • Object
show all
Defined in:
lib/jekyll-pre-commit/checks/front_matter_variable_exists.rb

Instance Method Summary collapse

Methods inherited from Check

#initialize

Constructor Details

This class inherits a constructor from Jekyll::PreCommit::Checks::Check

Instance Method Details

#check(staged, not_staged, site, args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jekyll-pre-commit/checks/front_matter_variable_exists.rb', line 5

def check(staged, not_staged, site, args)
  if !args["variables"]
    @result[:message] += "No variables to check."
    return @result
  end

  staged.each do |post|
    args["variables"].each do |variable|
      if !post.data[variable]
        @result[:ok] = false
        @result[:message] += "#{post.data["title"]} was missing a #{variable}. "
      end
    end
  end

  @result
end