Created
February 19, 2011 07:59
-
-
Save mwawrusch/834914 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 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