begin
  require 'haml'
rescue LoadError => e
  puts "'haml' gem not available"
end

module Overcommit::GitHook
  class HamlSyntax < HookSpecificCheck
    include HookRegistry
    file_type :haml

    def skip?
      unless defined? Haml
        return :warn, "Can't find Haml gem"
      end
    end

    def run_check
      staged.each do |path|
        begin
          Haml::Engine.new(File.read(path), :check_syntax => true)
        rescue Haml::Error => e
          return :bad, e.message
        end
      end
      return :good, nil
    end
  end
end

module Overcommit::GitHook
  class HamlSyntax < HookSpecificCheck
    include HookRegistry
    file_type :haml

    def run_check
      begin
        require 'haml'
      rescue LoadError
        return :warn, "'haml' gem not installed -- run `gem install haml`"
      end

      staged.each do |path|
        begin
          Haml::Engine.new(File.read(path), :check_syntax => true)
        rescue Haml::Error => e
          return :bad, e.message
        end
      end
      return :good, nil
    end
  end
end

Make Haml syntax checker lazy-load haml gem
Make Haml syntax checker lazy-load haml gem

Similar to scss-lint, only load the gem if the repo contains modified
'.haml' files. This makes it so that people can leave this hook
installed but dormant unless they're actually working on Haml files.
Prior to this commit, they'd get a warning about the gem not being
installed.

Change-Id: I3fd7e1a7769983deda1872c8104c6505e4df3014
Reviewed-on: https://gerrit.causes.com/22714
Tested-by: Aiden Scandella <1faf1e8390cdac9204f160c35828cc423b7acd7b@causes.com>
Reviewed-by: Greg Hurrell <79e2475f81a6317276bf7cbb3958b20d289b78df@causes.com>
Reviewed-by: Joe Lencioni <1dd72cf724deaab5db236f616560fc7067b734e1@causes.com>
