Skip to content

Instantly share code, notes, and snippets.

@ravidsrk
Forked from chriseppstein/custom_functions.rb
Created February 23, 2012 16:32
Show Gist options
  • Save ravidsrk/1893608 to your computer and use it in GitHub Desktop.
Save ravidsrk/1893608 to your computer and use it in GitHub Desktop.
module Sass::Script::Functions
def user_color
sass_user_color = Sass::Script::String.new(options[:custom][:user].color, :string)
assert_type sass_user_color, :String
Sass::Script::String.new("##{sass_user_color.value}")
end
end
map.stylesheet "/stylesheets/*path", :controller => "runtime_stylesheets", :action => "show"
# Note: This might not work at all -- I didn't run it or anything.
class RuntimeStylesheetsController < ApplicationController
before_filter :lookup_user
caches_action :show, :cache_path => :show, :ttl => 24.hours
def show
contents = File.read("#{Rails.root}/app/runtime_stylesheets/#{params[:path].join("/")}")
render :text => Sass::Engine.new(contents, :custom => {:user => @user}).render, :content_type => "text/css"
end
private
def lookup_user
@user = User.find_by_id(session[:user_id])
render :text => "", :status => :not_found unless @user
end
def show_url
"user_stylesheets/#{@user.id}/#{params[:path].join("/")}"
end
end
body {
background-color: user-color();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment