lib/ustyle/sass_functions.rb in ustyle-1.14.0 vs lib/ustyle/sass_functions.rb in ustyle-1.14.10

- old
+ new

@@ -1,28 +1,16 @@ require "sass" require "cgi" require "base64" -require "chunky_png" module Sass::Script::Functions def ustyle_version ::Sass::Script::String.new ::Ustyle::VERSION end declare :ustyle_version, [] - def inline_asset(source) - assert_type source, :String - if Ustyle.sprockets? - ::Sass::Script::String.new "url(#{sprockets_context.asset_data_uri(source.value)})" - else - path = File.join(::Ustyle.assets_path, "images", source.value) - asset_data_uri(path) - end - end - declare :inline_asset, :args => [:source] - def inline_svg(source) assert_type source, :String if Ustyle.sprockets? svg = escaped_svg(sprockets_context.environment.find_asset(source.value).to_s) ::Sass::Script::String.new "url(data:#{Ustyle.mime_type_for(source.value)};charset=utf-8,#{svg})" @@ -36,36 +24,9 @@ def base64encode(string) assert_type string, :String Sass::Script::String.new(Base64.strict_encode64(string.value)) end declare :base64encode, :args => [:string] - - def ustyle_image_path(source) - ustyle_asset_path source, :image - end - declare :ustyle_image_path, :args => [:source] - - def ustyle_asset_path(source, type) - url = if Ustyle.sprockets? - sprockets_context.send(:"#{type}_path", source.value) - else - Ustyle.cloudfront_url(source.value, type) - end - - # sass-only - url ||= source.value.gsub('"', '') - Sass::Script::String.new(url, :string) - end - declare :ustyle_asset_path, :args => [:source, :type] - - def rgba_inline(c, px = 5) - color = ChunkyPNG::Color.rgba(c.red, c.green, c.blue, (c.alpha * 100 * 2.55).round) - image = ChunkyPNG::Image.new(px.to_i, px.to_i, color) - data = Base64.encode64(image.to_blob).gsub("\n", "") - - Sass::Script::String.new("url('data:image/png;base64,#{data}')") - end - declare :rgba_inline, :args => [:c, :px] protected def asset_data_uri(path, svg = false) asset = data(path)