sprockets-svg 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +7 -0
- data/README.md +4 -0
- data/Rakefile +6 -0
- data/lib/sprockets/svg/cleaner.rb +0 -1
- data/lib/sprockets/svg/png.rb +8 -6
- data/lib/sprockets/svg/server.rb +16 -3
- data/lib/sprockets/svg/version.rb +1 -1
- data/lib/sprockets/svg.rb +11 -0
- data/spec/app/.gitignore +2 -0
- data/spec/app/Rakefile +2 -0
- data/spec/app/app/assets/fonts/fontawesome-webfont.svg +414 -0
- data/spec/app/app/assets/images/facebook.svg +37 -0
- data/spec/app/app/controllers/application_controller.rb +2 -0
- data/spec/app/app/controllers/assets_controller.rb +7 -0
- data/spec/app/config/application.rb +13 -0
- data/spec/app/config/boot.rb +2 -0
- data/spec/app/config/environment.rb +2 -0
- data/spec/app/config/environments/test.rb +12 -0
- data/spec/app/config/initializers/secret_token.rb +1 -0
- data/spec/app/config/routes.rb +3 -0
- data/spec/app/config.ru +2 -0
- data/spec/rails_spec.rb +67 -0
- data/spec/spec_helper.rb +18 -0
- data/sprockets-svg.gemspec +0 -1
- metadata +35 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 920dbc50372c4ed37c7ae51dde3e0b559ab618ea
|
4
|
+
data.tar.gz: c1d1bed364e46f9d17e53e95f53558da4e450079
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d25bb9d9a0b5533196d2f4a9450c75f87be8391fd21965b208ec92e51a7f155b0859db77d554e2cb067c1bace026f8a47fe3ab5e63388597cd1dfd5f684a118
|
7
|
+
data.tar.gz: e361fd605239e6decd33387bcad7368db8dfc43ad9d55a0c4bcd5b21ca20988c28332c9ef5ffc21ced771b0e7eaf21afb02e9647875cfe303fac8ac3ab25606c
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/byroot/sprockets-svg.svg)](https://travis-ci.org/byroot/sprockets-svg)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/byroot/sprockets-svg.png)](https://codeclimate.com/github/byroot/sprockets-svg)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/sprockets-svg.png)](http://badge.fury.io/rb/sprockets-svg)
|
4
|
+
|
1
5
|
# Sprockets::Svg
|
2
6
|
|
3
7
|
SVG toolchain for sprockets
|
data/Rakefile
CHANGED
@@ -6,7 +6,6 @@ module Sprockets
|
|
6
6
|
# TODO: integrate svgo instead: https://github.com/svg/svgo
|
7
7
|
# See https://github.com/lautis/uglifier on how to integrate a npm package as a gem.
|
8
8
|
def self.process(svg)
|
9
|
-
p :preprocess_svg
|
10
9
|
document = Nokogiri::XML(svg)
|
11
10
|
document.css('[display=none]').remove()
|
12
11
|
document.to_s
|
data/lib/sprockets/svg/png.rb
CHANGED
@@ -10,16 +10,18 @@ module Sprockets
|
|
10
10
|
|
11
11
|
def write_to_with_png_conversion(path, options={})
|
12
12
|
write_to_without_png_conversion(path, options)
|
13
|
-
if
|
14
|
-
Png.convert(path, path
|
13
|
+
if Svg.image?(path)
|
14
|
+
Png.convert(path, png_path(path))
|
15
15
|
end
|
16
16
|
nil
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def png_path(svg_path)
|
20
|
+
if svg_path =~ /^(.*)\-([0-9a-f]+)\.svg$/
|
21
|
+
"#{$1}.svg-#{$2}.png"
|
22
|
+
else
|
23
|
+
"#{svg_path}.png"
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
# TODO: integrate svgo instead: https://github.com/svg/svgo
|
data/lib/sprockets/svg/server.rb
CHANGED
@@ -12,13 +12,13 @@ module Sprockets
|
|
12
12
|
|
13
13
|
def find_asset_with_conversion(path, options = {})
|
14
14
|
convert = false
|
15
|
-
if path.ends_with?('.svg.png')
|
15
|
+
if path.to_s.ends_with?('.svg.png')
|
16
16
|
path = path.gsub(/\.png/, '')
|
17
17
|
convert = true
|
18
18
|
end
|
19
19
|
asset = find_asset_without_conversion(path, options)
|
20
20
|
|
21
|
-
if convert
|
21
|
+
if asset && convert
|
22
22
|
asset = svg_asset_to_static_png(asset)
|
23
23
|
end
|
24
24
|
|
@@ -32,7 +32,20 @@ module Sprockets
|
|
32
32
|
def svg_asset_to_static_png(svg_asset)
|
33
33
|
tmp_path = Tempfile.new(['svg2png', '.svg']).path
|
34
34
|
svg_asset.write_to(tmp_path)
|
35
|
-
::Sprockets::StaticAsset.new(self, svg_asset.logical_path + '.png', Pathname.new(tmp_path + '.png'))
|
35
|
+
png_asset = ::Sprockets::StaticAsset.new(self, svg_asset.logical_path + '.png', Pathname.new(tmp_path + '.png'))
|
36
|
+
png_asset.instance_variable_set(:@digest, svg_asset.digest)
|
37
|
+
png_asset
|
38
|
+
end
|
39
|
+
|
40
|
+
def each_file(*args)
|
41
|
+
return to_enum(__method__) unless block_given?
|
42
|
+
|
43
|
+
super do |path|
|
44
|
+
yield path
|
45
|
+
if Svg.image?(path.to_s)
|
46
|
+
yield Pathname.new(path.to_s + '.png')
|
47
|
+
end
|
48
|
+
end
|
36
49
|
end
|
37
50
|
|
38
51
|
end
|
data/lib/sprockets/svg.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
require 'sprockets/svg/version'
|
2
2
|
|
3
|
+
require 'nokogiri'
|
4
|
+
|
3
5
|
module Sprockets
|
4
6
|
module Svg
|
5
7
|
extend self
|
6
8
|
|
9
|
+
def self.image?(path)
|
10
|
+
return false unless path.ends_with?('.svg')
|
11
|
+
|
12
|
+
document = Nokogiri::XML(File.read(path))
|
13
|
+
svg = document.css('svg')
|
14
|
+
svg.attribute('height') && svg.attribute('width')
|
15
|
+
end
|
16
|
+
|
7
17
|
def install(assets)
|
8
18
|
assets.register_preprocessor 'image/svg+xml', :svg_min do |context, data|
|
9
19
|
Sprockets::Svg::Cleaner.process(data)
|
@@ -20,5 +30,6 @@ require_relative 'svg/server'
|
|
20
30
|
Sprockets::Asset.send(:include, Sprockets::Svg::Png)
|
21
31
|
Sprockets::StaticAsset.send(:include, Sprockets::Svg::Png)
|
22
32
|
Sprockets::Environment.send(:include, Sprockets::Svg::Server)
|
33
|
+
Sprockets::Index.send(:include, Sprockets::Svg::Server)
|
23
34
|
|
24
35
|
require_relative 'svg/railtie' if defined?(Rails)
|
data/spec/app/.gitignore
ADDED
data/spec/app/Rakefile
ADDED