class TrustyCms::Config
def define(key, options={})
but at the moment that's only done in testing.
define "your.layout", choose_layout
define "my.layout", choose_layout
choose_layout = TrustyCms::Config::Definition.new(:select_from => lambda {Layout.all.map{|l| [l.name, l.d]}})
It's also possible to reuse a definition by passing it to define:
end
...
config.define 'defaults.page.parts', :default => "Body,Extended"
config.define 'defaults.locale', :select_from => lambda { TrustyCms::AvailableLocales.locales }, :allow_blank => true
TrustyCms.config do |config|
From the main radiant config/initializers/radiant_config.rb:
* :allow_display should be false if the config item should not be showable in radius tags
* :allow_change should be false if the config item can only be set, not changed. Add a default to specify an unchanging config entry.
* :allow_blank should be false if the config item must not be blank or nil
* :validate_with should be a block that will receive a value and return true or false. Validations are also implied by type or select_from.
* :select_from should be a list or hash suitable for passing to options_for_select, or a block that will return such a list at runtime
* :type can be :string, :boolean or :integer. Note that all settings whose key ends in ? are considered boolean.
* :default is the value that will be placed in the database if none has been set already
Can take several options:
define('setting.key', options)
Declares a setting definition that will constrain and support the use of a particular config entry.
def define(key, options={}) called_from = caller.grep(/\/initializers\//).first if options.is_a? TrustyCms::Config::Definition definition = options else key = [options[:prefix], key].join('.') if options[:prefix] end definition ||= TrustyCms::Config::Definition.new(options.merge(:definer => called_from)) definitions[key] = definition if self[key].nil? && !definition.default.nil? begin self[key] = definition.default rescue ActiveRecord::RecordInvalid raise LoadError, "Default configuration invalid: value '#{definition.default}' is not allowed for '#{key}'" end end end