Sha256: e5efe3ba31640f076b57ac309f56d115f664122734c69424b6d5a403ecc78912

Contents?: true

Size: 553 Bytes

Versions: 1

Compression:

Stored size: 553 Bytes

Contents

require 'mime-types'

module RailsSassImages::Sass
  # 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')
  def inline(path)
    asset = RailsSassImages.asset(path)

    mime = MIME::Types.type_for(asset.to_s).first.content_type
    file = asset.read
    file = [file].flatten.pack('m').gsub("\n", '')

    Sass::Script::String.new("url('data:#{mime};base64,#{file}')")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails-sass-images-0.5 lib/rails-sass-images/sass/inline.rb