Class: Guard::Haml

Inherits:
Guard
  • 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(watchers = [], options = {}) ⇒ Haml

Returns a new instance of Haml.



10
11
12
13
14
15
16
# File 'lib/guard/haml.rb', line 10

def initialize(watchers = [], options = {})
  @options = {
    :notifications => true,
    :default_ext   => 'html'
  }.merge options
  super(watchers, @options)
end

Instance Method Details

#reloadObject



26
27
28
# File 'lib/guard/haml.rb', line 26

def reload
  run_all
end

#run_allObject



30
31
32
# File 'lib/guard/haml.rb', line 30

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

#run_on_changes(paths) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/guard/haml.rb', line 34

def run_on_changes(paths)
  paths.each do |file|
    output_files = get_output(file)
    compiled_haml = compile_haml(file)
    output_files.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_files.join(', ')}".gsub("#{Bundler.root.to_s}/", '')
    ::Guard::UI.info message
    Notifier.notify( true, message ) if @options[:notifications]
  end
  notify paths
end

#startObject



18
19
20
# File 'lib/guard/haml.rb', line 18

def start
  run_all if @options[:run_at_start]
end

#stopObject



22
23
24
# File 'lib/guard/haml.rb', line 22

def stop
  true
end