middleman-tinify 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +67 -0
- data/Rakefile +14 -0
- data/features/step_definitions/file_size.rb +3 -0
- data/features/support/env.rb +4 -0
- data/features/tinify.feature +29 -0
- data/fixtures/image-app/source/images/panda.png +0 -0
- data/lib/middleman-tinify.rb +32 -0
- data/middleman-tinify.gemspec +27 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eb1129125eee002dd0f7ad02f16f39c2749e7c0b
|
4
|
+
data.tar.gz: 73ba80b5e819409d43e00dd674d999310fa29f4d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 32b4c1ef31422e0fd7ff7f69f93cc00369b10b6c75257154c2001215c77f86cb549c56643595deb940030703aefb2a1457c1549c17d3f7204f75fd13040355cc
|
7
|
+
data.tar.gz: 8a4a1d1fa5d8bae5cbe54390dfe35363e3960974d757cc9de0699a289ad1662fd448a8bc05a770cf4ba72de813cdd0250905c8e8e739803630a4a317709a8741
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Planio GmbH
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
middleman-tinify
|
2
|
+
================
|
3
|
+
|
4
|
+
This minimizes JPGs and PNGs during your middleman builds using the
|
5
|
+
[tinify.com](https://api.tinify.com) API service. In order to use this service,
|
6
|
+
you need to sign up for their service and get an API key.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
Add the `middleman-tinify` gem to your Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
# Gemfile
|
15
|
+
gem 'middleman-tinify'
|
16
|
+
```
|
17
|
+
|
18
|
+
and run
|
19
|
+
|
20
|
+
```
|
21
|
+
bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
|
25
|
+
Usage
|
26
|
+
-----
|
27
|
+
|
28
|
+
Add the following line to your middleman config file:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# config.rb
|
32
|
+
|
33
|
+
activate :tinify, key: 'WfYnAvEjI9pELLsTyh36mKiZbYLZQtZz'
|
34
|
+
```
|
35
|
+
|
36
|
+
By default, all PNGs and JPGs within your `images_dir` will be minified. The
|
37
|
+
following optional configuration is available:
|
38
|
+
|
39
|
+
* `path`: Configure a different path to locate the relevant images. If left
|
40
|
+
blank, the `images_path` will be used. If your images are located in
|
41
|
+
`source/pictures`, use `path: 'pictures'`.
|
42
|
+
|
43
|
+
* `proxy`: You can instruct the API client to make all requests over an HTTP
|
44
|
+
proxy. Set the URL of your proxy server, which can optionally include
|
45
|
+
credentials. Take a look at the [official API
|
46
|
+
documentation](https://tinypng.com/developers/reference/ruby) of the `tinify`
|
47
|
+
gem for an example.
|
48
|
+
|
49
|
+
|
50
|
+
**N.B.:** Image minification will only be done in the regular build, not in the
|
51
|
+
preview server.
|
52
|
+
|
53
|
+
Running tests
|
54
|
+
-------------
|
55
|
+
|
56
|
+
Checkout this repository and execute the following commands:
|
57
|
+
|
58
|
+
```
|
59
|
+
bundle install
|
60
|
+
TINIFY_KEY=$YOUR_API_KEY rake
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
License
|
65
|
+
-------
|
66
|
+
|
67
|
+
This software is licensed under the MIT License. [View the license](LICENSE).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
7
|
+
t.cucumber_opts = '--color --tags ~@wip --strict'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake/clean'
|
11
|
+
|
12
|
+
task test: ['cucumber']
|
13
|
+
|
14
|
+
task default: :test
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Feature: Minify PNGs
|
2
|
+
|
3
|
+
Scenario: No changes if tinify is not activated
|
4
|
+
Given a fixture app "image-app"
|
5
|
+
And a file named "config.rb" with:
|
6
|
+
"""
|
7
|
+
"""
|
8
|
+
And a successfully built app at "image-app"
|
9
|
+
Then the file "build/images/panda.png" should have 56907 bytes
|
10
|
+
|
11
|
+
|
12
|
+
Scenario: PNGs in images folder are minimized
|
13
|
+
Given a fixture app "image-app"
|
14
|
+
And a file named "config.rb" with:
|
15
|
+
"""
|
16
|
+
activate :tinify, key: ENV['TINIFY_KEY']
|
17
|
+
"""
|
18
|
+
And a successfully built app at "image-app"
|
19
|
+
Then the file "build/images/panda.png" should have 15237 bytes
|
20
|
+
|
21
|
+
Scenario: Image folder may be set explicitly
|
22
|
+
Given a fixture app "image-app"
|
23
|
+
And a file named "config.rb" with:
|
24
|
+
"""
|
25
|
+
set :images_dir, 'pictures'
|
26
|
+
activate :tinify, key: ENV['TINIFY_KEY'], path: 'images'
|
27
|
+
"""
|
28
|
+
And a successfully built app at "image-app"
|
29
|
+
Then the file "build/images/panda.png" should have 15237 bytes
|
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "middleman-core"
|
2
|
+
|
3
|
+
module Middleman
|
4
|
+
class Tinify < Extension
|
5
|
+
option :key, nil, 'API key for api.tinify.com'
|
6
|
+
option :proxy, nil, 'Proxy settings to access tinify.com service (optional)'
|
7
|
+
option :path, nil, 'Path to images to tinify, defaults to :images_dir if not set'
|
8
|
+
|
9
|
+
def initialize(app, options_hash={}, &block)
|
10
|
+
super
|
11
|
+
require 'tinify'
|
12
|
+
|
13
|
+
::Tinify.key = options.key
|
14
|
+
::Tinify.proxy = options.proxy if options.proxy
|
15
|
+
end
|
16
|
+
|
17
|
+
def after_build(builder)
|
18
|
+
source_dir = File.join(app.config[:build_dir], options.path || app.config[:images_dir])
|
19
|
+
prefix = app.config[:build_dir] + File::SEPARATOR
|
20
|
+
|
21
|
+
files = Dir[File.join(source_dir, "**", "*.{jpg,jpeg,png}")]
|
22
|
+
|
23
|
+
files.each do |file|
|
24
|
+
::Tinify.from_file(file).to_file(file)
|
25
|
+
|
26
|
+
builder.thor.say_status :tinified, file.sub(prefix, "")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Middleman::Extensions.register(:tinify) { Middleman::Tinify }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "middleman-tinify"
|
5
|
+
s.version = "0.0.1"
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.authors = ["Gregor Schmidt - Planio GmbH"]
|
8
|
+
s.email = ["support@plan.io"]
|
9
|
+
s.homepage = "https://plan.io"
|
10
|
+
s.summary = %q{Minfiy images in middleman}
|
11
|
+
s.description = %q{Uses tinify service to minimize images during your middleman build.}
|
12
|
+
s.license = "MIT"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_runtime_dependency("middleman-core", "~> 4.2")
|
19
|
+
s.add_runtime_dependency("tinify", "~> 1.5")
|
20
|
+
|
21
|
+
s.add_development_dependency("aruba")
|
22
|
+
s.add_development_dependency("bundler")
|
23
|
+
s.add_development_dependency("capybara")
|
24
|
+
s.add_development_dependency("cucumber")
|
25
|
+
s.add_development_dependency("middleman-cli")
|
26
|
+
s.add_development_dependency("rake")
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-tinify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregor Schmidt - Planio GmbH
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tinify
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: aruba
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: capybara
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: cucumber
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: middleman-cli
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Uses tinify service to minimize images during your middleman build.
|
126
|
+
email:
|
127
|
+
- support@plan.io
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- Gemfile
|
134
|
+
- LICENSE
|
135
|
+
- README.md
|
136
|
+
- Rakefile
|
137
|
+
- features/step_definitions/file_size.rb
|
138
|
+
- features/support/env.rb
|
139
|
+
- features/tinify.feature
|
140
|
+
- fixtures/image-app/source/images/panda.png
|
141
|
+
- lib/middleman-tinify.rb
|
142
|
+
- middleman-tinify.gemspec
|
143
|
+
homepage: https://plan.io
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata: {}
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 2.6.13
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: Minfiy images in middleman
|
167
|
+
test_files:
|
168
|
+
- features/step_definitions/file_size.rb
|
169
|
+
- features/support/env.rb
|
170
|
+
- features/tinify.feature
|