Created
September 8, 2012 11:58
-
-
Save gugu/3674195 to your computer and use it in GitHub Desktop.
sass-staticurl-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubypython" | |
ENV["DJANGO_SETTINGS_MODULE"] = "settings" | |
ENV["PYTHONPATH"] = "." | |
RubyPython.start(:python_exe => ENV["PYTHON_EXECUTABLE_NAME"]) | |
RubyPython.import('imp').load_source("activate_this",File.join(File.dirname(RubyPython::Runtime.python), "activate_this.py")) | |
$versioning = RubyPython.import("staticutils.versioning") | |
$settings = RubyPython.import("django.conf").settings | |
$storage = RubyPython.import("django.core.files.storage") | |
$fs_storage = $storage.FileSystemStorage(location=$settings.VERSIONED_STATIC_ROOT) | |
module Sass::Script::Functions | |
def staticurl(url) | |
assert_type url, :String | |
path, hash = url.value.split('#') | |
version = $versioning.get_file_version(path, $fs_storage) | |
prefixed_path = $versioning.get_versioned_path(path, version) | |
Sass::Script::String.new('url(/static/' + prefixed_path.rubify + (hash ? '#' + hash : '') + ')') | |
end | |
declare :staticurl, :args => [:string] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment