rails-sass-images 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/ChangeLog +2 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +114 -0
- data/LICENSE +165 -0
- data/README.md +60 -0
- data/Rakefile +15 -0
- data/lib/assets/stylesheets/rails-sass-images.sass +3 -0
- data/lib/assets/stylesheets/rails-sass-images/image-size.sass +10 -0
- data/lib/assets/stylesheets/rails-sass-images/retina-image.sass +9 -0
- data/lib/assets/stylesheets/rails-sass-images/retina-inline.sass +9 -0
- data/lib/rails-sass-images.rb +37 -0
- data/lib/rails-sass-images/sass.rb +26 -0
- data/lib/rails-sass-images/sass/inline.rb +39 -0
- data/lib/rails-sass-images/sass/size.rb +33 -0
- data/lib/rails-sass-images/version.rb +3 -0
- data/rails-sass-images.gemspec +23 -0
- data/spec/app/.gitignore +2 -0
- data/spec/app/app/assets/images/monolith.png +0 -0
- data/spec/app/app/assets/stylesheets/image-size.sass +4 -0
- data/spec/app/app/assets/stylesheets/inline.sass +2 -0
- data/spec/app/app/assets/stylesheets/retina-image.sass +4 -0
- data/spec/app/app/assets/stylesheets/retina-inline.sass +4 -0
- data/spec/app/app/assets/stylesheets/size.sass +3 -0
- data/spec/app/app/assets/stylesheets/wrong_inline.sass +2 -0
- data/spec/app/app/controllers/application_controller.rb +2 -0
- data/spec/app/app/controllers/css_controller.rb +6 -0
- data/spec/app/config.ru +2 -0
- data/spec/app/config/application.rb +18 -0
- data/spec/app/config/boot.rb +3 -0
- data/spec/app/config/environment.rb +2 -0
- data/spec/app/config/environments/test.rb +11 -0
- data/spec/app/config/routes.rb +3 -0
- data/spec/sass_spec.rb +48 -0
- data/spec/spec_helper.rb +12 -0
- metadata +138 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format documentation --colour
|
data/.travis.yml
ADDED
data/ChangeLog
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails-sass-images (0.1)
|
5
|
+
dimensions (> 0)
|
6
|
+
rails (>= 3.1)
|
7
|
+
sass-rails (> 0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionmailer (3.2.13)
|
13
|
+
actionpack (= 3.2.13)
|
14
|
+
mail (~> 2.5.3)
|
15
|
+
actionpack (3.2.13)
|
16
|
+
activemodel (= 3.2.13)
|
17
|
+
activesupport (= 3.2.13)
|
18
|
+
builder (~> 3.0.0)
|
19
|
+
erubis (~> 2.7.0)
|
20
|
+
journey (~> 1.0.4)
|
21
|
+
rack (~> 1.4.5)
|
22
|
+
rack-cache (~> 1.2)
|
23
|
+
rack-test (~> 0.6.1)
|
24
|
+
sprockets (~> 2.2.1)
|
25
|
+
activemodel (3.2.13)
|
26
|
+
activesupport (= 3.2.13)
|
27
|
+
builder (~> 3.0.0)
|
28
|
+
activerecord (3.2.13)
|
29
|
+
activemodel (= 3.2.13)
|
30
|
+
activesupport (= 3.2.13)
|
31
|
+
arel (~> 3.0.2)
|
32
|
+
tzinfo (~> 0.3.29)
|
33
|
+
activeresource (3.2.13)
|
34
|
+
activemodel (= 3.2.13)
|
35
|
+
activesupport (= 3.2.13)
|
36
|
+
activesupport (3.2.13)
|
37
|
+
i18n (= 0.6.1)
|
38
|
+
multi_json (~> 1.0)
|
39
|
+
arel (3.0.2)
|
40
|
+
builder (3.0.4)
|
41
|
+
diff-lcs (1.2.3)
|
42
|
+
dimensions (1.2.0)
|
43
|
+
erubis (2.7.0)
|
44
|
+
hike (1.2.2)
|
45
|
+
i18n (0.6.1)
|
46
|
+
journey (1.0.4)
|
47
|
+
json (1.7.7)
|
48
|
+
mail (2.5.3)
|
49
|
+
i18n (>= 0.4.0)
|
50
|
+
mime-types (~> 1.16)
|
51
|
+
treetop (~> 1.4.8)
|
52
|
+
mime-types (1.22)
|
53
|
+
multi_json (1.7.2)
|
54
|
+
polyglot (0.3.3)
|
55
|
+
rack (1.4.5)
|
56
|
+
rack-cache (1.2)
|
57
|
+
rack (>= 0.4)
|
58
|
+
rack-ssl (1.3.3)
|
59
|
+
rack
|
60
|
+
rack-test (0.6.2)
|
61
|
+
rack (>= 1.0)
|
62
|
+
rails (3.2.13)
|
63
|
+
actionmailer (= 3.2.13)
|
64
|
+
actionpack (= 3.2.13)
|
65
|
+
activerecord (= 3.2.13)
|
66
|
+
activeresource (= 3.2.13)
|
67
|
+
activesupport (= 3.2.13)
|
68
|
+
bundler (~> 1.0)
|
69
|
+
railties (= 3.2.13)
|
70
|
+
railties (3.2.13)
|
71
|
+
actionpack (= 3.2.13)
|
72
|
+
activesupport (= 3.2.13)
|
73
|
+
rack-ssl (~> 1.3.2)
|
74
|
+
rake (>= 0.8.7)
|
75
|
+
rdoc (~> 3.4)
|
76
|
+
thor (>= 0.14.6, < 2.0)
|
77
|
+
rake (10.0.4)
|
78
|
+
rdoc (3.12.2)
|
79
|
+
json (~> 1.4)
|
80
|
+
rspec-core (2.13.1)
|
81
|
+
rspec-expectations (2.13.0)
|
82
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
83
|
+
rspec-mocks (2.13.1)
|
84
|
+
rspec-rails (2.13.0)
|
85
|
+
actionpack (>= 3.0)
|
86
|
+
activesupport (>= 3.0)
|
87
|
+
railties (>= 3.0)
|
88
|
+
rspec-core (~> 2.13.0)
|
89
|
+
rspec-expectations (~> 2.13.0)
|
90
|
+
rspec-mocks (~> 2.13.0)
|
91
|
+
sass (3.2.7)
|
92
|
+
sass-rails (3.2.6)
|
93
|
+
railties (~> 3.2.0)
|
94
|
+
sass (>= 3.1.10)
|
95
|
+
tilt (~> 1.3)
|
96
|
+
sprockets (2.2.2)
|
97
|
+
hike (~> 1.2)
|
98
|
+
multi_json (~> 1.0)
|
99
|
+
rack (~> 1.0)
|
100
|
+
tilt (~> 1.1, != 1.3.0)
|
101
|
+
thor (0.18.1)
|
102
|
+
tilt (1.3.7)
|
103
|
+
treetop (1.4.12)
|
104
|
+
polyglot
|
105
|
+
polyglot (>= 0.3.1)
|
106
|
+
tzinfo (0.3.37)
|
107
|
+
|
108
|
+
PLATFORMS
|
109
|
+
ruby
|
110
|
+
|
111
|
+
DEPENDENCIES
|
112
|
+
rails-sass-images!
|
113
|
+
rake
|
114
|
+
rspec-rails
|
data/LICENSE
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Rails Sass Images
|
2
|
+
|
3
|
+
Sass functions and mixins to inline images and get images size:
|
4
|
+
|
5
|
+
```sass
|
6
|
+
.icon
|
7
|
+
+image-size("icon.png")
|
8
|
+
background: inline("icon.png")
|
9
|
+
|
10
|
+
.icon-wrap
|
11
|
+
width: image-width("icon.png") + 6px
|
12
|
+
height: image-height("icon.png")
|
13
|
+
```
|
14
|
+
|
15
|
+
with HiDPI (Retina) support:
|
16
|
+
|
17
|
+
```sass
|
18
|
+
.icon
|
19
|
+
+retina-inline("icon.png")
|
20
|
+
|
21
|
+
.background
|
22
|
+
+retina-image("big-image.jpg")
|
23
|
+
```
|
24
|
+
|
25
|
+
and fonts support:
|
26
|
+
|
27
|
+
```sass
|
28
|
+
@font-face
|
29
|
+
font-family: "MyFont"
|
30
|
+
src: inline("my.woff") format('woff')
|
31
|
+
```
|
32
|
+
|
33
|
+
Sponsored by [Evil Martians](http://evilmartians.com/).
|
34
|
+
|
35
|
+
## Features
|
36
|
+
|
37
|
+
Instead of Compass, Rails Sass Images has:
|
38
|
+
|
39
|
+
* Retina support.
|
40
|
+
* Full Assets Pipeline support.
|
41
|
+
* Useful shortcuts.
|
42
|
+
* More file types support.
|
43
|
+
* Smaller and cleaner code.
|
44
|
+
|
45
|
+
If you still need Compass for CSS 3 prefixes,
|
46
|
+
see [Autoprefixer](https://github.com/ai/autoprefixer).
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
Add gem to your Rails `Gemfile`:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
gem "rails-sass-images"
|
54
|
+
```
|
55
|
+
|
56
|
+
and import mixins in your `application.sass`:
|
57
|
+
|
58
|
+
```sass
|
59
|
+
@import "rails-sass-images"
|
60
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
task :clobber_package do
|
11
|
+
rm_r 'pkg' rescue nil
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Delete all generated files'
|
15
|
+
task :clobber => [:clobber_package]
|
@@ -0,0 +1,10 @@
|
|
1
|
+
// Add `width` and `height` properties with image size.
|
2
|
+
// For retina images you can set scale `factor` and width and height
|
3
|
+
// will be divited by this factor.
|
4
|
+
//
|
5
|
+
// .button
|
6
|
+
// +image-size("button/nice.png")
|
7
|
+
// background: image-path("button/nice.png")
|
8
|
+
@mixin image-size($path, $factor: 1)
|
9
|
+
width: image-width($path) / $factor
|
10
|
+
height: image-height($path) / $factor
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Set image sizes and background. It will use retina image, that has twice
|
2
|
+
// size to be clean on Retina screens.
|
3
|
+
//
|
4
|
+
// .button
|
5
|
+
// +retina-image("nice/button.png")
|
6
|
+
@mixin retina-image($path)
|
7
|
+
+image-size($path, 2)
|
8
|
+
background: image-url($path) no-repeat
|
9
|
+
background-size: (image-width($path) / 2) (image-height($path) / 2)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// Set image sizes and background and inline file as base64 data:uri.
|
2
|
+
// It will use retina image, that has twice size to be clean on Retina screens.
|
3
|
+
//
|
4
|
+
// .button
|
5
|
+
// +retina-inline("nice/button.png")
|
6
|
+
@mixin retina-inline($path)
|
7
|
+
+image-size($path, 2)
|
8
|
+
background: inline($path) no-repeat
|
9
|
+
background-size: (image-width($path) / 2) (image-height($path) / 2)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2013 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
|
3
|
+
sponsored by Evil Martians.
|
4
|
+
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
=end
|
18
|
+
|
19
|
+
require 'pathname'
|
20
|
+
dir = Pathname(__FILE__).dirname.join('rails-sass-images')
|
21
|
+
|
22
|
+
module RailsSassImages
|
23
|
+
# Enable `lib/assets/`
|
24
|
+
class Engine < ::Rails::Engine
|
25
|
+
end
|
26
|
+
|
27
|
+
# Return asset by file `path` from Sass parser
|
28
|
+
def self.asset(path)
|
29
|
+
path = path.value
|
30
|
+
asset = Rails.application.assets[path]
|
31
|
+
raise "Can't find asset #{path}" unless asset
|
32
|
+
asset
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
require dir.join('version')
|
37
|
+
require dir.join('sass')
|
@@ -0,0 +1,26 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2013 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
|
3
|
+
sponsored by Evil Martians.
|
4
|
+
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
=end
|
18
|
+
|
19
|
+
require 'sass-rails'
|
20
|
+
|
21
|
+
dir = Pathname(__FILE__).dirname.join('sass')
|
22
|
+
Dir.glob(dir.join('*.rb').to_s) { |ext| require ext }
|
23
|
+
|
24
|
+
module Sass::Script::Functions
|
25
|
+
include RailsSassImages::Sass
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2013 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
|
3
|
+
sponsored by Evil Martians.
|
4
|
+
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
=end
|
18
|
+
|
19
|
+
require 'mime-types'
|
20
|
+
|
21
|
+
module RailsSassImages::Sass
|
22
|
+
# Inline asset file to CSS by data-uri. Can be used for images and fonts.
|
23
|
+
#
|
24
|
+
# .icon
|
25
|
+
# background: inline("icon.png")
|
26
|
+
#
|
27
|
+
# @font-face
|
28
|
+
# font-family: "MyFont"
|
29
|
+
# src: inline("my.woff") format('woff')
|
30
|
+
def inline(path)
|
31
|
+
asset = RailsSassImages.asset(path)
|
32
|
+
|
33
|
+
mime = MIME::Types.type_for(asset.pathname.to_s).first.content_type
|
34
|
+
file = asset.pathname.read
|
35
|
+
file = [file].flatten.pack('m').gsub("\n", '')
|
36
|
+
|
37
|
+
Sass::Script::String.new("url('data:#{mime};base64,#{file}')")
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright 2013 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
|
3
|
+
sponsored by Evil Martians.
|
4
|
+
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
=end
|
18
|
+
|
19
|
+
require 'dimensions'
|
20
|
+
|
21
|
+
module RailsSassImages::Sass
|
22
|
+
# Get image width
|
23
|
+
def image_width(path)
|
24
|
+
asset = RailsSassImages.asset(path)
|
25
|
+
Sass::Script::Number.new(Dimensions.width(asset.pathname), ["px"])
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get image height
|
29
|
+
def image_height(path)
|
30
|
+
asset = RailsSassImages.asset(path)
|
31
|
+
Sass::Script::Number.new(Dimensions.height(asset.pathname), ["px"])
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require './lib/rails-sass-images/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.name = 'rails-sass-images'
|
6
|
+
s.version = RailsSassImages::VERSION.dup
|
7
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
8
|
+
s.summary = 'Sass functions and mixins to inline images ' +
|
9
|
+
'and get images size'
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
13
|
+
s.extra_rdoc_files = ['README.md', 'LICENSE', 'ChangeLog']
|
14
|
+
s.require_path = 'lib'
|
15
|
+
|
16
|
+
s.author = 'Andrey "A.I." Sitnik'
|
17
|
+
s.email = 'andrey@sitnik.ru'
|
18
|
+
s.homepage = 'https://github.com/ai/rails-sass-images'
|
19
|
+
|
20
|
+
s.add_dependency 'sass-rails', ['> 0']
|
21
|
+
s.add_dependency 'dimensions', ['> 0']
|
22
|
+
s.add_dependency 'rails', ['>= 3.1']
|
23
|
+
end
|
data/spec/app/.gitignore
ADDED
Binary file
|
data/spec/app/config.ru
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "action_controller/railtie"
|
4
|
+
require "sprockets/railtie"
|
5
|
+
|
6
|
+
if defined?(Bundler)
|
7
|
+
Bundler.require(*Rails.groups(:assets => %w(development test)))
|
8
|
+
end
|
9
|
+
|
10
|
+
module App
|
11
|
+
class Application < Rails::Application
|
12
|
+
config.encoding = "utf-8"
|
13
|
+
config.assets.enabled = true
|
14
|
+
config.assets.version = '1.0'
|
15
|
+
|
16
|
+
config.sass.style = :compressed
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
App::Application.configure do
|
2
|
+
config.cache_classes = true
|
3
|
+
config.serve_static_assets = true
|
4
|
+
config.static_cache_control = "public, max-age=3600"
|
5
|
+
config.whiny_nils = true
|
6
|
+
config.consider_all_requests_local = true
|
7
|
+
config.action_controller.perform_caching = false
|
8
|
+
config.action_dispatch.show_exceptions = false
|
9
|
+
config.action_controller.allow_forgery_protection = false
|
10
|
+
config.active_support.deprecation = :stderr
|
11
|
+
end
|
data/spec/sass_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe CssController, :type => :controller do
|
4
|
+
after :all do
|
5
|
+
Rails.root.join('tmp').rmtree
|
6
|
+
Rails.root.join('log').rmtree
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should inline assets" do
|
10
|
+
get :test, :file => 'inline'
|
11
|
+
response.should be_success
|
12
|
+
response.body.should == ".icon{background:#{INLINE}}\n"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should raise error on unknown file" do
|
16
|
+
proc {
|
17
|
+
get :test, :file => 'wrong_inline'
|
18
|
+
}.should raise_error(/Can't find asset no\.png/)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should get image size" do
|
22
|
+
get :test, :file => 'size'
|
23
|
+
response.should be_success
|
24
|
+
response.body.should == ".icon{width:4px;height:6px}\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should get image size by mixin" do
|
28
|
+
get :test, :file => 'image-size'
|
29
|
+
response.should be_success
|
30
|
+
response.body.should == ".icon{width:4px;height:6px}\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should has retina-image mixin" do
|
34
|
+
get :test, :file => 'retina-image'
|
35
|
+
response.should be_success
|
36
|
+
response.body.should == ".icon{width:2px;height:3px;" +
|
37
|
+
"background:url(/assets/monolith.png) no-repeat;" +
|
38
|
+
"background-size:2px 3px}\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should has retina-inline mixin" do
|
42
|
+
get :test, :file => 'retina-inline'
|
43
|
+
response.should be_success
|
44
|
+
response.body.should == ".icon{width:2px;height:3px;" +
|
45
|
+
"background:#{INLINE} no-repeat;" +
|
46
|
+
"background-size:2px 3px}\n"
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
ENV['RAILS_ENV'] ||= 'test'
|
3
|
+
|
4
|
+
DIR = Pathname(__FILE__).dirname
|
5
|
+
require DIR.join('app/config/environment').to_s
|
6
|
+
require DIR.join('../lib/rails-sass-images').to_s
|
7
|
+
|
8
|
+
require 'pp'
|
9
|
+
require 'rspec/rails'
|
10
|
+
|
11
|
+
INLINE = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAGCAAAAADB" +
|
12
|
+
"UmCpAAAAC0lEQVQI12NgwAcAAB4AAW6FRzIAAAAASUVORK5CYII=')"
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-sass-images
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrey "A.I." Sitnik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sass-rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>'
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>'
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: dimensions
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>'
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>'
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rails
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
description:
|
63
|
+
email: andrey@sitnik.ru
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files:
|
67
|
+
- README.md
|
68
|
+
- LICENSE
|
69
|
+
- ChangeLog
|
70
|
+
files:
|
71
|
+
- .gitignore
|
72
|
+
- .rspec
|
73
|
+
- .travis.yml
|
74
|
+
- ChangeLog
|
75
|
+
- Gemfile
|
76
|
+
- Gemfile.lock
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/assets/stylesheets/rails-sass-images.sass
|
81
|
+
- lib/assets/stylesheets/rails-sass-images/image-size.sass
|
82
|
+
- lib/assets/stylesheets/rails-sass-images/retina-image.sass
|
83
|
+
- lib/assets/stylesheets/rails-sass-images/retina-inline.sass
|
84
|
+
- lib/rails-sass-images.rb
|
85
|
+
- lib/rails-sass-images/sass.rb
|
86
|
+
- lib/rails-sass-images/sass/inline.rb
|
87
|
+
- lib/rails-sass-images/sass/size.rb
|
88
|
+
- lib/rails-sass-images/version.rb
|
89
|
+
- rails-sass-images.gemspec
|
90
|
+
- spec/app/.gitignore
|
91
|
+
- spec/app/app/assets/images/monolith.png
|
92
|
+
- spec/app/app/assets/stylesheets/image-size.sass
|
93
|
+
- spec/app/app/assets/stylesheets/inline.sass
|
94
|
+
- spec/app/app/assets/stylesheets/retina-image.sass
|
95
|
+
- spec/app/app/assets/stylesheets/retina-inline.sass
|
96
|
+
- spec/app/app/assets/stylesheets/size.sass
|
97
|
+
- spec/app/app/assets/stylesheets/wrong_inline.sass
|
98
|
+
- spec/app/app/controllers/application_controller.rb
|
99
|
+
- spec/app/app/controllers/css_controller.rb
|
100
|
+
- spec/app/config.ru
|
101
|
+
- spec/app/config/application.rb
|
102
|
+
- spec/app/config/boot.rb
|
103
|
+
- spec/app/config/environment.rb
|
104
|
+
- spec/app/config/environments/test.rb
|
105
|
+
- spec/app/config/routes.rb
|
106
|
+
- spec/sass_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
homepage: https://github.com/ai/rails-sass-images
|
109
|
+
licenses: []
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
hash: 973236283843385968
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
hash: 973236283843385968
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.23
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: Sass functions and mixins to inline images and get images size
|
138
|
+
test_files: []
|