rails-sass-images 0.5 → 0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +5 -5
- data/ChangeLog.md +4 -0
- data/Gemfile +0 -4
- data/README.md +4 -2
- data/lib/rails-sass-images/sass/inline.rb +10 -2
- data/lib/rails-sass-images/version.rb +1 -1
- data/spec/app/app/assets/images/square.svg +1 -0
- data/spec/app/app/assets/stylesheets/inline-svg.sass +2 -0
- data/spec/app/config/application.rb +1 -4
- data/spec/plain_spec.rb +25 -14
- data/spec/rails_spec.rb +14 -14
- data/spec/spec_helper.rb +8 -5
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cba13d7d4f12aca10edb470201f8801acbed6889
|
4
|
+
data.tar.gz: 8b10d42d9c70286c922ce0457ce2299cb9b04f1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 026022539d5c88d4ee96af176a84fe2c9c4f780f4989b057cebed86954b19753ebc7c60b7e6f466992b1ab31816914283571198d21ddd6ad0f9fea810f1ec31b
|
7
|
+
data.tar.gz: a79fd8c213914725da089c339e2e9b24f467e90f2bf652137e02d4e5f46ab0424764062098b962ebdc1a2b6b8b86536a297e6887bdb6c4ff10d831f6135eb567
|
data/.travis.yml
CHANGED
data/ChangeLog.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Rails Sass Images
|
1
|
+
# Rails Sass Images [](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
|
-
|
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
|
-
|
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
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"><path d="M0,0h1v1H0" fill="#ff0000"/></svg>
|
data/spec/plain_spec.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
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
|
-
|
55
|
+
expect {
|
50
56
|
@assets['wrong-inline.css']
|
51
|
-
}.
|
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
|
-
|
62
|
+
expect {
|
57
63
|
@assets['wrong-inline.css']
|
58
|
-
}.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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"
|
data/spec/rails_spec.rb
CHANGED
@@ -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.
|
12
|
-
response.body.
|
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
|
-
|
16
|
+
expect {
|
17
17
|
get :test, file: 'wrong-inline'
|
18
|
-
}.
|
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.
|
24
|
-
response.body.
|
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.
|
30
|
-
response.body.
|
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.
|
36
|
-
response.body.
|
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.
|
44
|
-
response.body.
|
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.
|
54
|
-
response.body.
|
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"
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
ENV['RAILS_ENV'] ||= 'test'
|
2
2
|
|
3
|
-
|
4
|
-
|
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
|
-
|
10
|
-
|
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.
|
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:
|
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.
|
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
|