module RailsSassImages::Sass
Public Instance Methods
image_height(path)
click to toggle source
Get image height
# File lib/rails-sass-images/sass/size.rb, line 11 def image_height(path) asset = RailsSassImages.asset(path) SassC::Script::Value::Number.new(Dimensions.height(asset), ["px"]) end
image_width(path)
click to toggle source
Get image width
# File lib/rails-sass-images/sass/size.rb, line 5 def image_width(path) asset = RailsSassImages.asset(path) SassC::Script::Value::Number.new(Dimensions.width(asset), ["px"]) end
inline(path)
click to toggle source
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')
# File lib/rails-sass-images/sass/inline.rb, line 13 def inline(path) asset = RailsSassImages.asset(path) mimes = MIME::Types.type_for(asset.to_s) raise "Unknown MIME-type for #{ asset.to_s }" unless mimes.first mime = mimes.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 SassC::Script::Value::String.new("url('data:#{mime};#{encoding},#{file}')") end