Skip to content

Instantly share code, notes, and snippets.

@gugu
Created September 8, 2012 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugu/3674195 to your computer and use it in GitHub Desktop.
Save gugu/3674195 to your computer and use it in GitHub Desktop.
sass-staticurl-plugin
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