Skip to content

Instantly share code, notes, and snippets.

@mwawrusch
Created February 19, 2011 07:59
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 mwawrusch/834914 to your computer and use it in GitHub Desktop.
Save mwawrusch/834914 to your computer and use it in GitHub Desktop.
module Models
module Extensions
module ColorScheme
extend ActiveSupport::Concern
included do
cattr_accessor :default_color_scheme
end
module InstanceMethods
# Helper method that creates a css class based on the color scheme selected. If none is selected
# the default color scheme as definied in the initializer will be used.
def color_scheme_css_class
"colorscheme_#{self.color_scheme ? self.color_scheme : self.default_color_scheme}".downcase
end
end
module ClassMethods
# Initilizer for the color scheme.
# include color_scheme in your class and optionally specify the default_color_scheme, which
# can range from a to j
#
# color_scheme default_color_scheme => 'a'
def color_scheme(*fields)
options = fields.extract_options!
self.default_color_scheme = options[:default_color_scheme] || "a"
#default_color_scheme = "a"
field :color_scheme
validates_inclusion_of :color_scheme,
:in => %w[a b c d e f g h i j],
:allow_nil => true
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment