guard-image_optim 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +21 -0
- data/README.md +40 -0
- data/lib/guard/image_optim/templates/Guardfile +10 -0
- data/lib/guard/image_optim/version.rb +5 -0
- data/lib/guard/image_optim.rb +119 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa42c4ebd0894260ff3d7af55012f6921e70c224
|
4
|
+
data.tar.gz: de324f59e6dc9fe9913f9c8f1214832164f3bdea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c79836f2ef4fd8518c3c3882a6630860ab8f0dab6c37dac5ae7cb9c358fbe37520933abb3cf2fcee747c0554986b86533084181ad4293d1aaf07a5a6ab258a63
|
7
|
+
data.tar.gz: 4983d4541e1a609b751bf182ff840038eadc6b8b031402e55b8c91b0e5ad4b80efef0b0349bdc636acdd70b0e36c6751c7e7bc2ba1ab40fa2aa5e2639ba9b541
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Ezekiel Gabrielse
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Guard::ImageOptim [![Gem Version](https://badge.fury.io/rb/guard-image_optim.svg)](http://badge.fury.io/rb/guard-image_optim)
|
2
|
+
Guard::ImageOptim automatically optimizes your images with image_optim.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add to your `Gemfile`:
|
6
|
+
```ruby
|
7
|
+
gem 'guard-image_optim'
|
8
|
+
```
|
9
|
+
|
10
|
+
Require in your `Guardfile`:
|
11
|
+
```ruby
|
12
|
+
require "guard/image_optim"
|
13
|
+
```
|
14
|
+
|
15
|
+
Or, add the default Guard::MtHaml template to your `Guardfile` by running:
|
16
|
+
```bash
|
17
|
+
$ guard init image_optim
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
###
|
24
|
+
# Sample Guardfile block for Guard::ImageOptim
|
25
|
+
#
|
26
|
+
# :input ("images") set input image directory
|
27
|
+
# :notifications (true) toggle guard notifications
|
28
|
+
# :run_at_start (false) optimize images when guard starts
|
29
|
+
# :pngout (false) toggle pngout for image_optim gem
|
30
|
+
# :svgo (false) toggle svgo for image_optim gem
|
31
|
+
###
|
32
|
+
guard :image_optim, :input => "images"
|
33
|
+
|
34
|
+
```
|
35
|
+
|
36
|
+
## Authors
|
37
|
+
[Ezekiel Gabrielse](http://ezekielg.com)
|
38
|
+
|
39
|
+
## License
|
40
|
+
Graphite is available under the [MIT](http://opensource.org/licenses/MIT) license.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
###
|
2
|
+
# Sample Guardfile block for Guard::ImageOptim
|
3
|
+
#
|
4
|
+
# :input ("images") set input image directory
|
5
|
+
# :notifications (true) toggle guard notifications
|
6
|
+
# :run_at_start (false) optimize images when guard starts
|
7
|
+
# :pngout (false) toggle pngout for image_optim gem
|
8
|
+
# :svgo (false) toggle svgo for image_optim gem
|
9
|
+
###
|
10
|
+
guard :image_optim, :input => "images"
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require "guard"
|
2
|
+
require "guard/plugin"
|
3
|
+
require "guard/watcher"
|
4
|
+
require "pathname"
|
5
|
+
require "image_optim"
|
6
|
+
require "image_optim_pack"
|
7
|
+
|
8
|
+
###
|
9
|
+
# Guard to optimize images
|
10
|
+
###
|
11
|
+
module Guard
|
12
|
+
class ImageOptim < Plugin
|
13
|
+
|
14
|
+
###
|
15
|
+
# Initializer
|
16
|
+
###
|
17
|
+
def initialize(options = {})
|
18
|
+
options = {
|
19
|
+
:input => "images",
|
20
|
+
:notifications => true,
|
21
|
+
:run_at_start => false,
|
22
|
+
:pngout => false,
|
23
|
+
:svgo => false
|
24
|
+
}.merge(options)
|
25
|
+
|
26
|
+
@optimizer = ::ImageOptim.new({
|
27
|
+
:pngout => options[:pngout],
|
28
|
+
:svgo => options[:svgo]
|
29
|
+
})
|
30
|
+
|
31
|
+
super(options)
|
32
|
+
|
33
|
+
if options[:input]
|
34
|
+
watchers << ::Guard::Watcher.new(%r{^#{options[:input]}/*.*$})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
###
|
39
|
+
# Run at start
|
40
|
+
###
|
41
|
+
def start
|
42
|
+
run_all if options[:run_at_start]
|
43
|
+
end
|
44
|
+
|
45
|
+
###
|
46
|
+
# Stop running
|
47
|
+
###
|
48
|
+
def stop
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
###
|
53
|
+
# On Guard reload
|
54
|
+
###
|
55
|
+
def reload
|
56
|
+
run_all
|
57
|
+
end
|
58
|
+
|
59
|
+
###
|
60
|
+
# Run all
|
61
|
+
###
|
62
|
+
def run_all
|
63
|
+
run_on_changes Watcher.match_files(self, Dir.glob(File.join("**", "*.*")))
|
64
|
+
end
|
65
|
+
|
66
|
+
###
|
67
|
+
# Run on changes to watched files
|
68
|
+
#
|
69
|
+
# @param {Array} paths
|
70
|
+
# Paths of changed files
|
71
|
+
###
|
72
|
+
def run_on_changes(paths)
|
73
|
+
paths.each do |file|
|
74
|
+
optimize! Pathname.new(file).realpath
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
###
|
79
|
+
# Called when a watched file is removed
|
80
|
+
#
|
81
|
+
# @param {Array} paths
|
82
|
+
# Paths of changed files
|
83
|
+
####
|
84
|
+
def run_on_removals(paths)
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
###
|
90
|
+
# Optimize file
|
91
|
+
#
|
92
|
+
# @param {String} file
|
93
|
+
###
|
94
|
+
def optimize!(file)
|
95
|
+
begin
|
96
|
+
throw :task_has_failed unless @optimizer.optimize_image! file
|
97
|
+
::Guard::UI.info(color("optimized #{File.basename(file)}", ";32")) if options[:notifications]
|
98
|
+
rescue StandardError => error
|
99
|
+
::Guard::UI.error(color("error optimizing #{File.basename(file)} : #{error}", ";31")) if options[:notifications]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
###
|
104
|
+
# Set message color
|
105
|
+
#
|
106
|
+
# @param {String} message
|
107
|
+
# Text to color
|
108
|
+
# @param {String} color
|
109
|
+
# Color code
|
110
|
+
###
|
111
|
+
def color(message, color)
|
112
|
+
if ::Guard::UI.send(:color_enabled?)
|
113
|
+
"\e[0#{color}m#{message}\e[0m"
|
114
|
+
else
|
115
|
+
message
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-image_optim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ezekiel Gabrielse
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: guard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: image_optim
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.18'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.18'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: image_optim_pack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Guard::ImageOptim automatically optimizes your images with image_optim.
|
56
|
+
email:
|
57
|
+
- ezekg@yahoo.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/guard/image_optim/templates/Guardfile
|
63
|
+
- lib/guard/image_optim/version.rb
|
64
|
+
- lib/guard/image_optim.rb
|
65
|
+
- README.md
|
66
|
+
- LICENSE.md
|
67
|
+
homepage: http://github.com/ezekg/guard-image_optim
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.3.6
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project: guard-image_optim
|
87
|
+
rubygems_version: 2.0.14
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Guard gem for image_optim
|
91
|
+
test_files: []
|