Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

sass-staticurl-plugin

View staticurl.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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
Something went wrong with that request. Please try again.