rails-sass-images 0.5 → 0.6

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: 0a313b8d58d03d3b7bc2820f00b72a769c19f839
4
- data.tar.gz: c7930af69f98b6526ef628164fab6ec83c25f7b3
3
+ metadata.gz: cba13d7d4f12aca10edb470201f8801acbed6889
4
+ data.tar.gz: 8b10d42d9c70286c922ce0457ce2299cb9b04f1d
5
5
  SHA512:
6
- metadata.gz: 7a41f969226d64fa32f8939bba614e242c004f10083f757287ea40267f5a66fb5c622e0f9251838da531eff741afbed5f8282caedb8c4ff579efbf27e9d5ae31
7
- data.tar.gz: 23a160ecca764803a1e26a70376ab36438cc73f509806d00d690008c0131e6165b3908357d359dca959ebd2a7c981a6830f79d5d6eec15918c353c4b8e424e8e
6
+ metadata.gz: 026022539d5c88d4ee96af176a84fe2c9c4f780f4989b057cebed86954b19753ebc7c60b7e6f466992b1ab31816914283571198d21ddd6ad0f9fea810f1ec31b
7
+ data.tar.gz: a79fd8c213914725da089c339e2e9b24f467e90f2bf652137e02d4e5f46ab0424764062098b962ebdc1a2b6b8b86536a297e6887bdb6c4ff10d831f6135eb567
@@ -1,7 +1,7 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- - jruby-19mode
7
- - rbx-2
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - jruby-21mode
@@ -1,3 +1,7 @@
1
+ ### 1.0 “Correggio”
2
+ * Better encoding for SVG (by Alexey Plutalov).
3
+ * Remove official Ruby 1.9 support.
4
+
1
5
  ### 0.5 “Gentile Bellini”
2
6
  * Allow to use gem without Sprockets.
3
7
  * Add `hidpi-background` mixin for repeated backgrounds.
data/Gemfile CHANGED
@@ -6,7 +6,3 @@ gem 'rspec-rails'
6
6
 
7
7
  gem 'rails', '>= 4'
8
8
  gem 'sass-rails', '>= 4'
9
-
10
- gem 'racc', platforms: 'rbx'
11
- gem 'rubysl', platforms: 'rbx'
12
- gem 'rubysl-test-unit', platforms: 'rbx'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rails Sass Images
1
+ # Rails Sass Images [![Build Status](https://travis-ci.org/ai/rails-sass-images.svg)](https://travis-ci.org/ai/rails-sass-images)
2
2
 
3
3
  Sass functions and mixins to inline images and get images size:
4
4
 
@@ -30,7 +30,9 @@ and fonts support:
30
30
  src: inline("my.woff") format('woff')
31
31
  ```
32
32
 
33
- Sponsored by [Evil Martians](http://evilmartians.com/).
33
+ <a href="https://evilmartians.com/?utm_source=rails-sass-images">
34
+ <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
35
+ </a>
34
36
 
35
37
  ## Features
36
38
 
@@ -1,3 +1,4 @@
1
+ require 'cgi'
1
2
  require 'mime-types'
2
3
 
3
4
  module RailsSassImages::Sass
@@ -14,8 +15,15 @@ module RailsSassImages::Sass
14
15
 
15
16
  mime = MIME::Types.type_for(asset.to_s).first.content_type
16
17
  file = asset.read
17
- file = [file].flatten.pack('m').gsub("\n", '')
18
18
 
19
- Sass::Script::String.new("url('data:#{mime};base64,#{file}')")
19
+ if mime == 'image/svg+xml'
20
+ file = CGI::escape(file).gsub('+', '%20')
21
+ encoding = 'charset=utf-8'
22
+ else
23
+ file = [file].flatten.pack('m').gsub("\n", '')
24
+ encoding = 'base64'
25
+ end
26
+
27
+ Sass::Script::String.new("url('data:#{mime};#{encoding},#{file}')")
20
28
  end
21
29
  end
@@ -1,3 +1,3 @@
1
1
  module RailsSassImages
2
- VERSION = '0.5'.freeze unless defined? RailsSassImages::VERSION
2
+ VERSION = '0.6'.freeze unless defined? RailsSassImages::VERSION
3
3
  end
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"><path d="M0,0h1v1H0" fill="#ff0000"/></svg>
@@ -0,0 +1,2 @@
1
+ .icon
2
+ background: inline("square.svg")
@@ -9,10 +9,7 @@ end
9
9
 
10
10
  module App
11
11
  class Application < Rails::Application
12
- config.encoding = "utf-8"
13
- config.assets.enabled = true
14
- config.assets.version = '1.0'
15
-
12
+ config.encoding = 'utf-8'
16
13
  config.secret_key_base = 'foo'
17
14
  end
18
15
  end
@@ -16,6 +16,12 @@ describe RailsSassImages do
16
16
  "/assets/#{path}"
17
17
  end
18
18
  end
19
+
20
+ @assets.context_class.instance_eval do
21
+ def sass_config
22
+ { }
23
+ end
24
+ end
19
25
  end
20
26
 
21
27
  after do
@@ -26,36 +32,36 @@ describe RailsSassImages do
26
32
 
27
33
  it "loads from dir" do
28
34
  RailsSassImages.load_from = DIR.join('app/app/assets/images')
29
- @assets['size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
35
+ expect(@assets['size.css'].to_s).to eq ".icon{width:4px;height:6px}\n"
30
36
  end
31
37
 
32
38
  it "loads by default from current dir" do
33
39
  RailsSassImages.load_from = '.'
34
- @assets['relative.css'].to_s.should == ".icon{width:4px;height:6px}\n"
40
+ expect(@assets['relative.css'].to_s).to eq ".icon{width:4px;height:6px}\n"
35
41
  end
36
42
 
37
43
  it "loads assets from sprockets" do
38
44
  RailsSassImages.load_from = @assets
39
- @assets['size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
45
+ expect(@assets['size.css'].to_s).to eq ".icon{width:4px;height:6px}\n"
40
46
  end
41
47
 
42
48
  it "loads assets lazy" do
43
49
  RailsSassImages.load_from = proc { @assets }
44
- @assets['size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
50
+ expect(@assets['size.css'].to_s).to eq ".icon{width:4px;height:6px}\n"
45
51
  end
46
52
 
47
53
  it "raises error on unknown file in assets" do
48
54
  RailsSassImages.load_from = @assets
49
- proc {
55
+ expect {
50
56
  @assets['wrong-inline.css']
51
- }.should raise_error(/Can't find asset no\.png/)
57
+ }.to raise_error(/Can't find asset no\.png/)
52
58
  end
53
59
 
54
60
  it "raises error on unknown file in path" do
55
61
  RailsSassImages.load_from = '.'
56
- proc {
62
+ expect {
57
63
  @assets['wrong-inline.css']
58
- }.should raise_error(/Can't find asset no\.png in \./)
64
+ }.to raise_error(/Can't find asset no\.png in \./)
59
65
  end
60
66
 
61
67
  end
@@ -66,25 +72,30 @@ describe RailsSassImages do
66
72
  end
67
73
 
68
74
  it "inlines assets" do
69
- @assets['inline.css'].to_s.should == ".icon{background:#{INLINE}}\n"
75
+ expect(@assets['inline.css'].to_s).to eq ".icon{background:#{INLINE}}\n"
76
+ end
77
+
78
+ it "inlines SVG" do
79
+ expect(@assets['inline-svg.css'].to_s).to eq ".icon{background:#{INLINE_SVG}}\n"
70
80
  end
71
81
 
72
82
  it "gets image size" do
73
- @assets['size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
83
+ expect(@assets['size.css'].to_s).to eq ".icon{width:4px;height:6px}\n"
74
84
  end
75
85
 
76
86
  it "gets image size by mixin" do
77
- @assets['image-size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
87
+ expect(@assets['image-size.css'].to_s).to eq(
88
+ ".icon{width:4px;height:6px}\n")
78
89
  end
79
90
 
80
91
  it "has hidpi-background mixin" do
81
- @assets['hidpi-background.css'].to_s.should == (".icon{" +
92
+ expect(@assets['hidpi-background.css'].to_s).to eq (".icon{" +
82
93
  "background-image:url(/assets/monolith.png);" +
83
94
  "background-size:2px 3px}\n")
84
95
  end
85
96
 
86
97
  it "has hidpi-image mixin" do
87
- @assets['hidpi-image.css'].to_s.should == ".icon{" +
98
+ expect(@assets['hidpi-image.css'].to_s).to eq ".icon{" +
88
99
  "width:2px;height:3px;" +
89
100
  "background-image:url(/assets/monolith.png);" +
90
101
  "background-size:2px 3px;" +
@@ -92,7 +103,7 @@ describe RailsSassImages do
92
103
  end
93
104
 
94
105
  it "has hidpi-inline mixin" do
95
- @assets['hidpi-inline.css'].to_s.should == ".icon{" +
106
+ expect(@assets['hidpi-inline.css'].to_s).to eq ".icon{" +
96
107
  "width:2px;height:3px;" +
97
108
  "background:#{INLINE} no-repeat;" +
98
109
  "background-size:2px 3px}\n"
@@ -8,40 +8,40 @@ describe CssController, type: :controller do
8
8
 
9
9
  it "inlines assets" do
10
10
  get :test, file: 'inline'
11
- response.should be_success
12
- response.body.should == ".icon{background:#{INLINE}}\n"
11
+ expect(response).to be_success
12
+ expect(response.body).to eq ".icon{background:#{INLINE}}\n"
13
13
  end
14
14
 
15
15
  it "raises error on unknown file" do
16
- proc {
16
+ expect {
17
17
  get :test, file: 'wrong-inline'
18
- }.should raise_error(/Can't find asset no\.png/)
18
+ }.to raise_error(/Can't find asset no\.png/)
19
19
  end
20
20
 
21
21
  it "gets image size" do
22
22
  get :test, file: 'size'
23
- response.should be_success
24
- response.body.should == ".icon{width:4px;height:6px}\n"
23
+ expect(response).to be_success
24
+ expect(response.body).to eq ".icon{width:4px;height:6px}\n"
25
25
  end
26
26
 
27
27
  it "gets image size by mixin" do
28
28
  get :test, file: 'image-size'
29
- response.should be_success
30
- response.body.should == ".icon{width:4px;height:6px}\n"
29
+ expect(response).to be_success
30
+ expect(response.body).to eq ".icon{width:4px;height:6px}\n"
31
31
  end
32
32
 
33
33
  it "has hidpi-background mixin" do
34
34
  get :test, file: 'hidpi-background'
35
- response.should be_success
36
- response.body.should == ".icon{" +
35
+ expect(response).to be_success
36
+ expect(response.body).to eq ".icon{" +
37
37
  "background-image:url(/assets/monolith.png);" +
38
38
  "background-size:2px 3px}\n"
39
39
  end
40
40
 
41
41
  it "has hidpi-image mixin" do
42
42
  get :test, file: 'hidpi-image'
43
- response.should be_success
44
- response.body.should == ".icon{" +
43
+ expect(response).to be_success
44
+ expect(response.body).to eq ".icon{" +
45
45
  "width:2px;height:3px;" +
46
46
  "background-image:url(/assets/monolith.png);" +
47
47
  "background-size:2px 3px;" +
@@ -50,8 +50,8 @@ describe CssController, type: :controller do
50
50
 
51
51
  it "has hidpi-inline mixin" do
52
52
  get :test, file: 'hidpi-inline'
53
- response.should be_success
54
- response.body.should == ".icon{" +
53
+ expect(response).to be_success
54
+ expect(response.body).to eq ".icon{" +
55
55
  "width:2px;height:3px;" +
56
56
  "background:#{INLINE} no-repeat;" +
57
57
  "background-size:2px 3px}\n"
@@ -1,10 +1,13 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
2
 
3
- DIR = Pathname(__FILE__).dirname
4
- require DIR.join('app/config/environment').to_s
5
- require DIR.join('../lib/rails-sass-images').to_s
3
+ require_relative 'app/config/environment'
4
+ require_relative '../lib/rails-sass-images'
6
5
 
7
6
  require 'rspec/rails'
8
7
 
9
- INLINE = 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAGCAAAAADB' +
10
- 'UmCpAAAAC0lEQVQI12NgwAcAAB4AAW6FRzIAAAAASUVORK5CYII=")'
8
+ DIR = Pathname(__FILE__).dirname
9
+ INLINE = 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAGCAAAAADB' +
10
+ 'UmCpAAAAC0lEQVQI12NgwAcAAB4AAW6FRzIAAAAASUVORK5CYII=")'
11
+ INLINE_SVG = 'url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2F' +
12
+ 'www.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201%201%22%3E%3Cpath' +
13
+ '%20d%3D%22M0%2C0h1v1H0%22%20fill%3D%22%23ff0000%22%2F%3E%3C%2Fsvg%3E%0A")'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-sass-images
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "A.I." Sitnik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 00:00:00.000000000 Z
11
+ date: 2015-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
@@ -83,10 +83,12 @@ files:
83
83
  - rails-sass-images.gemspec
84
84
  - spec/app/.gitignore
85
85
  - spec/app/app/assets/images/monolith.png
86
+ - spec/app/app/assets/images/square.svg
86
87
  - spec/app/app/assets/stylesheets/hidpi-background.sass
87
88
  - spec/app/app/assets/stylesheets/hidpi-image.sass
88
89
  - spec/app/app/assets/stylesheets/hidpi-inline.sass
89
90
  - spec/app/app/assets/stylesheets/image-size.sass
91
+ - spec/app/app/assets/stylesheets/inline-svg.sass
90
92
  - spec/app/app/assets/stylesheets/inline.sass
91
93
  - spec/app/app/assets/stylesheets/relative.sass
92
94
  - spec/app/app/assets/stylesheets/size.sass
@@ -122,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
124
  version: '0'
123
125
  requirements: []
124
126
  rubyforge_project:
125
- rubygems_version: 2.2.0
127
+ rubygems_version: 2.4.5
126
128
  signing_key:
127
129
  specification_version: 4
128
130
  summary: Sass functions and mixins to inline images and get images size