Skip to content

Commit

Permalink
Made datauri return the whole url literal instead of the data string.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Norton committed Feb 29, 2012
1 parent aa9dfef commit 19bb659
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions bin/sass
Expand Up @@ -25,6 +25,16 @@ class Scope
end
end

class Url <Sass::Script::Literal
def initialize(url)
super(url)
end

def to_s(opts = {})
"url(\"#{@value}\")"
end
end

class Sass::Tree::Visitors::Perform
alias_method :_visit_import, :visit_import
def visit_import(node)
Expand Down Expand Up @@ -59,9 +69,12 @@ module Sass::Script::Functions
mime = "image/jpg" if name.end_with?(".jpg") || name.end_with?(".jpeg")
file = File.open(Scope.find(string.value), 'rb')
begin
Sass::Script::String.new(
"data:#{mime};base64,#{Base64.encode64(file.read).strip}",
:string)
# love that gsub at the end? ruby's Base64 adds \n's every
# 60 characters. Why? I have no ideas. RFC 2045 doesn't
# say anything about that. It's just the usual ruby community
# gift!
data = Base64.encode64(file.read).strip.gsub("\n", "")
Url.new("data:#{mime};base64,#{data}")
ensure
file.close
end
Expand Down

0 comments on commit 19bb659

Please sign in to comment.