sprockets-svgo 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/sprockets/svgo.rb +13 -3
- data/lib/sprockets/svgo/command.rb +8 -1
- data/lib/sprockets/svgo/context_extensions.rb +3 -4
- data/lib/sprockets/svgo/sass_functions.rb +2 -1
- data/lib/sprockets/svgo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f173928c13b114219779d6b9d7fe0184b30d7d3
|
4
|
+
data.tar.gz: 247e619aa251348f6e9c68971936554c293ca769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eebaa9b7ed82ee870777e0ea5cebf4d44efac8add2279551117d2d8d92f31c00248aa8e138aae135bde16438982d68bc1e048f16132ef039b6052d97ca41cc8
|
7
|
+
data.tar.gz: 2716313df02f6ad9687439021e8db93c2efa845a8866b66887defa7bc5270dc8befe0fd04b97de0af94ced825abf39859e2e37d45820425b54e9d98360c06768
|
data/README.md
CHANGED
@@ -19,15 +19,15 @@ gem 'sprockets-svgo'
|
|
19
19
|
|
20
20
|
## Using
|
21
21
|
|
22
|
-
|
23
|
-
```
|
24
|
-
|
22
|
+
With SASS
|
23
|
+
```scss
|
24
|
+
// icons.scss
|
25
25
|
.bold {
|
26
26
|
background-image: svgo-data-uri("images/bold.svg");
|
27
27
|
}
|
28
28
|
```
|
29
|
-
|
30
|
-
```
|
29
|
+
With ERB
|
30
|
+
```css
|
31
31
|
/* icons.css.erb */
|
32
32
|
.bold {
|
33
33
|
background-image: url(<%= svgo_asset_data_uri("images/bold.svg") %>);
|
data/lib/sprockets/svgo.rb
CHANGED
@@ -5,8 +5,18 @@ require "sprockets/svgo/context_extensions"
|
|
5
5
|
require "sprockets/svgo/sass_functions"
|
6
6
|
|
7
7
|
module Sprockets::SVGO
|
8
|
-
|
9
|
-
options =
|
10
|
-
|
8
|
+
class << self
|
9
|
+
def uri(options = {})
|
10
|
+
options = options.merge(datauri: "enc", output: "-")
|
11
|
+
Command.new(options).execute
|
12
|
+
end
|
13
|
+
|
14
|
+
def cache_key
|
15
|
+
@cache_key ||= "#{name}:#{VERSION}:svgo:#{version}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def version
|
19
|
+
@version ||= Command.new(version: true).execute
|
20
|
+
end
|
11
21
|
end
|
12
22
|
end
|
@@ -39,7 +39,10 @@ class Sprockets::SVGO::Command
|
|
39
39
|
|
40
40
|
def execute
|
41
41
|
command = [svgo_path]
|
42
|
-
|
42
|
+
|
43
|
+
if options[:filename]
|
44
|
+
command << "--input=#{options[:filename]}"
|
45
|
+
end
|
43
46
|
|
44
47
|
if options[:output]
|
45
48
|
command << "--output #{options[:output]}"
|
@@ -69,6 +72,10 @@ class Sprockets::SVGO::Command
|
|
69
72
|
command << "--precision=#{options[:precision]}"
|
70
73
|
end
|
71
74
|
|
75
|
+
if options[:version]
|
76
|
+
command << "--version"
|
77
|
+
end
|
78
|
+
|
72
79
|
`#{command.join(" ")}`.chomp
|
73
80
|
end
|
74
81
|
|
@@ -2,10 +2,9 @@ module Sprockets
|
|
2
2
|
class Context
|
3
3
|
def svgo_asset_data_uri(path, options = {})
|
4
4
|
asset = depend_on_asset(path)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
SVGO.uri(options)
|
5
|
+
cache_key = [SVGO.cache_key, asset.hexdigest, options]
|
6
|
+
environment.cache.fetch(cache_key) do
|
7
|
+
SVGO.uri(options.merge(filename: asset.filename))
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Sprockets
|
2
2
|
module SassProcessor::Functions
|
3
3
|
def svgo_data_uri(path, options = {})
|
4
|
-
|
4
|
+
options = options.transform_values(&:value).symbolize_keys
|
5
|
+
url = sprockets_context.svgo_asset_data_uri(path.value, options)
|
5
6
|
Autoload::Sass::Script::String.new("url(" + url + ")")
|
6
7
|
end
|
7
8
|
|