Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.