Class: Guard::ImageOptim
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::ImageOptim
- Defined in:
- lib/guard/image_optim.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ImageOptim
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 = {}) ⇒ ImageOptim
Initializer
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/guard/image_optim.rb', line 17 def initialize( = {}) = { :input => "images", :nice => 10, :notifications => true, :run_at_start => false, :pngout => false, :svgo => false }.merge() @optimizer = ::ImageOptim.new({ :nice => [:nice], :pngout => [:pngout], :svgo => [:svgo] }) super() if [:input] watchers << ::Guard::Watcher.new(%r{^#{options[:input]}/*.*$}) end end |
Instance Method Details
#reload ⇒ Object
On Guard reload
57 58 59 |
# File 'lib/guard/image_optim.rb', line 57 def reload run_all end |
#run_all ⇒ Object
Run all
64 65 66 |
# File 'lib/guard/image_optim.rb', line 64 def run_all run_on_changes Watcher.match_files(self, Dir.glob(File.join("**", "*.*"))) end |
#run_on_changes(paths) ⇒ Object
Run on changes to watched files
74 75 76 77 78 |
# File 'lib/guard/image_optim.rb', line 74 def run_on_changes(paths) paths.each do |file| optimize! Pathname.new(file).realpath end end |
#run_on_removals(paths) ⇒ Object
Called when a watched file is removed
86 87 |
# File 'lib/guard/image_optim.rb', line 86 def run_on_removals(paths) end |
#start ⇒ Object
Run at start
43 44 45 |
# File 'lib/guard/image_optim.rb', line 43 def start run_all if [:run_at_start] end |
#stop ⇒ Object
Stop running
50 51 52 |
# File 'lib/guard/image_optim.rb', line 50 def stop true end |