sprockets-svg 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sprockets/svg/cleaner.rb +5 -4
- data/lib/sprockets/svg/version.rb +1 -1
- data/spec/cleaner_spec.rb +30 -0
- data/spec/fixtures/source.svg +12 -0
- data/spec/rails_spec.rb +4 -4
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca8ee0ce977bf5c0d1140265953cf17b190ad529
|
4
|
+
data.tar.gz: 369619d9d2d2104abcd51e0c9601cc20767d2281
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67479b3fa111293006e1f3770120e43eb9bfdef0e6e6fcec190fa22829f40f6e96befa03d5a5f06c9cc2f71aae3c712f6638bff60003d7fae6a75159341418a3
|
7
|
+
data.tar.gz: 8531492ffb4c19fdc63b1ce3ebd89625523a3e1e283bcccda14b944619193728ebbc513c2baad640f0b00737a97fcd747f6ae3111541d6d4270e9b92b16478c1
|
@@ -6,10 +6,11 @@ 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
|
-
document = Nokogiri::XML(svg)
|
10
|
-
document.css('[display=none]').remove
|
11
|
-
document.
|
9
|
+
document = Nokogiri::XML(svg).css('svg')
|
10
|
+
document.css('[display=none]').remove
|
11
|
+
document.xpath('//comment()').remove
|
12
|
+
document.to_s.gsub("\n", '').gsub(/>\s+</, '><').strip
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
15
|
-
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sprockets::Svg::Cleaner do
|
4
|
+
|
5
|
+
let(:source_svg) { File.read(__dir__ + '/fixtures/source.svg') }
|
6
|
+
|
7
|
+
let(:minified_svg) { described_class.process(source_svg) }
|
8
|
+
|
9
|
+
it 'reduce the SVG size from 1064 to 493 bytes' do
|
10
|
+
expect(source_svg.bytesize).to be == 1064
|
11
|
+
expect(minified_svg.bytesize).to be == 493
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'remove comments' do
|
15
|
+
expect(minified_svg).to_not include('<!--')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'remove hidden elements' do
|
19
|
+
expect(minified_svg).to_not include('display="none"')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'remove doctype' do
|
23
|
+
expect(minified_svg).to_not include('DOCTYPE')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'remove the xml header' do
|
27
|
+
expect(minified_svg).to_not include('<?xml')
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
3
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
4
|
+
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
5
|
+
viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
|
6
|
+
<path id="Error_1_" fill="#666B6D" d="M12,0C5.4,0,0,5.4,0,12s5.4,12,12,12s12-5.4,12-12S18.6,0,12,0z M12,4c1.4,0,2.7,0.4,3.9,1
|
7
|
+
L12,8.8L8.8,12L5,15.9c-0.6-1.1-1-2.5-1-3.9C4,7.6,7.6,4,12,4z M12,20c-1.4,0-2.7-0.4-3.9-1l3.9-3.9l3.2-3.2L19,8.1
|
8
|
+
c0.6,1.1,1,2.5,1,3.9C20,16.4,16.4,20,12,20z"/>
|
9
|
+
<path display="none" fill="#B7B7B7" d="M15,2H1C0.447,2,0,2.447,0,3v10c0,0.553,0.447,1,1,1h14c0.553,0,1-0.447,1-1V3
|
10
|
+
C16,2.447,15.553,2,15,2z M8,8.586L3.414,4h9.172L8,8.586z M4.586,8L2,10.586V5.414L4.586,8z M6,9.414l1.647,1.646
|
11
|
+
c0.195,0.195,0.512,0.195,0.707,0L10,9.414L12.586,12H3.414L6,9.414z M11.414,8L14,5.414v5.172L11.414,8z"/>
|
12
|
+
</svg>
|
data/spec/rails_spec.rb
CHANGED
@@ -9,15 +9,15 @@ ASSETS = Pathname.new(COMPILED_ASSETS_PATH)
|
|
9
9
|
|
10
10
|
describe 'Sprockets::Svg' do
|
11
11
|
|
12
|
-
let(:svg_name) { 'facebook-
|
12
|
+
let(:svg_name) { 'facebook-83a94368b23ba9e928820abc2cc12254.svg' }
|
13
13
|
|
14
|
-
let(:png_name) { 'facebook.svg-
|
14
|
+
let(:png_name) { 'facebook.svg-83a94368b23ba9e928820abc2cc12254.png' }
|
15
15
|
|
16
16
|
let(:svg_path) { ASSETS.join(svg_name) }
|
17
17
|
|
18
18
|
let(:png_path) { ASSETS.join(png_name) }
|
19
19
|
|
20
|
-
let(:font_path) { ASSETS.join('fontawesome-webfont-
|
20
|
+
let(:font_path) { ASSETS.join('fontawesome-webfont-be512ff93d0957609a535f25f438ac42.svg') }
|
21
21
|
|
22
22
|
let(:svg_fingerprint) { Digest::MD5.hexdigest(svg_path.read) }
|
23
23
|
|
@@ -44,7 +44,7 @@ describe 'Sprockets::Svg' do
|
|
44
44
|
expect(svg_path).to be_exist
|
45
45
|
expect(png_path).to be_exist
|
46
46
|
|
47
|
-
expect(svg_fingerprint).to be == '
|
47
|
+
expect(svg_fingerprint).to be == '2d8738f246e37a7befd06db8dc2f7e11'
|
48
48
|
# Metadata etc are kinda time dependant, so this assertion is the best I can do.
|
49
49
|
expect(png_source).to be_starts_with("\x89PNG\r\n")
|
50
50
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-svg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,8 @@ files:
|
|
102
102
|
- spec/app/config/environments/test.rb
|
103
103
|
- spec/app/config/initializers/secret_token.rb
|
104
104
|
- spec/app/config/routes.rb
|
105
|
+
- spec/cleaner_spec.rb
|
106
|
+
- spec/fixtures/source.svg
|
105
107
|
- spec/rails_spec.rb
|
106
108
|
- spec/spec_helper.rb
|
107
109
|
- sprockets-svg.gemspec
|
@@ -144,5 +146,7 @@ test_files:
|
|
144
146
|
- spec/app/config/environments/test.rb
|
145
147
|
- spec/app/config/initializers/secret_token.rb
|
146
148
|
- spec/app/config/routes.rb
|
149
|
+
- spec/cleaner_spec.rb
|
150
|
+
- spec/fixtures/source.svg
|
147
151
|
- spec/rails_spec.rb
|
148
152
|
- spec/spec_helper.rb
|