Created
October 8, 2010 22:03
-
-
Save chriseppstein/617650 to your computer and use it in GitHub Desktop.
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
module Sass::Script::Functions | |
def user_color | |
color_values = options[:custom][:user].color. | |
scan(/^#?(..?)(..?)(..?)$/).first. | |
map {|num| num.ljust(2, num).to_i(16)} | |
Sass::Script::Color.new(color_values) | |
end | |
end |
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
map.stylesheet "/stylesheets/*path", :controller => "runtime_stylesheets", :action => "show" |
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
# 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("/")}") | |
options = {:custom => {:user => @user}} | |
# If you're using compass & assuming you have compass-rails installed and activated in production. | |
options.update(Compass.configuration.to_sass_engine_options) | |
engine = Sass::Engine.new(contents, options) | |
render :text => engine.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 |
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
body { | |
background-color: user-color(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for improving on the user_color example. Returning a Sass::Script::Color instead of a Sass::Script::String is much better.