Class: Guard::MtHaml

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/mthaml.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MtHaml

Initializer



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/guard/mthaml.rb', line 11

def initialize(options = {})
    options = {
        :input => "views/src",
        :output => "views",
        :environment => "php",
        :notifications => true,
        :compress_output => false,
        :run_at_start => true,
        :static_files => false
    }.merge(options)

    super(options)

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

Instance Method Details

#reloadObject



40
41
42
# File 'lib/guard/mthaml.rb', line 40

def reload
    run_all
end

#run_allObject

Run all



47
48
49
# File 'lib/guard/mthaml.rb', line 47

def run_all
    run_on_changes Watcher.match_files(self, Dir.glob(File.join("**", "*.*")).reject { |f| f[%r{(\.php)$}] })
end

#run_on_changes(paths) ⇒ Object

Run on changes to watched files

Parameters:

  • paths (Array)

    Paths of changed files



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/guard/mthaml.rb', line 57

def run_on_changes(paths)
    paths.each do |file|

        file = Pathname.new(file)
        file_dir = file.dirname.realpath
        input_dir = Pathname.new(options[:input]).realpath
        input_file = file.realpath

        unless input_dir == file_dir
            output_dir = Pathname.new(options[:output]).realpath + file_dir.basename
            make_directory(output_dir)
        else
            output_dir = Pathname.new(options[:output]).realpath
        end

        compile_haml(input_file, output_dir)
    end
end

#startObject

Run at start



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

def start
    run_all if options[:run_at_start]
end

#stopObject



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

def stop
    true
end