sprockets-webp 0.1.2 → 0.2.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 +4 -4
- data/README.md +29 -5
- data/lib/sprockets-webp.rb +2 -0
- data/lib/sprockets/webp/converter.rb +31 -27
- data/lib/sprockets/webp/railtie.rb +6 -10
- data/lib/sprockets/webp/version.rb +3 -1
- data/sprockets-webp.gemspec +3 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 642506ee4f9e939c6db5a5bc7162cdac1c92d48b
|
4
|
+
data.tar.gz: 030e4ff9ae8e2e17fc0af84c2d8e709585ecbf25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d24725eaadae7d2643f70c74a60531c0aff1e1b7d472c0ec45809595873b9f78445a2bca5c35246103ae179f56ef9eba80c1d649964fa9d11c851f4c83c6377f
|
7
|
+
data.tar.gz: 9835ac60ebcb656697b5825d77b15df2149459d734382955231fbfa74ddb2877e17409c5adcce74ed339a8a4fb4d8c96844d76a5becddab89a868d6dbc03040f
|
data/README.md
CHANGED
@@ -1,20 +1,44 @@
|
|
1
1
|
# Sprockets::WebP
|
2
2
|
|
3
|
-
|
3
|
+
This gem provides a Rails Asset Pipeline hook for converting PNG and JPEG assets to WebP format.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
The main requirement is obviously [libwebp](https://developers.google.com/speed/webp/) itself. Please, consult the [webp-ffi](https://github.com/le0pard/webp-ffi) README for the installation instructions.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
7
|
-
|
11
|
+
If you're using Rails 4 you need to add gem to the ```:production``` group in to your application's Gemfile:
|
12
|
+
|
13
|
+
group :produciton do
|
14
|
+
# ...
|
15
|
+
gem 'sprockets-webp'
|
16
|
+
# ...
|
17
|
+
end
|
18
|
+
|
19
|
+
In case of Rails 3, add it to the ```:assets``` group:
|
8
20
|
|
9
|
-
|
21
|
+
group :assets do
|
22
|
+
# ...
|
23
|
+
gem 'sprockets-webp'
|
24
|
+
# ...
|
25
|
+
end
|
10
26
|
|
11
27
|
And then execute:
|
12
28
|
|
13
29
|
$ bundle
|
14
30
|
|
15
|
-
|
31
|
+
Drop some PNGs and JPGs into ```app/assets/images``` and you can test converter locally with the Rake task:
|
32
|
+
|
33
|
+
$ bundle exec rake assets:precompile RAILS_ENV=production
|
34
|
+
|
35
|
+
### Rails 3 Notice
|
36
|
+
|
37
|
+
Minimal required version of Rails 3 is ```3.2.9```, because of Sprockets ```~> 2.2``` dependency requirement.
|
38
|
+
|
39
|
+
### Rails 4 Notice
|
16
40
|
|
17
|
-
|
41
|
+
I don't have any Rails 4 live apps right now, so I can't test this gem in "real", non synthetic, environment. So, if you have some problems, ideas or suggestions caused your Rails 4 application, please, feel free to contact me.
|
18
42
|
|
19
43
|
## Contributing
|
20
44
|
|
data/lib/sprockets-webp.rb
CHANGED
@@ -4,33 +4,37 @@ require 'tempfile'
|
|
4
4
|
require 'fileutils'
|
5
5
|
require 'webp-ffi'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
7
|
+
module Sprockets
|
8
|
+
module WebP
|
9
|
+
class Converter
|
10
|
+
def self.process(app, context, data)
|
11
|
+
# Application Config alias
|
12
|
+
config = app.config.assets
|
13
|
+
|
14
|
+
# If Application Assets Digests enabled - Add Digest
|
15
|
+
digest = config.digest ? "-#{context.environment.digest.update(data).hexdigest}" : nil
|
16
|
+
file_name = context.logical_path # Original File name w/o extension
|
17
|
+
file_ext = context.pathname.extname # Original File extension
|
18
|
+
webp_file = "#{file_name}#{digest}#{file_ext}.webp" # WebP File fullname
|
19
|
+
|
20
|
+
# WebP File Pathname
|
21
|
+
webp_path = Pathname.new File.join(app.root, 'public', config.prefix, webp_file)
|
22
|
+
|
23
|
+
# Create Directory for both Files, unless already exists
|
24
|
+
FileUtils.mkdir_p(webp_path.dirname) unless Dir.exists?(webp_path.dirname)
|
25
|
+
|
26
|
+
# Create Temp File with Original File binary data
|
27
|
+
Tempfile.open('webp') do |file|
|
28
|
+
file.binmode
|
29
|
+
file.write(data)
|
30
|
+
file.close
|
31
|
+
|
32
|
+
# Encode Original File Temp copy to WebP File Pathname
|
33
|
+
::WebP.encode(file.path, webp_path.to_path)
|
34
|
+
end
|
35
|
+
|
36
|
+
data
|
37
|
+
end
|
32
38
|
end
|
33
|
-
|
34
|
-
data
|
35
39
|
end
|
36
40
|
end
|
@@ -1,18 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Sprockets
|
2
4
|
module WebP
|
3
|
-
class Railtie < Rails::Engine
|
4
|
-
initializer
|
5
|
-
|
6
|
-
assets = app.assets
|
7
|
-
|
8
|
-
assets.register_mime_type 'image/png', '.png'
|
9
|
-
assets.register_mime_type 'image/jpeg', '.jpg'
|
10
|
-
|
11
|
-
assets.register_postprocessor 'image/jpeg', :jpeg_webp do |context, data|
|
5
|
+
class Railtie < ::Rails::Engine
|
6
|
+
initializer :webp do |app|
|
7
|
+
app.assets.register_postprocessor 'image/jpeg', :jpeg_webp do |context, data|
|
12
8
|
Converter.process(app, context, data)
|
13
9
|
end
|
14
10
|
|
15
|
-
assets.register_postprocessor 'image/png', :png_webp do |context, data|
|
11
|
+
app.assets.register_postprocessor 'image/png', :png_webp do |context, data|
|
16
12
|
Converter.process(app, context, data)
|
17
13
|
end
|
18
14
|
end
|
data/sprockets-webp.gemspec
CHANGED
@@ -17,6 +17,9 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^spec/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
+
spec.required_ruby_version = '>= 1.9.3'
|
21
|
+
|
22
|
+
spec.add_dependency 'sprockets', '~> 2.2'
|
20
23
|
spec.add_dependency 'webp-ffi', '~> 0.1.7'
|
21
24
|
|
22
25
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-webp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Riveiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sprockets
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: webp-ffi
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
95
|
requirements:
|
82
96
|
- - '>='
|
83
97
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
98
|
+
version: 1.9.3
|
85
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - '>='
|