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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69242204acbe5bd5727ac8229e0b977e46d3de50
4
- data.tar.gz: b624f48bcdcc3cdc4122d099a2ac03cf82fbf0dd
3
+ metadata.gz: 6f173928c13b114219779d6b9d7fe0184b30d7d3
4
+ data.tar.gz: 247e619aa251348f6e9c68971936554c293ca769
5
5
  SHA512:
6
- metadata.gz: c63e7a76b71ead2e6a8b40acd26126e3c4a274422ba2afb9ff04b183d09c1bc3dabc014dcc5008adb2f8536d508688642519d63f6b7c26fcc2ff2e0fcb7d57a5
7
- data.tar.gz: 8f72e6e5cce6d5d5ac44db7d6fe2109053e9cab600027c7a7e3a019ca77eea2db67eba7dc3427602f3379253ad37893e0a472caa4280c0a9015c22f837048c92
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
- In a .css, .scss, or .sass file:
23
- ```css
24
- /* icons.css */
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
- In an .erb file:
30
- ```scss
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") %>);
@@ -5,8 +5,18 @@ require "sprockets/svgo/context_extensions"
5
5
  require "sprockets/svgo/sass_functions"
6
6
 
7
7
  module Sprockets::SVGO
8
- def self.uri(options = {})
9
- options = options.merge(datauri: "enc", output: "-")
10
- Command.new(options).execute
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
- command << "--input=#{options[:filename]}"
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
- options = options.merge(filename: asset.filename)
6
-
7
- environment.cache.fetch([:svgo, options.to_s]) do
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
- url = sprockets_context.svgo_asset_data_uri(path.value, options.symbolize_keys)
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
 
@@ -1,5 +1,5 @@
1
1
  module Sprockets
2
2
  module SVGO
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets-svgo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali