Module: RailsSassImages::Sass
- Included in:
- Sass::Script::Functions
- Defined in:
- lib/rails-sass-images/sass/size.rb,
lib/rails-sass-images/sass/inline.rb
Instance Method Summary collapse
-
#image_height(path) ⇒ Object
Get image height.
-
#image_width(path) ⇒ Object
Get image width.
-
#inline(path) ⇒ Object
Inline asset file to CSS by data-uri.
Instance Method Details
#image_height(path) ⇒ Object
Get image height
11 12 13 14 |
# File 'lib/rails-sass-images/sass/size.rb', line 11 def image_height(path) asset = RailsSassImages.asset(path) Sass::Script::Number.new(Dimensions.height(asset), ["px"]) end |
#image_width(path) ⇒ Object
Get image width
5 6 7 8 |
# File 'lib/rails-sass-images/sass/size.rb', line 5 def image_width(path) asset = RailsSassImages.asset(path) Sass::Script::Number.new(Dimensions.width(asset), ["px"]) end |
#inline(path) ⇒ Object
Inline asset file to CSS by data-uri. Can be used for images and fonts.
.icon
background: inline("icon.png")
@font-face
font-family: "MyFont"
src: inline("my.woff") format('woff')
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rails-sass-images/sass/inline.rb', line 13 def inline(path) asset = RailsSassImages.asset(path) mime = MIME::Types.type_for(asset.to_s).first.content_type file = asset.read if mime == 'image/svg+xml' file = CGI::escape(file).gsub('+', '%20') encoding = 'charset=utf-8' else file = [file].flatten.pack('m').gsub("\n", '') encoding = 'base64' end Sass::Script::String.new("url('data:#{mime};#{encoding},#{file}')") end |