Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move Radiant.config to Radiant.detail

  • Loading branch information...
commit 2f2ac6c329e990ef1529d619899c76966526513e 1 parent 8ce0de6
@saturnflyer saturnflyer authored
View
1  CHANGELOG.md
@@ -2,6 +2,7 @@
# 2.x
+* Rename Radiant.config to Radiant.detail [Jim Gay]
* Remove InheritableClassAttributes [Jim Gay]
* Remove specific autotest support [Jim Gay]
* Remove the notion of Radiant instances [Jim Gay]
View
8 app/controllers/radiant/admin/configuration_controller.rb
@@ -6,7 +6,7 @@ class Admin::ConfigurationController < ::Radiant::AdminController
# Note that configuration is routed as a singular resource so we only deal with show/edit/update
# and the show and edit views determine what set of config values is shown and made editable.
- before_filter :initialize_config
+ before_filter :initialize_detail
only_allow_access_to :edit, :update,
:when => [:admin],
@@ -25,7 +25,7 @@ def edit
def update
if params[:config]
begin
- Radiant.config.transaction do
+ Radiant.detail.transaction do
params["config"].each_pair do |key, value|
@editable_config[key] = Radiant::Config.find_or_create_by_key(key)
@editable_config[key].value = value # validation sets errors on @editable_config['key'] that the helper methods will pick up
@@ -44,8 +44,8 @@ def update
protected
- def initialize_config
- @editable_config = {}
+ def initialize_detail
+ @editable_detail = {}
end
end
View
6 app/controllers/radiant/application_controller.rb
@@ -8,13 +8,13 @@ class ApplicationController < ::ApplicationController
before_filter :set_timezone
before_filter :force_utf8_params if RUBY_VERSION =~ /1\.9/
- attr_accessor :radiant_config, :cache
- attr_reader :pagination_parameters, :radiant_config
+ attr_accessor :cache
+ attr_reader :pagination_parameters, :detail
helper_method :pagination_parameters
def initialize
super
- @radiant_config = Radiant::Config
+ @detail = Radiant::Config
end
# helpers to include additional assets from actions or views
View
2  app/controllers/radiant/site_controller.rb
@@ -90,7 +90,7 @@ def process_page(page)
end
def dev?
- request.host == radiant_config['dev.host'] || request.host =~ /^dev\./
+ request.host == detail['dev.host'] || request.host =~ /^dev\./
end
def live?
View
8 app/helpers/radiant/application_helper.rb
@@ -2,7 +2,7 @@ module Radiant
module ApplicationHelper
include Radiant::RegionsHelper
- def config
+ def detail
Radiant::Config
end
@@ -11,11 +11,11 @@ def default_page_title
end
def title
- config['admin.title'] || 'Radiant CMS'
+ detail['admin.title'] || 'Radiant CMS'
end
def subtitle
- config['admin.subtitle'] || 'Publishing for Small Teams'
+ detail['admin.subtitle'] || 'Publishing for Small Teams'
end
def logged_in?
@@ -208,7 +208,7 @@ def gravatar_url(email, options={})
def pagination_for(list, options={})
if list.respond_to? :total_pages
options = {
- :max_per_page => config['pagination.max_per_page'] || 500,
+ :max_per_page => detail['pagination.max_per_page'] || 500,
:depaginate => true
}.merge(options.symbolize_keys)
depaginate = options.delete(:depaginate) # supply :depaginate => false to omit the 'show all' link
View
2  app/helpers/radiant/configuration_helper.rb
@@ -68,7 +68,7 @@ def edit_config(key, options={})
def setting_for(key)
@editable_config ||= {} # normally initialized in Admin::ConfigurationController
- @editable_config[key] ||= Radiant.config.find_or_create_by_key(key)
+ @editable_config[key] ||= Radiant.detail.find_or_create_by_key(key)
end
def definition_for(key)
View
82 app/models/radiant/config.rb
@@ -12,17 +12,17 @@ def config_definitions=(definitions)
class Config < ActiveRecord::Base
#
- # The Radiant.config model class is stored in the database (and cached) but emulates a hash
+ # The Radiant.detail model class is stored in the database (and cached) but emulates a hash
# with simple bracket methods that allow you to get and set values like so:
#
- # Radiant.config['setting.name'] = 'value'
- # Radiant.config['setting.name'] #=> "value"
+ # Radiant.detail['setting.name'] = 'value'
+ # Radiant.detail['setting.name'] #=> "value"
#
# Config entries can be used freely as general-purpose global variables unless a definition
- # has been given for that key, in which case restrictions and defaults may apply. The restrictions
- # can take the form of validations, requirements, permissions or permitted options. They are
+ # has been given for that key, in which case restrictions and defaults may apply. The restrictions
+ # can take the form of validations, requirements, permissions or permitted options. They are
# declared by calling Radiant::Config#define:
- #
+ #
# # setting must be either 'foo', 'bar' or 'blank'
# define('admin.name', :select_from => ['foo', 'bar'])
#
@@ -34,14 +34,14 @@ class Config < ActiveRecord::Base
#
# Which almost always happens in a block like this:
#
- # Radiant.config do |config|
+ # Radiant.detail do |config|
# config.namespace('user', :allow_change => true) do |user|
# user.define 'allow_password_reset?', :default => true
# end
# end
#
# and usually in a config/radiant_config.rb file either in radiant itself, in the application directory
- # or in an extension. Radiant currently defines the following settings and makes them editable by
+ # or in an extension. Radiant currently defines the following settings and makes them editable by
# admin users on the site configuration page:
#
# admin.title :: the title of the admin system
@@ -59,9 +59,9 @@ class Config < ActiveRecord::Base
#
# Helper methods are defined in ConfigurationHelper that will display config entry values
# or edit fields:
- #
+ #
# # to display label and value, where label comes from looking up the config key in the active locale
- # show_setting('admin.name')
+ # show_setting('admin.name')
#
# # to display an appropriate checkbox, text field or select box with label as above:
# edit_setting('admin.name)
@@ -70,9 +70,9 @@ class Config < ActiveRecord::Base
self.table_name = 'config'
after_save :update_cache
attr_reader :definition
-
+
class ConfigError < RuntimeError; end
-
+
class << self
def [](key)
if table_exists?
@@ -91,55 +91,55 @@ def []=(key, value)
setting.value = value
end
end
-
+
def to_hash
Hash[ *find(:all).map { |pair| [pair.key, pair.value] }.flatten ]
end
-
+
def initialize_cache
Radiant::Config.ensure_cache_file
Rails.cache.write('Radiant::Config',Radiant::Config.to_hash)
Rails.cache.write('Radiant.cache_mtime', File.mtime(cache_file))
Rails.cache.silence!
end
-
+
def cache_file_exists?
File.file?(cache_file)
end
-
+
def stale_cache?
return true unless Radiant::Config.cache_file_exists?
Rails.cache.read('Radiant.cache_mtime') != File.mtime(cache_file)
end
-
+
def ensure_cache_file
FileUtils.mkpath(cache_path)
FileUtils.touch(cache_file)
end
-
+
def cache_path
"#{Rails.root}/tmp"
end
-
+
def cache_file
cache_file = File.join(cache_path,'radiant_config_cache.txt')
end
-
+
def site_settings
@site_settings ||= %w{ site.title site.host dev.host local.timezone }
end
-
+
def default_settings
@default_settings ||= %w{ defaults.locale defaults.page.filter defaults.page.parts defaults.page.fields defaults.page.status defaults.snippet.filter }
end
-
+
def user_settings
@user_settings ||= ['user.allow_password_reset?']
end
-
+
# A convenient drying method for specifying a prefix and options common to several settings.
- #
- # Radiant.config do |config|
+ #
+ # Radiant.detail do |config|
# config.namespace('secret', :allow_display => false) do |secret|
# secret.define('identity', :default => 'batman') # defines 'secret.identity'
# secret.define('lair', :default => 'batcave') # defines 'secret.lair'
@@ -151,7 +151,7 @@ def namespace(prefix, options = {}, &block)
prefix = [options[:prefix], prefix].join('.') if options[:prefix]
with_options(options.merge(:prefix => prefix), &block)
end
-
+
# Declares a setting definition that will constrain and support the use of a particular config entry.
#
# define('setting.key', options)
@@ -167,7 +167,7 @@ def namespace(prefix, options = {}, &block)
#
# From the main radiant config/initializers/radiant_config.rb:
#
- # Radiant.config do |config|
+ # Radiant.detail do |config|
# config.define 'defaults.locale', :select_from => lambda { Radiant::AvailableLocales.locales }, :allow_blank => true
# config.define 'defaults.page.parts', :default => "Body,Extended"
# ...
@@ -206,31 +206,31 @@ def define(key, options={})
end
end
end
-
+
def definitions
Radiant.config_definitions
end
-
+
def definition_for(key)
definitions[key] ||= Radiant::Config::Definition.new(:empty => true)
end
-
+
def clear_definitions!
Radiant.config_definitions = {}
end
-
+
end
-
+
# The usual way to use a config item:
#
- # Radiant.config['key'] = value
+ # Radiant.detail['key'] = value
#
# is equivalent to this:
#
# Radiant::Config.find_or_create_by_key('key').value = value
#
# Calling value= also applies any validations and restrictions that are found in the associated definition.
- # so this will raise a ConfigError if you try to change a protected config entry or a RecordInvalid if you
+ # so this will raise a ConfigError if you try to change a protected config entry or a RecordInvalid if you
# set a value that is not among those permitted.
#
def value=(param)
@@ -249,15 +249,15 @@ def value=(param)
# Requesting a config item:
#
- # key = Radiant.config['key']
+ # key = Radiant.detail['key']
#
# is equivalent to this:
#
# key = Radiant::Config.find_or_create_by_key('key').value
#
- # If the config item is boolean the response will be true or false. For items with :type => :integer it will be an integer,
+ # If the config item is boolean the response will be true or false. For items with :type => :integer it will be an integer,
# for everything else a string.
- #
+ #
def value
if boolean?
checked?
@@ -278,26 +278,26 @@ def definition
def boolean?
definition.boolean? || self.key.ends_with?("?")
end
-
+
# Returns true if the item is boolean and true.
#
def checked?
return nil if self[:value].nil?
boolean? && self[:value] == "true"
end
-
+
# Returns true if the item defintion includes a :select_from parameter that limits the range of permissible options.
#
def selector?
definition.selector?
end
-
+
# Returns a name corresponding to the current setting value, if the setting definition includes a select_from parameter.
#
def selected_value
definition.selected(value)
end
-
+
def update_cache
Radiant::Config.initialize_cache
end
View
14 app/views/radiant/admin/configuration/edit.html.haml
@@ -11,25 +11,25 @@
- render_region :form do |form|
- form.edit_site do
%fieldset
- %h3 Site
- - Radiant.config.site_settings.each do |site_setting|
+ %h3 Site
+ - Radiant.detail.site_settings.each do |site_setting|
%p
= edit_config site_setting
-
+
- form.edit_defaults do
%fieldset
%h3 Defaults
- - Radiant.config.default_settings.each do |default_setting|
+ - Radiant.detail.default_settings.each do |default_setting|
%p
= edit_config default_setting
-
+
- form.edit_users do
%fieldset
%h3 Passwords
- - Radiant.config.user_settings.each do |user_setting|
+ - Radiant.detail.user_settings.each do |user_setting|
%p
= edit_config user_setting
-
+
- render_region :form_bottom do |form_bottom|
- form_bottom.edit_buttons do
.buttons
View
28 app/views/radiant/admin/configuration/show.html.haml
@@ -9,28 +9,28 @@
= t('personal_preferences')
= image_tag(gravatar_url(@user.email, :size=>"64px"), :class=>"avatar", :width=>64, :height=>64, :alt=>"")
%p.ruled
- %label
- = t('name')
+ %label
+ = t('name')
%span
= current_user.name
%p.ruled
- %label
- = t('email_address')
- %span.uri
+ %label
+ = t('email_address')
+ %span.uri
= current_user.email
%p.ruled
- %label
- = t('login')
+ %label
+ = t('login')
%span
= current_user.login
%p.ruled
- %label
- = t('password')
+ %label
+ = t('password')
%big &bull;&bull;&bull;&bull;&bull;
%p.ruled
%label
- = t('language')
- %span
+ = t('language')
+ %span
= current_user.locale
#config.box
@@ -41,18 +41,18 @@
.actions
= button_to t("edit_configuration"), edit_admin_configuration_url, :method => :get
Configuration
- - Radiant.config.site_settings.each do |site_setting|
+ - Radiant.detail.site_settings.each do |site_setting|
%p.ruled
= show_config site_setting, :class => (site_setting =~ /host$/ ? 'uri' : nil)
- config.defaults do
%h4 Defaults
- - Radiant.config.default_settings.each do |default_setting|
+ - Radiant.detail.default_settings.each do |default_setting|
%p.ruled
= show_config default_setting
- config.users do
%h4 Passwords
- - Radiant.config.user_settings.each do |user_setting|
+ - Radiant.detail.user_settings.each do |user_setting|
%p.ruled
= show_config user_setting
View
4 config/initializers/radiant_config.rb
@@ -1,4 +1,4 @@
-Radiant.config do |config|
+Radiant.detail do |config|
config.define 'admin.title', :default => "Radiant CMS"
config.define 'dev.host'
config.define 'local.timezone', :allow_change => true, :select_from => lambda { ActiveSupport::TimeZone::MAPPING.keys.sort }
@@ -14,4 +14,4 @@
config.define 'site.title', :default => "Your site title", :allow_blank => false
config.define 'site.host', :default => "www.example.com", :allow_blank => false
config.define 'user.allow_password_reset?', :default => true
-end
+end
View
4 lib/generators/extension/templates/extension.rb
@@ -9,10 +9,6 @@ class <%= class_name %> < Radiant::Extension
# See your config/routes.rb file in this extension to define custom routes
- extension_config do |config|
- # config is the Radiant.configuration object
- end
-
def activate
# tab 'Content' do
# add_item "<%= extension_name %>", "/admin/<%= file_name %>", :after => "Pages"
View
2  lib/generators/extension/templates/radiant_config.rb
@@ -1,3 +1,3 @@
-Radiant.config do |config|
+Radiant.detail do |config|
# config.define "setting.name", :default => 'value', :select_from => ['foo', 'bar']
end
View
2  lib/radiant.rb
@@ -1,7 +1,7 @@
RADIANT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..")) unless defined? RADIANT_ROOT
module Radiant
- def self.config
+ def self.detail
Radiant::Config
end
end
View
6 spec/controllers/radiant/paginated_controller_spec.rb
@@ -11,7 +11,7 @@
#
# describe "with pagination settings from paginate_models" do
# it "should override defaults" do
- # Radiant.config['admin.pagination.per_page'] = ""
+ # Radiant.detail['admin.pagination.per_page'] = ""
# Admin::UsersController.send :paginate_models, {:per_page => 5, :inner_window => 12}
# controller.pagination_parameters.should == {:page => 1, :per_page => 5}
# controller.will_paginate_options.should == {:inner_window => 12, :param_name => :p}
@@ -20,14 +20,14 @@
#
# describe "with configured pagination settings" do
# it "should override defaults" do
- # Radiant.config['admin.pagination.per_page'] = 23
+ # Radiant.detail['admin.pagination.per_page'] = 23
# controller.pagination_parameters.should == {:page => 1, :per_page => 23}
# end
# end
#
describe "without configuration" do
it "should have pagination defaults" do
- Radiant.config['admin.pagination.per_page'] = nil
+ Radiant.detail['admin.pagination.per_page'] = nil
controller.pagination_parameters.should == {:page => 1, :per_page => 50}
controller.will_paginate_options.should == {:param_name => :p}
end
View
4 spec/fixtures/bad_settings.rb
@@ -1,5 +1,5 @@
-Radiant.config do |config|
+Radiant.detail do |config|
config.namespace('testing', :allow_change => true) do |testing|
testing.define 'invalid', :label => 'Default is not valid', :default => "non-monkey", :validate_with => lambda {|s| s.errors.add(:value, "non-monkey!") unless s.value == "monkey" }
end
-end
+end
View
4 spec/fixtures/more_settings.rb
@@ -1,8 +1,8 @@
-Radiant.config do |config|
+Radiant.detail do |config|
config.namespace('testing', :allow_change => true) do |testing|
testing.define 'defaulted', :label => 'Has a default', :default => "this default string"
testing.define 'protected', :label => 'Cannot change', :default => "something", :allow_change => false
testing.define 'validated', :label => 'Has validation', :default => "monkey", :validate_with => lambda {|s| s.errors.add(:value, "not monkey") unless s.value == "monkey" }
testing.define 'selected', :select_from => lambda { TextFilter.descendants.map { |s| s.filter_name }.sort }, :label => "Default text filter", :allow_blank => true
end
-end
+end
View
4 spec/fixtures/settings.rb
@@ -1,5 +1,5 @@
-Radiant.config do |config|
+Radiant.detail do |config|
config.namespace('testing', :allow_change => true) do |testing|
testing.define 'simple', :label => 'A text setting', :notes => 'just a string', :default => "this string"
end
-end
+end
View
24 spec/lib/radiant/config/definition_spec.rb
@@ -50,14 +50,14 @@
:allow_blank => false
})
end
- after :each do
+ after :each do
Radiant::Cache.clear
- Radiant.config.clear_definitions!
+ Radiant.detail.clear_definitions!
end
describe "basic definition" do
before do
- Radiant.config.define('test', @basic)
+ Radiant.detail.define('test', @basic)
@setting = Radiant::Config.find_by_key('test')
end
@@ -67,7 +67,7 @@
Radiant::Config['test'].should == 'quite testy'
end
end
-
+
describe "validating" do
before do
Radiant::Config.define('valid', @validating)
@@ -110,24 +110,24 @@
Radiant::Config.define('later', @selecting_at_runtime)
Radiant::Config.define('required', @selecting_required)
end
-
+
it "should identify itself as a selector" do
Radiant::Config.find_by_key('not').selector?.should be_false
Radiant::Config.find_by_key('now').selector?.should be_true
end
-
+
it "should offer a list of options" do
Radiant::Config.find_by_key('required').selection.should have(3).items
Radiant::Config.find_by_key('now').selection.include?(["", ""]).should be_true
Radiant::Config.find_by_key('now').selection.include?(["m", "Monkey"]).should be_true
Radiant::Config.find_by_key('now').selection.include?(["g", "Goat"]).should be_true
end
-
+
it "should run a supplied selection block" do
@enclosed = "testing"
Radiant::Config.find_by_key('later').selection.include?(["testing", "testing"]).should be_true
end
-
+
it "should normalise the options to a list of pairs" do
Radiant::Config.find_by_key('hashed').selection.is_a?(Hash).should be_false
Radiant::Config.find_by_key('hashed').selection.include?(["monkey", "Definitely a monkey"]).should be_true
@@ -137,19 +137,19 @@
Radiant::Config.find_by_key('required').selection.should have(3).items
Radiant::Config.find_by_key('required').selection.include?(["", ""]).should be_false
end
-
+
end
-
+
describe "protecting" do
before do
Radiant::Config.define('required', @present)
Radiant::Config.define('fixed', @protected)
end
-
+
it "should raise a ConfigError when a protected value is set" do
lambda{ Radiant::Config['fixed'] = "different" }.should raise_error(Radiant::Config::ConfigError)
end
-
+
it "should raise a validation error when a required value is made blank" do
lambda{ Radiant::Config['required'] = "" }.should raise_error
end
View
32 spec/models/radiant/config_spec.rb
@@ -2,12 +2,12 @@
describe Radiant::Config do
before :each do
- Radiant.config.initialize_cache
- @config = Radiant.config
+ Radiant.detail.initialize_cache
+ @config = Radiant.detail
set('test', 'cool')
set('foo', 'bar')
end
- after :each do
+ after :each do
Radiant::Cache.clear
end
@@ -26,27 +26,27 @@
@config['test'] = 'cool'
end
end
-
+
it "should create a cache of all records in a hash with Radiant::Config.initialize_cache" do
Rails.cache.read('Radiant::Config').should == Radiant::Config.to_hash
end
-
+
it "should recreate the cache after a record is saved" do
Radiant::Config.create!(:key => 'cache', :value => 'true')
Rails.cache.read('Radiant::Config').should == Radiant::Config.to_hash
end
-
+
it "should update the mtime on the cache file after a record is saved" do
FileUtils.should_receive(:mkpath).with("#{Rails.root}/tmp").at_least(:once)
FileUtils.should_receive(:touch).with(Radiant::Config.cache_file)
Radiant::Config['mtime'] = 'now'
end
-
+
it "should record the cache file mtime when the cache is initialized" do
Radiant::Config.initialize_cache
Rails.cache.read('Radiant.cache_mtime').should == File.mtime(Radiant::Config.cache_file)
end
-
+
it "should create a cache file when initializing the cache" do
Radiant::Cache.clear
cache_file = File.join(Rails.root,'tmp','radiant_config_cache.txt')
@@ -54,11 +54,11 @@
Radiant::Config.initialize_cache
File.file?(cache_file).should be_true
end
-
+
it "should find the value in the cache with []" do
Radiant::Config['test'].should === Rails.cache.read('Radiant::Config')['test']
end
-
+
it "should set the value in the database with []=" do
Radiant::Config['new-db-key'] = 'db-value'
Radiant::Config.find_by_key('new-db-key').value.should == 'db-value'
@@ -105,12 +105,12 @@
@config['junk?'].should be_false
end
end
-
+
describe "where no definition exists" do
it "should create a blank definition" do
get_config("ad.hoc.setting").definition.should be_kind_of(Radiant::Config::Definition)
end
-
+
it "should not protect or constrain" do
c = get_config("impromptu.storage")
c.allow_blank?.should be_true
@@ -118,25 +118,25 @@
c.settable?.should be_true
end
end
-
+
describe "where a definition exists" do
before do
@config.clear_definitions!
load(SPEC_ROOT + "/fixtures/more_settings.rb")
end
-
+
it "should validate against the definition" do
definition = get_config('testing.validated')
lambda{ @config['testing.validated'] = "pig" }.should raise_error(ActiveRecord::RecordInvalid)
end
-
+
it "should protect when the definition requires it" do
definition = get_config('testing.protected')
definition.settable?.should be_false
lambda { definition.value = "something else" }.should raise_error(Radiant::Config::ConfigError)
end
end
-
+
def get_config(key)
setting = Radiant::Config.find_or_create_by_key(key)
end
Please sign in to comment.
Something went wrong with that request. Please try again.