hoist option values out of helper to merged module as config
This commit is contained in:
@ -1,4 +1,17 @@
|
||||
module Merged
|
||||
|
||||
# Quite simple mapping from name to usually a selection of values.
|
||||
# Options have type that can be set but usually is inferred from
|
||||
# wether there is one values (select) other wise text.
|
||||
# date is also supported.
|
||||
#
|
||||
# a corresponding ./app/views/merged/sections/_option_form_TYPE.haml
|
||||
# nust exist to render the type.
|
||||
#
|
||||
# Also values may be provided by a module function/attribute on Merged.
|
||||
# eg option text_color (also shade_color) have a Merged.text_color that return a
|
||||
# hash. In this case so it is easy to customize the colors of the app.
|
||||
#
|
||||
class OptionDefinition < SharedBase
|
||||
|
||||
fields :name , :default , :description , :values , :type
|
||||
@ -13,11 +26,13 @@ module Merged
|
||||
end
|
||||
|
||||
def has_values?
|
||||
return true if Merged.respond_to?( name.to_sym )
|
||||
return false if attributes[:values].nil?
|
||||
! attributes[:values].empty?
|
||||
end
|
||||
|
||||
def values
|
||||
return Merged.send(name.to_sym).keys if Merged.respond_to?( name.to_sym )
|
||||
return [] unless has_values?
|
||||
attributes[:values].split(" ")
|
||||
end
|
||||
|
Reference in New Issue
Block a user