rails-sass-images 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +4 -0
- data/README.md +13 -1
- data/lib/assets/stylesheets/rails-sass-images.sass +1 -0
- data/lib/assets/stylesheets/rails-sass-images/hidpi-background.sass +8 -0
- data/lib/assets/stylesheets/rails-sass-images/hidpi-image.sass +2 -2
- data/lib/rails-sass-images.rb +28 -16
- data/lib/rails-sass-images/railtie.rb +1 -1
- data/lib/rails-sass-images/sass/inline.rb +2 -2
- data/lib/rails-sass-images/sass/size.rb +2 -2
- data/lib/rails-sass-images/version.rb +1 -1
- data/rails-sass-images.gemspec +0 -1
- data/spec/app/app/assets/stylesheets/hidpi-background.sass +4 -0
- data/spec/app/app/assets/stylesheets/relative.sass +3 -0
- data/spec/plain_spec.rb +69 -33
- data/spec/rails_spec.rb +15 -4
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a313b8d58d03d3b7bc2820f00b72a769c19f839
|
4
|
+
data.tar.gz: c7930af69f98b6526ef628164fab6ec83c25f7b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a41f969226d64fa32f8939bba614e242c004f10083f757287ea40267f5a66fb5c622e0f9251838da531eff741afbed5f8282caedb8c4ff579efbf27e9d5ae31
|
7
|
+
data.tar.gz: 23a160ecca764803a1e26a70376ab36438cc73f509806d00d690008c0131e6165b3908357d359dca959ebd2a7c981a6830f79d5d6eec15918c353c4b8e424e8e
|
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -61,7 +61,7 @@ and import mixins in your `application.sass`:
|
|
61
61
|
@import "rails-sass-images"
|
62
62
|
```
|
63
63
|
|
64
|
-
|
64
|
+
### Sprockets
|
65
65
|
|
66
66
|
You can use Rails Sass Images with plain Ruby application with Sprockets.
|
67
67
|
Just install in to Sprockets environment:
|
@@ -77,3 +77,15 @@ and import mixins in your Sass files:
|
|
77
77
|
```sass
|
78
78
|
@import "rails-sass-images"
|
79
79
|
```
|
80
|
+
|
81
|
+
### Other
|
82
|
+
|
83
|
+
You can use Rails Sass Images without Sprockets. Just set dir to load assets:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
require 'rails-sass-images'
|
87
|
+
|
88
|
+
RailsSassImages.load_from = './images/'
|
89
|
+
```
|
90
|
+
|
91
|
+
By default, load dir will be current dir `.`.
|
@@ -0,0 +1,8 @@
|
|
1
|
+
// Set HiDPI (Retina) image background.
|
2
|
+
//
|
3
|
+
// .loader
|
4
|
+
// background-repeat: repeat-x
|
5
|
+
// +hidpi-background("nice/button.png")
|
6
|
+
@mixin hidpi-background($path)
|
7
|
+
background-image: image-url($path)
|
8
|
+
background-size: (image-width($path) / 2) (image-height($path) / 2)
|
data/lib/rails-sass-images.rb
CHANGED
@@ -4,37 +4,49 @@ module RailsSassImages
|
|
4
4
|
# Return asset by file `path` from Sass parser
|
5
5
|
def self.asset(path)
|
6
6
|
path = path.value
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
@load_from = @load_from.call() if @load_from.is_a? Proc
|
9
|
+
|
10
|
+
if @load_from.is_a? Pathname
|
11
|
+
asset = @load_from.join(path)
|
12
|
+
raise "Can't find asset #{path} in #{@load_from}" unless asset.exist?
|
13
|
+
elsif sprockets? @load_from
|
14
|
+
asset = @load_from[path]
|
15
|
+
raise "Can't find asset #{path}" unless asset
|
16
|
+
asset = asset.pathname
|
17
|
+
end
|
18
|
+
|
9
19
|
asset
|
10
20
|
end
|
11
21
|
|
12
22
|
# Set Sprockets environment and add Rails Sass Images styles paths
|
13
23
|
def self.install(sprockets)
|
14
24
|
sprockets.append_path(Pathname(__FILE__).dirname.join('assets/stylesheets'))
|
15
|
-
|
25
|
+
@load_from = sprockets
|
16
26
|
end
|
17
27
|
|
18
|
-
# Set Sprockets environment
|
19
|
-
def self.
|
20
|
-
|
28
|
+
# Set Sprockets environment or assets dir path
|
29
|
+
def self.load_from=(source)
|
30
|
+
source = Pathname(source) if source.is_a? String
|
31
|
+
@load_from = source
|
21
32
|
end
|
22
33
|
|
23
|
-
# Get Sprockets environment
|
24
|
-
def self.
|
25
|
-
|
26
|
-
@assets
|
27
|
-
elsif @assets_loader
|
28
|
-
@assets = @assets_loader.call()
|
29
|
-
end
|
34
|
+
# Get Sprockets environment or assets dir path
|
35
|
+
def self.load_from
|
36
|
+
@load_from
|
30
37
|
end
|
31
38
|
|
32
|
-
|
33
|
-
|
34
|
-
|
39
|
+
private
|
40
|
+
|
41
|
+
# Safe detect is `var` is a Sprockets environment
|
42
|
+
def self.sprockets?(var)
|
43
|
+
return false unless defined? Sprockets
|
44
|
+
var.is_a? Sprockets::Environment or var.is_a? Sprockets::Index
|
35
45
|
end
|
36
46
|
end
|
37
47
|
|
48
|
+
RailsSassImages.load_from = '.'
|
49
|
+
|
38
50
|
dir = Pathname(__FILE__).dirname.join('rails-sass-images')
|
39
51
|
require dir.join('version')
|
40
52
|
require dir.join('sass')
|
@@ -12,8 +12,8 @@ module RailsSassImages::Sass
|
|
12
12
|
def inline(path)
|
13
13
|
asset = RailsSassImages.asset(path)
|
14
14
|
|
15
|
-
mime = MIME::Types.type_for(asset.
|
16
|
-
file = asset.
|
15
|
+
mime = MIME::Types.type_for(asset.to_s).first.content_type
|
16
|
+
file = asset.read
|
17
17
|
file = [file].flatten.pack('m').gsub("\n", '')
|
18
18
|
|
19
19
|
Sass::Script::String.new("url('data:#{mime};base64,#{file}')")
|
@@ -4,12 +4,12 @@ module RailsSassImages::Sass
|
|
4
4
|
# Get image width
|
5
5
|
def image_width(path)
|
6
6
|
asset = RailsSassImages.asset(path)
|
7
|
-
Sass::Script::Number.new(Dimensions.width(asset
|
7
|
+
Sass::Script::Number.new(Dimensions.width(asset), ["px"])
|
8
8
|
end
|
9
9
|
|
10
10
|
# Get image height
|
11
11
|
def image_height(path)
|
12
12
|
asset = RailsSassImages.asset(path)
|
13
|
-
Sass::Script::Number.new(Dimensions.height(asset
|
13
|
+
Sass::Script::Number.new(Dimensions.height(asset), ["px"])
|
14
14
|
end
|
15
15
|
end
|
data/rails-sass-images.gemspec
CHANGED
data/spec/plain_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'sprockets'
|
|
4
4
|
|
5
5
|
describe RailsSassImages do
|
6
6
|
before do
|
7
|
-
@original = RailsSassImages.
|
7
|
+
@original = RailsSassImages.load_from
|
8
8
|
|
9
9
|
@assets = Sprockets::Environment.new
|
10
10
|
@assets.append_path(DIR.join('app/app/assets/images'))
|
@@ -16,51 +16,87 @@ describe RailsSassImages do
|
|
16
16
|
"/assets/#{path}"
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
RailsSassImages.install(@assets)
|
21
19
|
end
|
22
20
|
|
23
21
|
after do
|
24
|
-
RailsSassImages.
|
25
|
-
RailsSassImages.assets_loader = nil
|
22
|
+
RailsSassImages.load_from = @original
|
26
23
|
end
|
27
24
|
|
28
|
-
|
29
|
-
RailsSassImages.assets = nil
|
30
|
-
another = Sprockets::Environment.new
|
25
|
+
describe 'assets loading' do
|
31
26
|
|
32
|
-
|
27
|
+
it "loads from dir" do
|
28
|
+
RailsSassImages.load_from = DIR.join('app/app/assets/images')
|
29
|
+
@assets['size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
32
|
+
it "loads by default from current dir" do
|
33
|
+
RailsSassImages.load_from = '.'
|
34
|
+
@assets['relative.css'].to_s.should == ".icon{width:4px;height:6px}\n"
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
it "loads assets from sprockets" do
|
38
|
+
RailsSassImages.load_from = @assets
|
39
|
+
@assets['size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
@assets['
|
44
|
-
|
45
|
-
end
|
42
|
+
it "loads assets lazy" do
|
43
|
+
RailsSassImages.load_from = proc { @assets }
|
44
|
+
@assets['size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
it "raises error on unknown file in assets" do
|
48
|
+
RailsSassImages.load_from = @assets
|
49
|
+
proc {
|
50
|
+
@assets['wrong-inline.css']
|
51
|
+
}.should raise_error(/Can't find asset no\.png/)
|
52
|
+
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
it "raises error on unknown file in path" do
|
55
|
+
RailsSassImages.load_from = '.'
|
56
|
+
proc {
|
57
|
+
@assets['wrong-inline.css']
|
58
|
+
}.should raise_error(/Can't find asset no\.png in \./)
|
59
|
+
end
|
54
60
|
|
55
|
-
it "has hidpi-image mixin" do
|
56
|
-
@assets['hidpi-image.css'].to_s == ".icon{width:2px;height:3px;" +
|
57
|
-
"background:url(/assets/monolith.png) no-repeat;" +
|
58
|
-
"background-size:2px 3px}\n"
|
59
61
|
end
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
describe 'mixins' do
|
64
|
+
before do
|
65
|
+
RailsSassImages.install(@assets)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "inlines assets" do
|
69
|
+
@assets['inline.css'].to_s.should == ".icon{background:#{INLINE}}\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "gets image size" do
|
73
|
+
@assets['size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "gets image size by mixin" do
|
77
|
+
@assets['image-size.css'].to_s.should == ".icon{width:4px;height:6px}\n"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "has hidpi-background mixin" do
|
81
|
+
@assets['hidpi-background.css'].to_s.should == (".icon{" +
|
82
|
+
"background-image:url(/assets/monolith.png);" +
|
83
|
+
"background-size:2px 3px}\n")
|
84
|
+
end
|
85
|
+
|
86
|
+
it "has hidpi-image mixin" do
|
87
|
+
@assets['hidpi-image.css'].to_s.should == ".icon{" +
|
88
|
+
"width:2px;height:3px;" +
|
89
|
+
"background-image:url(/assets/monolith.png);" +
|
90
|
+
"background-size:2px 3px;" +
|
91
|
+
"background-repeat:no-repeat}\n"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "has hidpi-inline mixin" do
|
95
|
+
@assets['hidpi-inline.css'].to_s.should == ".icon{" +
|
96
|
+
"width:2px;height:3px;" +
|
97
|
+
"background:#{INLINE} no-repeat;" +
|
98
|
+
"background-size:2px 3px}\n"
|
99
|
+
end
|
100
|
+
|
65
101
|
end
|
66
102
|
end
|
data/spec/rails_spec.rb
CHANGED
@@ -30,18 +30,29 @@ describe CssController, type: :controller do
|
|
30
30
|
response.body.should == ".icon{width:4px;height:6px}\n"
|
31
31
|
end
|
32
32
|
|
33
|
+
it "has hidpi-background mixin" do
|
34
|
+
get :test, file: 'hidpi-background'
|
35
|
+
response.should be_success
|
36
|
+
response.body.should == ".icon{" +
|
37
|
+
"background-image:url(/assets/monolith.png);" +
|
38
|
+
"background-size:2px 3px}\n"
|
39
|
+
end
|
40
|
+
|
33
41
|
it "has hidpi-image mixin" do
|
34
42
|
get :test, file: 'hidpi-image'
|
35
43
|
response.should be_success
|
36
|
-
response.body.should == ".icon{
|
37
|
-
"
|
38
|
-
"background-
|
44
|
+
response.body.should == ".icon{" +
|
45
|
+
"width:2px;height:3px;" +
|
46
|
+
"background-image:url(/assets/monolith.png);" +
|
47
|
+
"background-size:2px 3px;" +
|
48
|
+
"background-repeat:no-repeat}\n"
|
39
49
|
end
|
40
50
|
|
41
51
|
it "has hidpi-inline mixin" do
|
42
52
|
get :test, file: 'hidpi-inline'
|
43
53
|
response.should be_success
|
44
|
-
response.body.should == ".icon{
|
54
|
+
response.body.should == ".icon{" +
|
55
|
+
"width:2px;height:3px;" +
|
45
56
|
"background:#{INLINE} no-repeat;" +
|
46
57
|
"background-size:2px 3px}\n"
|
47
58
|
end
|
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.5'
|
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-
|
11
|
+
date: 2014-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: sprockets
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: dimensions
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,6 +70,7 @@ files:
|
|
84
70
|
- README.md
|
85
71
|
- Rakefile
|
86
72
|
- lib/assets/stylesheets/rails-sass-images.sass
|
73
|
+
- lib/assets/stylesheets/rails-sass-images/hidpi-background.sass
|
87
74
|
- lib/assets/stylesheets/rails-sass-images/hidpi-image.sass
|
88
75
|
- lib/assets/stylesheets/rails-sass-images/hidpi-inline.sass
|
89
76
|
- lib/assets/stylesheets/rails-sass-images/image-size.sass
|
@@ -96,10 +83,12 @@ files:
|
|
96
83
|
- rails-sass-images.gemspec
|
97
84
|
- spec/app/.gitignore
|
98
85
|
- spec/app/app/assets/images/monolith.png
|
86
|
+
- spec/app/app/assets/stylesheets/hidpi-background.sass
|
99
87
|
- spec/app/app/assets/stylesheets/hidpi-image.sass
|
100
88
|
- spec/app/app/assets/stylesheets/hidpi-inline.sass
|
101
89
|
- spec/app/app/assets/stylesheets/image-size.sass
|
102
90
|
- spec/app/app/assets/stylesheets/inline.sass
|
91
|
+
- spec/app/app/assets/stylesheets/relative.sass
|
103
92
|
- spec/app/app/assets/stylesheets/size.sass
|
104
93
|
- spec/app/app/assets/stylesheets/wrong-inline.sass
|
105
94
|
- spec/app/app/controllers/application_controller.rb
|