kirigami 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +123 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/kirigami.gemspec +29 -0
- data/lib/kirigami.rb +14 -0
- data/lib/kirigami/configuration.rb +83 -0
- data/lib/kirigami/image.rb +89 -0
- data/lib/kirigami/railtie.rb +8 -0
- data/lib/kirigami/version.rb +3 -0
- data/lib/tasks/kirigami/cut.rb +22 -0
- metadata +129 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 86731343cb2b71eedd73d57ccfc13e60fdb88990
|
|
4
|
+
data.tar.gz: df44e2170e043317a0fe116e4699169dbb47651c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 48b81fb05fe359d2ad8dcce90222d09ea627e53ff489c1c19624157eb43524f485e745097032fbe147538659e3d7197f2ff2da078d53d75b7273d4738b797f77
|
|
7
|
+
data.tar.gz: c0a48c86142d16c5259084dbc1548574a23f9f938e3376a9c4512a9be9c803754e7bd9d6702bc30add01249f6b56c7730f0c6b7515fac1da681b97df5cd8252b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
kirigami (0.4.0)
|
|
5
|
+
activesupport
|
|
6
|
+
mini_magick
|
|
7
|
+
rails (>= 3.0.0)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
actioncable (5.1.4)
|
|
13
|
+
actionpack (= 5.1.4)
|
|
14
|
+
nio4r (~> 2.0)
|
|
15
|
+
websocket-driver (~> 0.6.1)
|
|
16
|
+
actionmailer (5.1.4)
|
|
17
|
+
actionpack (= 5.1.4)
|
|
18
|
+
actionview (= 5.1.4)
|
|
19
|
+
activejob (= 5.1.4)
|
|
20
|
+
mail (~> 2.5, >= 2.5.4)
|
|
21
|
+
rails-dom-testing (~> 2.0)
|
|
22
|
+
actionpack (5.1.4)
|
|
23
|
+
actionview (= 5.1.4)
|
|
24
|
+
activesupport (= 5.1.4)
|
|
25
|
+
rack (~> 2.0)
|
|
26
|
+
rack-test (>= 0.6.3)
|
|
27
|
+
rails-dom-testing (~> 2.0)
|
|
28
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
29
|
+
actionview (5.1.4)
|
|
30
|
+
activesupport (= 5.1.4)
|
|
31
|
+
builder (~> 3.1)
|
|
32
|
+
erubi (~> 1.4)
|
|
33
|
+
rails-dom-testing (~> 2.0)
|
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
35
|
+
activejob (5.1.4)
|
|
36
|
+
activesupport (= 5.1.4)
|
|
37
|
+
globalid (>= 0.3.6)
|
|
38
|
+
activemodel (5.1.4)
|
|
39
|
+
activesupport (= 5.1.4)
|
|
40
|
+
activerecord (5.1.4)
|
|
41
|
+
activemodel (= 5.1.4)
|
|
42
|
+
activesupport (= 5.1.4)
|
|
43
|
+
arel (~> 8.0)
|
|
44
|
+
activesupport (5.1.4)
|
|
45
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
46
|
+
i18n (~> 0.7)
|
|
47
|
+
minitest (~> 5.1)
|
|
48
|
+
tzinfo (~> 1.1)
|
|
49
|
+
arel (8.0.0)
|
|
50
|
+
builder (3.2.3)
|
|
51
|
+
concurrent-ruby (1.0.5)
|
|
52
|
+
crass (1.0.2)
|
|
53
|
+
erubi (1.7.0)
|
|
54
|
+
globalid (0.4.0)
|
|
55
|
+
activesupport (>= 4.2.0)
|
|
56
|
+
i18n (0.8.6)
|
|
57
|
+
loofah (2.1.1)
|
|
58
|
+
crass (~> 1.0.2)
|
|
59
|
+
nokogiri (>= 1.5.9)
|
|
60
|
+
mail (2.6.6)
|
|
61
|
+
mime-types (>= 1.16, < 4)
|
|
62
|
+
method_source (0.9.0)
|
|
63
|
+
mime-types (3.1)
|
|
64
|
+
mime-types-data (~> 3.2015)
|
|
65
|
+
mime-types-data (3.2016.0521)
|
|
66
|
+
mini_magick (4.8.0)
|
|
67
|
+
mini_portile2 (2.3.0)
|
|
68
|
+
minitest (5.10.3)
|
|
69
|
+
nio4r (2.1.0)
|
|
70
|
+
nokogiri (1.8.1)
|
|
71
|
+
mini_portile2 (~> 2.3.0)
|
|
72
|
+
rack (2.0.3)
|
|
73
|
+
rack-test (0.7.0)
|
|
74
|
+
rack (>= 1.0, < 3)
|
|
75
|
+
rails (5.1.4)
|
|
76
|
+
actioncable (= 5.1.4)
|
|
77
|
+
actionmailer (= 5.1.4)
|
|
78
|
+
actionpack (= 5.1.4)
|
|
79
|
+
actionview (= 5.1.4)
|
|
80
|
+
activejob (= 5.1.4)
|
|
81
|
+
activemodel (= 5.1.4)
|
|
82
|
+
activerecord (= 5.1.4)
|
|
83
|
+
activesupport (= 5.1.4)
|
|
84
|
+
bundler (>= 1.3.0)
|
|
85
|
+
railties (= 5.1.4)
|
|
86
|
+
sprockets-rails (>= 2.0.0)
|
|
87
|
+
rails-dom-testing (2.0.3)
|
|
88
|
+
activesupport (>= 4.2.0)
|
|
89
|
+
nokogiri (>= 1.6)
|
|
90
|
+
rails-html-sanitizer (1.0.3)
|
|
91
|
+
loofah (~> 2.0)
|
|
92
|
+
railties (5.1.4)
|
|
93
|
+
actionpack (= 5.1.4)
|
|
94
|
+
activesupport (= 5.1.4)
|
|
95
|
+
method_source
|
|
96
|
+
rake (>= 0.8.7)
|
|
97
|
+
thor (>= 0.18.1, < 2.0)
|
|
98
|
+
rake (10.5.0)
|
|
99
|
+
sprockets (3.7.1)
|
|
100
|
+
concurrent-ruby (~> 1.0)
|
|
101
|
+
rack (> 1, < 3)
|
|
102
|
+
sprockets-rails (3.2.1)
|
|
103
|
+
actionpack (>= 4.0)
|
|
104
|
+
activesupport (>= 4.0)
|
|
105
|
+
sprockets (>= 3.0.0)
|
|
106
|
+
thor (0.20.0)
|
|
107
|
+
thread_safe (0.3.6)
|
|
108
|
+
tzinfo (1.2.3)
|
|
109
|
+
thread_safe (~> 0.1)
|
|
110
|
+
websocket-driver (0.6.5)
|
|
111
|
+
websocket-extensions (>= 0.1.0)
|
|
112
|
+
websocket-extensions (0.1.2)
|
|
113
|
+
|
|
114
|
+
PLATFORMS
|
|
115
|
+
ruby
|
|
116
|
+
|
|
117
|
+
DEPENDENCIES
|
|
118
|
+
bundler (~> 1.16.a)
|
|
119
|
+
kirigami!
|
|
120
|
+
rake (~> 10.0)
|
|
121
|
+
|
|
122
|
+
BUNDLED WITH
|
|
123
|
+
1.16.0.pre.2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Bodacious
|
|
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,89 @@
|
|
|
1
|
+
# Kirigami
|
|
2
|
+
|
|
3
|
+
Cut the images in your assets dir to a web-friendly size.
|
|
4
|
+
|
|
5
|
+
Kirigami performs optimisations on your images to ensure they are web-friendly.
|
|
6
|
+
|
|
7
|
+
By default, Kirigami uses the optimisation suggestions recommended by
|
|
8
|
+
[Google's Page Speed Insights](https://developers.google.com/speed/docs/insights/OptimizeImages)
|
|
9
|
+
|
|
10
|
+
In ImageMagick terms, these are:
|
|
11
|
+
|
|
12
|
+
convert original.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB new.jpg
|
|
13
|
+
|
|
14
|
+
Image dimensions, extensions, and filenames are not changed.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Add this line to your application's Gemfile:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem 'kirigami'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
And then execute:
|
|
25
|
+
|
|
26
|
+
$ bundle
|
|
27
|
+
|
|
28
|
+
Or install it yourself as:
|
|
29
|
+
|
|
30
|
+
$ gem install kirigami
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
**WARNING:** This will change the size and quality of images in your Rails application.
|
|
35
|
+
Make sure you have read the documentation and have backed up your images before you proceed
|
|
36
|
+
|
|
37
|
+
`$ rails kirigami:cut`
|
|
38
|
+
|
|
39
|
+
This rake task will go through each of the images specified in your configuration and
|
|
40
|
+
crop their size (if necessary), remove any metadata, and compress them (JPG only).
|
|
41
|
+
|
|
42
|
+
To peek under the hood, check out [lib/kirigami/image.rb](lib/kirigami/image.rb#L28-L41)
|
|
43
|
+
|
|
44
|
+
## Configuration
|
|
45
|
+
|
|
46
|
+
To configure options, add an initializer in `config/initializers/kirigami.rb`
|
|
47
|
+
|
|
48
|
+
``` ruby
|
|
49
|
+
Kirigami.configure do |config|
|
|
50
|
+
|
|
51
|
+
# Only convert images with these extensions (default: %w[ png jpg jpeg gif ])
|
|
52
|
+
self.config.image_extensions ||= %w[ png jpg jpeg gif ]
|
|
53
|
+
|
|
54
|
+
# Create a backup copy of each image before conversion (default: true)
|
|
55
|
+
self.config.safe_mode ||= true
|
|
56
|
+
|
|
57
|
+
# JPEG compression quality (default: "85%")
|
|
58
|
+
self.config.jpeg_compression_quality ||= '85%'
|
|
59
|
+
|
|
60
|
+
# An array of dirpaths where your images are located (defaults: "./app/assets/images")
|
|
61
|
+
self.config.image_paths ||= "[yourapp]/app/assets/images"
|
|
62
|
+
|
|
63
|
+
# Ignore images within these dirpaths (default: [])
|
|
64
|
+
self.config.exclude_paths ||= []
|
|
65
|
+
|
|
66
|
+
# Set minimagick to debug mode (default: false)
|
|
67
|
+
self.config.debug = false
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## TODO
|
|
73
|
+
|
|
74
|
+
- [] Add support for specifying max sizes for individual images
|
|
75
|
+
- [] Add proper tests
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
80
|
+
|
|
81
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
82
|
+
|
|
83
|
+
## Contributing
|
|
84
|
+
|
|
85
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/katanacode/kirigami.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kirigami"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/kirigami.gemspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "kirigami/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "kirigami"
|
|
8
|
+
spec.version = Kirigami::VERSION
|
|
9
|
+
spec.authors = ["Bodacious"]
|
|
10
|
+
spec.email = ["gavin@katanacode.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Cut down your assets/images to web-friendly sizes}
|
|
13
|
+
spec.description = %q{Cut down your assets/images to a web-friendly sizes}
|
|
14
|
+
spec.homepage = "https://github.com/katanacode/kirigami"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
# spec.bindir = "exe"
|
|
21
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_dependency 'mini_magick'
|
|
25
|
+
spec.add_dependency 'activesupport'
|
|
26
|
+
spec.add_dependency 'rails', ">= 3.0.0"
|
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16.a"
|
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
29
|
+
end
|
data/lib/kirigami.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'mini_magick'
|
|
2
|
+
require 'active_support/configurable'
|
|
3
|
+
|
|
4
|
+
require "kirigami/version"
|
|
5
|
+
if defined?(Rails)
|
|
6
|
+
require 'kirigami/railtie'
|
|
7
|
+
else
|
|
8
|
+
warn "Kirigami is currently configured for Rails projects."
|
|
9
|
+
end
|
|
10
|
+
require 'kirigami/image'
|
|
11
|
+
require 'kirigami/configuration'
|
|
12
|
+
module Kirigami
|
|
13
|
+
extend Kirigami::Configuration
|
|
14
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Kirigami
|
|
2
|
+
|
|
3
|
+
module Configuration
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
#
|
|
7
|
+
IMAGE_EXTENSIONS = %w[ png jpg jpeg gif ]
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
#
|
|
11
|
+
EXCLUDE_PATHS = []
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
#
|
|
15
|
+
SAFE_MODE = true
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
#
|
|
19
|
+
JPEG_COMPRESSION_QUALITY = '85%'.freeze
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
#
|
|
23
|
+
JPEG_COLORSPACE = 'RGB'.freeze
|
|
24
|
+
|
|
25
|
+
##
|
|
26
|
+
#
|
|
27
|
+
JPEG_SAMPLING_FACTOR = "4:2:0".freeze
|
|
28
|
+
|
|
29
|
+
##
|
|
30
|
+
#
|
|
31
|
+
JPEG_INTERLACING = "JPEG".freeze
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
#
|
|
35
|
+
DEBUG = false
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def self.extended(klass)
|
|
39
|
+
klass.class_eval do
|
|
40
|
+
include ActiveSupport::Configurable
|
|
41
|
+
|
|
42
|
+
config.image_extensions ||= IMAGE_EXTENSIONS
|
|
43
|
+
|
|
44
|
+
config.image_paths ||= Array(rails_image_paths)
|
|
45
|
+
|
|
46
|
+
config.exclude_paths ||= EXCLUDE_PATHS
|
|
47
|
+
|
|
48
|
+
config.safe_mode ||= SAFE_MODE
|
|
49
|
+
|
|
50
|
+
config.jpeg_compression_quality ||= JPEG_COMPRESSION_QUALITY
|
|
51
|
+
|
|
52
|
+
config.jpeg_colorspace ||= JPEG_COLORSPACE
|
|
53
|
+
|
|
54
|
+
config.jpeg_sampling_factor ||= JPEG_SAMPLING_FACTOR
|
|
55
|
+
|
|
56
|
+
config.jpeg_interlacing ||= JPEG_INTERLACING
|
|
57
|
+
|
|
58
|
+
MiniMagick.configure do |magick|
|
|
59
|
+
magick.debug = Logger::DEBUG if config.debug
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def logger
|
|
66
|
+
@logger ||= Logger.new($stdout, level: config.debug ? Logger::DEBUG : Logger::INFO)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def rails_assets_path
|
|
74
|
+
File.join("app/assets/images/**/*\.{%{formats}}")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def rails_image_paths
|
|
78
|
+
rails_assets_path % { formats: config.image_extensions.join(",") }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module Kirigami
|
|
2
|
+
# An Image file to be compressed and cut via Kirigami
|
|
3
|
+
class Image
|
|
4
|
+
|
|
5
|
+
##
|
|
6
|
+
# An ImageMagick Image Geometry for the target file size
|
|
7
|
+
# http://www.imagemagick.org/script/command-line-processing.php#geometry
|
|
8
|
+
#
|
|
9
|
+
# Returns String
|
|
10
|
+
attr_reader :max_size
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
# The filepath of the image to be cut
|
|
15
|
+
#
|
|
16
|
+
# Returns Pathname
|
|
17
|
+
attr_reader :path
|
|
18
|
+
|
|
19
|
+
# Create a new Image
|
|
20
|
+
#
|
|
21
|
+
# max_size - An ImageSize to specify the size and name of image.
|
|
22
|
+
def initialize(path, max_size)
|
|
23
|
+
@path = path
|
|
24
|
+
@max_size = max_size
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Cuts the File down to size! Creates a backup copy first, if required.
|
|
28
|
+
def cut!
|
|
29
|
+
create_backup_copy
|
|
30
|
+
MiniMagick::Tool::Mogrify.new do |mogrify|
|
|
31
|
+
mogrify.resize(max_size)
|
|
32
|
+
mogrify.strip
|
|
33
|
+
if jpeg?
|
|
34
|
+
mogrify.colorspace(Kirigami.config.jpeg_colorspace)
|
|
35
|
+
mogrify.sampling_factor(Kirigami.config.jpeg_sampling_factor)
|
|
36
|
+
mogrify.interlace(Kirigami.config.jpeg_interlacing)
|
|
37
|
+
mogrify.quality(Kirigami.config.jpeg_compression_quality)
|
|
38
|
+
end
|
|
39
|
+
mogrify << target_filepath
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# Create a backup copy of the File first
|
|
48
|
+
def create_backup_copy
|
|
49
|
+
FileUtils.cp(target_filepath, backup_filepath) if Kirigami.config.safe_mode
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# The absolute filepath for the target File
|
|
53
|
+
#
|
|
54
|
+
# Returns Pathname
|
|
55
|
+
def target_filepath
|
|
56
|
+
File.join(File.dirname(path), filename)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# The filename for the target File
|
|
60
|
+
#
|
|
61
|
+
# Returns String
|
|
62
|
+
def filename
|
|
63
|
+
File.basename(path)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# The filename for the backup File. Uses {filename} + ".BAK"
|
|
67
|
+
#
|
|
68
|
+
# Returns String
|
|
69
|
+
def backup_filename
|
|
70
|
+
File.basename(path) + ".BAK"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# The absolute filepath for the backup File
|
|
74
|
+
#
|
|
75
|
+
# Returns Pathname
|
|
76
|
+
def backup_filepath
|
|
77
|
+
File.join(File.dirname(path), backup_filename)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Is the target File a JPEG?
|
|
81
|
+
#
|
|
82
|
+
# Returns Boolean
|
|
83
|
+
def jpeg?
|
|
84
|
+
filename.ends_with?(".jpg")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'kirigami'
|
|
2
|
+
|
|
3
|
+
namespace :kirigami do
|
|
4
|
+
|
|
5
|
+
desc "Cuts images down to web-friendly size"
|
|
6
|
+
task :cut do
|
|
7
|
+
bash_pattern = "{" + Kirigami.config.image_paths.join(",") + "}"
|
|
8
|
+
Dir[bash_pattern].each do |image_path|
|
|
9
|
+
exclude_path = Kirigami.config.exclude_paths.detect do |path|
|
|
10
|
+
File.expand_path(image_path).to_s.starts_with?(path.realpath.to_s)
|
|
11
|
+
end
|
|
12
|
+
if exclude_path
|
|
13
|
+
Kirigami.logger.debug("Skipping image because: #{exclude_path} is excluded")
|
|
14
|
+
next
|
|
15
|
+
else
|
|
16
|
+
Kirigami.logger.debug("Processing image: #{image_path}")
|
|
17
|
+
Kirigami::Image.new(image_path, '2400x1600>').tap(&:cut!)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kirigami
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.4.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bodacious
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-10-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: mini_magick
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activesupport
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rails
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 3.0.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 3.0.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: 1.16.a
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 1.16.a
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.0'
|
|
83
|
+
description: Cut down your assets/images to a web-friendly sizes
|
|
84
|
+
email:
|
|
85
|
+
- gavin@katanacode.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".gitignore"
|
|
91
|
+
- Gemfile
|
|
92
|
+
- Gemfile.lock
|
|
93
|
+
- LICENSE.txt
|
|
94
|
+
- README.md
|
|
95
|
+
- Rakefile
|
|
96
|
+
- bin/console
|
|
97
|
+
- bin/setup
|
|
98
|
+
- kirigami.gemspec
|
|
99
|
+
- lib/kirigami.rb
|
|
100
|
+
- lib/kirigami/configuration.rb
|
|
101
|
+
- lib/kirigami/image.rb
|
|
102
|
+
- lib/kirigami/railtie.rb
|
|
103
|
+
- lib/kirigami/version.rb
|
|
104
|
+
- lib/tasks/kirigami/cut.rb
|
|
105
|
+
homepage: https://github.com/katanacode/kirigami
|
|
106
|
+
licenses:
|
|
107
|
+
- MIT
|
|
108
|
+
metadata: {}
|
|
109
|
+
post_install_message:
|
|
110
|
+
rdoc_options: []
|
|
111
|
+
require_paths:
|
|
112
|
+
- lib
|
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - ">="
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '0'
|
|
123
|
+
requirements: []
|
|
124
|
+
rubyforge_project:
|
|
125
|
+
rubygems_version: 2.6.13
|
|
126
|
+
signing_key:
|
|
127
|
+
specification_version: 4
|
|
128
|
+
summary: Cut down your assets/images to web-friendly sizes
|
|
129
|
+
test_files: []
|