sprockets-exporters_pack 0.1.1
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/LICENSE +21 -0
- data/README.md +48 -0
- data/lib/sprockets/exporters_pack/brotli_exporter.rb +47 -0
- data/lib/sprockets/exporters_pack/version.rb +5 -0
- data/lib/sprockets/exporters_pack.rb +8 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e33a778f3d05da2627213ff45a03343396ce2d94
|
4
|
+
data.tar.gz: 396a53a99d373de16262991092b059feb02749cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac2eb8406e9662ecf347abcbc3bcc1a1be95b6471489feb2209ed84acc65c881212b8a31150d37f96d60e6e2f42c9bfd32d69e58f708c30d9f64d6ae581239fb
|
7
|
+
data.tar.gz: 5dc14143f9ac7df3a8c175fc7bc2481cd7e898c9f71185c19496209e311fe4b0d243083e457536d44522d880307dfee79a1e53879daebef42ae2501a774428f5
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Hans Otto Wirtz
|
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,48 @@
|
|
1
|
+
# Sprockets::ExportersPack
|
2
|
+
|
3
|
+
This gem aims to add some exporters to [sprockets][rails/sprockets], which are currently [under review][PR].
|
4
|
+
|
5
|
+
Currently, it has:
|
6
|
+
- a Brotli exporter, which should be used with [ngx_brotli][google/ngx_brotli].
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your `Gemfile`:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'sprockets-exporters_pack'
|
14
|
+
```
|
15
|
+
|
16
|
+
```bash
|
17
|
+
$ bundle install
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
With Rails, in `application.rb`:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
config.assets.configure do |env|
|
26
|
+
env.register_exporter %w(text/css application/javascript image/svg+xml), Sprockets::ExportersPack::BrotliExporter
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
Without Rails:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
env = Sprockets::Environment.new
|
34
|
+
env.register_exporter %w(text/css application/javascript image/svg+xml), Sprockets::ExportersPack::BrotliExporter
|
35
|
+
```
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Yes please! Open an issue with exporters you want to see added.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
44
|
+
|
45
|
+
[PR]: https://github.com/rails/sprockets/pull/386
|
46
|
+
[rails/sprockets]: https://github.com/rails/sprockets
|
47
|
+
[rails/rails]: https://github.com/rails/rails
|
48
|
+
[google/ngx_brotli]: https://github.com/google/ngx_brotli
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'sprockets/exporters/base'
|
2
|
+
require 'brotli'
|
3
|
+
|
4
|
+
module Sprockets
|
5
|
+
module ExportersPack
|
6
|
+
class BrotliExporter < ::Sprockets::Exporters::Base
|
7
|
+
def setup
|
8
|
+
@brotli_target = "#{ target }.br"
|
9
|
+
end
|
10
|
+
|
11
|
+
def skip?(logger)
|
12
|
+
if ::File.exist?(@brotli_target)
|
13
|
+
logger.debug "Skipping #{ @brotli_target }, already exists"
|
14
|
+
true
|
15
|
+
else
|
16
|
+
logger.info "Writing #{ @brotli_target }"
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
data = File.binread(target)
|
23
|
+
mode = if asset.content_type.match /font|otf/
|
24
|
+
:font
|
25
|
+
elsif asset.content_type.match /text|(application\/(javascript|json|xml))/
|
26
|
+
:text
|
27
|
+
else
|
28
|
+
:generic
|
29
|
+
end
|
30
|
+
brotli = Brotli.deflate(data, mode: mode, quality: self.class.quality)
|
31
|
+
|
32
|
+
write(@brotli_target) do |file|
|
33
|
+
file.write(brotli)
|
34
|
+
file.close
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class << self
|
39
|
+
attr_writer :quality
|
40
|
+
|
41
|
+
def quality
|
42
|
+
@quality || 9
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets-exporters_pack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hans Otto Wirtz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: brotli
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sprockets
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.0.0.beta3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.0.beta3
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- hansottowirtz@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- lib/sprockets/exporters_pack.rb
|
79
|
+
- lib/sprockets/exporters_pack/brotli_exporter.rb
|
80
|
+
- lib/sprockets/exporters_pack/version.rb
|
81
|
+
homepage: https://github.com/hansottowirtz/sprockets-exporters_pack
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.6.8
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Adds multiple exporters to Sprockets
|
105
|
+
test_files: []
|