Class: Guard::Haml

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/haml.rb,
lib/guard/haml/notifier.rb

Defined Under Namespace

Classes: Notifier

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Haml

Returns a new instance of Haml.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/guard/haml.rb', line 10

def initialize(opts = {})
  opts = {
    notifications:        true,
    default_ext:          'html',
    auto_append_file_ext: false
  }.merge(opts)

  super(opts)

  if options[:input]
    watchers << ::Guard::Watcher.new(%r{^#{options[:input]}/([\w\-_]+(\.html)?\.haml)$})
  end
end

Instance Method Details

#reloadObject



32
33
34
# File 'lib/guard/haml.rb', line 32

def reload
  run_all
end

#run_allObject



36
37
38
# File 'lib/guard/haml.rb', line 36

def run_all
  run_on_changes(Watcher.match_files(self, Dir.glob(File.join('**', '*.*'))))
end

#run_on_changes(paths) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/guard/haml.rb', line 40

def run_on_changes(paths)
  paths.each do |file|
    output_paths = _output_paths(file)
    compiled_haml = compile_haml(file)

    output_paths.each do |output_file|
      FileUtils.mkdir_p File.dirname(output_file)
      File.open(output_file, 'w') { |f| f.write(compiled_haml) }
    end

    message = "Successfully compiled haml to html!\n"
    message += "# #{file} -> #{output_paths.join(', ')}".gsub("#{::Bundler.root.to_s}/", '')
    ::Guard::UI.info message
    Notifier.notify(true, message) if options[:notifications]
  end
end

#startObject



24
25
26
# File 'lib/guard/haml.rb', line 24

def start
  run_all if options[:run_at_start]
end

#stopObject



28
29
30
# File 'lib/guard/haml.rb', line 28

def stop
  true
end