Skip to content

Commit

Permalink
Integrated initial loading into the HushCMS module, added loading of …
Browse files Browse the repository at this point in the history
…config/hush.yml and validation of required entries
  • Loading branch information
jamesbrooks committed Aug 19, 2008
1 parent c77eb97 commit a8a8de4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
2 changes: 2 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
require File.join(File.dirname(__FILE__), 'lib', 'hush_cms')

HushCMS.load
48 changes: 38 additions & 10 deletions lib/hush_cms.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
require 'extensions/string'
require 'extensions/mapper'

%w( models controllers helpers ).each do |dir|
path = File.join(File.dirname(__FILE__), dir)
$LOAD_PATH << path
Dependencies.load_paths << path
Dependencies.load_once_paths.delete(path)
end

ActionController::Base.append_view_path(File.join(File.dirname(__FILE__), 'views'))
ActionView::Base.send :include, HushCMSViewHelpers

module HushCMS
class << self
attr_reader :configuration

def load
%w( models controllers controllers/admin helpers ).each do |dir|
path = File.join(File.dirname(__FILE__), dir)
$LOAD_PATH << path
Dependencies.load_paths << path
Dependencies.load_once_paths.delete(path)
end

ActionController::Base.append_view_path(File.join(File.dirname(__FILE__), 'views'))
ActionView::Base.send :include, HushCMSViewHelpers

if File.exist?("#{RAILS_ROOT}/config/hush.yml")
@configuration = YAML::load(File.open("#{RAILS_ROOT}/config/hush.yml"))
else
raise ConfigurationException.new("config/hush.yml doesn't exist")
end

validate_configuration
end

private
def validate_configuration
unless configuration
raise ConfigurationException.new("config/hush.yml doesn't define anything")
end

unless configuration['administration'] && configuration['administration']['username'] && configuration['administration']['password']
raise ConfigurationException.new("config/hush.yml doesn't define username and password under administration")
end
end
end

class ConfigurationException < Exception
end
end

0 comments on commit a8a8de4

Please sign in to comment.