extend layout capailities
[coquelicot.git] / lib / coquelicot / configure.rb
1 module Coquelicot::Configure
2   
3   def self.included(c)
4     c.extend ClassMethods
5     c.configure
6   end
7   
8   module ClassMethods
9     def configure
10       user_settings = File.exists?(settings_path) ? load_user_settings : {}
11       default_settings.delete('authentication_method') if user_settings['authentication_method']
12       merged_settings = default_settings.merge(user_settings)
13       if (authm=merged_settings.delete('authentication_method'))
14         authentication_method authm.delete('name'), authm
15       end
16       merged_settings.each{|k,v| set k,v }
17     end
18     private
19     def authentication_method(method,options={})
20       require "coquelicot/auth/#{method}"
21       set :auth_method, method
22       include (eval "Coquelicot::Auth::#{method.to_s.capitalize}")
23       options.each{|k,v| set k,v }
24     end
25     def default_settings
26       {
27         'default_expire' => 60,
28         'maximum_expire' => 60 * 24 * 30, # 1 month
29         'gone_period' => 10080,
30         'filename_length' => 20,
31         'random_pass_length' => 16,
32         'about_text' => '',
33         'additional_css' => '',
34         'depot_path' => Proc.new { File.join(root, 'files') },
35         'authentication_method' => {
36           'name' => 'simplepass',
37           'upload_password' => 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'          
38         },
39       }
40     end
41     
42     def settings_path
43       @settings_path ||= File.join(File.dirname(__FILE__),'..','..','conf','settings.yml')
44     end
45     
46     def load_user_settings
47       YAML.load(File.read(settings_path))
48     end
49   end
50 end