diff --git a/init.rb b/init.rb index 26f72b2..d439688 100644 --- a/init.rb +++ b/init.rb @@ -1 +1,3 @@ require File.join(File.dirname(__FILE__), 'lib', 'hush_cms') + +HushCMS.load diff --git a/lib/hush_cms.rb b/lib/hush_cms.rb index 8f6ceb9..878db81 100644 --- a/lib/hush_cms.rb +++ b/lib/hush_cms.rb @@ -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 + \ No newline at end of file