lib/prez/sass_extensions.rb in prez-0.0.2 vs lib/prez/sass_extensions.rb in prez-0.0.3
- old
+ new
@@ -1,16 +1,15 @@
-require "base64"
+require "prez/data_uri"
require "prez/error"
require "prez/files"
require "sass"
module Sass::Script::Functions
def twbs_font_path(path)
assert_type path, :String
path = path.value.sub /[?#].*/, ""
- font_data = Base64.encode64 Prez::Files.contents(path, "font")
- font_data.gsub! "\n", ""
+ contents = Prez::Files.contents path, "font"
extension = path[/\.([^.]*)$/, 1]
case extension
when "eot"
font_type = "application/vnd.ms-fontobject"
@@ -24,10 +23,10 @@
font_type = "application/font-woff2"
else
raise Prez::Error.new("Unknown font extension '#{extension}'")
end
- Sass::Script::Value::String.new("data:#{font_type};base64,#{font_data}")
+ Sass::Script::Value::String.new Prez::DataUri.new(font_type, contents).to_s
rescue Prez::Files::MissingError => e
raise Prez::Error.new("Could not find font: '#{path}'")
end
def twbs_image_path(path)