Sha256: 42edd8caebc70b57ab6ca5819bf900a3bf86bb3d53ff431feace97955b2d43fd

Contents?: true

Size: 817 Bytes

Versions: 11

Compression:

Stored size: 817 Bytes

Contents

module Sinatra
  module AssetPack
    module Css
      def self.preproc(str, assets)
        str.gsub(/url\(["']?(.*?)["']?\)/) { |url|
          path = $1
          file, options = path.split('?')
          local = assets.local_file_for file

          url = if local
            if options.to_s.include?('embed')
              to_data_uri(local)
            else
              BusterHelpers.add_cache_buster(file, local)
            end
          else
            path
          end

          "url(#{url})"
        }
      end

      def self.to_data_uri(file)
        require 'base64'

        data = File.read(file)
        ext  = File.extname(file)
        mime = Sinatra::Base.mime_type(ext)
        b64  = Base64.encode64(data).gsub("\n", '')

        "data:#{mime};base64,#{b64}"
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
sinatra-assetpack-0.1.3 lib/sinatra/assetpack/css.rb
sinatra-assetpack-0.1.2 lib/sinatra/assetpack/css.rb
sinatra-assetpack-0.1.1 lib/sinatra/assetpack/css.rb
sinatra-assetpack-0.1.0 lib/sinatra/assetpack/css.rb
sinatra-assetpack-flexible-compression-0.0.1 lib/sinatra/assetpack/css.rb
sundawg-sinatra-assetpack-fork-0.0.12.pre1 lib/sinatra/assetpack/css.rb
sinatra-assetpack-0.0.12.pre1 lib/sinatra/assetpack/css.rb
sinatra-assetpack-0.0.11 lib/sinatra/assetpack/css.rb
sinatra-assetpack-0.0.10 lib/sinatra/assetpack/css.rb
sinatra-assetpack-0.0.9 lib/sinatra/assetpack/css.rb
sinatra-assetpack-0.0.8 lib/sinatra/assetpack/css.rb