Class: Guard::MtHaml
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::MtHaml
- Defined in:
- lib/guard/mthaml.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ MtHaml
constructor
Initializer.
-
#reload ⇒ Object
On Guard reload.
-
#run_all ⇒ Object
Run all.
-
#run_on_changes(paths) ⇒ Object
Run on changes to watched files.
-
#run_on_removals(paths) ⇒ Object
Called when a watched file is removed.
-
#start ⇒ Object
Run at start.
-
#stop ⇒ Object
Stop running.
Constructor Details
#initialize(options = {}) ⇒ MtHaml
Initializer
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/guard/mthaml.rb', line 12 def initialize( = {}) = { input: "views/src", output: "views", environment: "php", extension: nil, notifications: true, compress_output: false, static_files: false, run_at_start: true }.merge() # Define extension if environment is nil if [:extension].nil? [:extension] = if [:static_files] then "html" else [:environment] end end super() if [:input] watchers << ::Guard::Watcher.new(%r{^#{[:input]}/(.+\.haml)$}) end end |
Instance Method Details
#reload ⇒ Object
On Guard reload
53 54 55 |
# File 'lib/guard/mthaml.rb', line 53 def reload run_all end |
#run_all ⇒ Object
Run all
60 61 62 |
# File 'lib/guard/mthaml.rb', line 60 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
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/guard/mthaml.rb', line 70 def run_on_changes(paths) paths.each do |file| file = Pathname.new(file) file_dir = file.dirname.realpath input_dir = Pathname.new([:input]).realpath input_file = file.realpath # Simple check to see if we need to create any directories in the output if file_dir == input_dir # File looks like it's in the base directory output_dir = Pathname.new([:output]).realpath else # Looks like we need to create a directory or two output_dir = Pathname.new([:output]).realpath + file_dir.to_s.gsub(input_dir.to_s, "")[1..-1] end # Make directories if they don't already exist make_directory(output_dir) # Initiate compiler compile_haml(input_file, output_dir) end end |
#run_on_removals(paths) ⇒ Object
Called when a watched file is removed
101 102 |
# File 'lib/guard/mthaml.rb', line 101 def run_on_removals(paths) end |
#start ⇒ Object
Run at start
39 40 41 |
# File 'lib/guard/mthaml.rb', line 39 def start run_all if [:run_at_start] end |
#stop ⇒ Object
Stop running
46 47 48 |
# File 'lib/guard/mthaml.rb', line 46 def stop true end |