lib/caboodle/kit.rb in caboodle-0.2.13 vs lib/caboodle/kit.rb in caboodle-0.2.14
- old
+ new
@@ -17,27 +17,34 @@
before do
Caboodle::Site.cache_for ||= 600
response.headers['Cache-Control'] = "public, max-age=#{Caboodle::Site.cache_for}"
end
+ error SocketError do
+ @title = "Whoops!"
+ @message = "Sorry. There was a problem communicating with #{self.class.kit_name}."
+ haml File.open(File.join(Caboodle::Kit.root, "views","error.haml")).read
+ end
+
Config = Hashie::Mash.new
class << self
attr_accessor :credit_link
def configure_site config_path
- set :config, config_path
+ set :config_path, config_path
if File.exists?(config_path)
Caboodle::Kit.load_config(config_path)
Caboodle::Kit.setup
else
puts "No such configuration file: #{config_path}"
end
end
def inherited subclass
+ set :kit_root, File.expand_path(File.dirname(caller[0].split(/:in/).last))
c = caller[0].split(":")
f = File.dirname(File.expand_path("#{c[0]}"))
views = File.join(f, "views")
pub = File.join(f, "public")
subclass.set :views, views if File.exists?(views)
@@ -82,16 +89,32 @@
array_of_files.each do |file|
config_path = File.expand_path(File.join(Caboodle::App.root,"config",file))
if File.exists?(config_path)
load_custom_config(config_path)
else
- `cp "#{File.join(root,"config",file)}" "#{File.join(Caboodle::App.root,"config",".")}"` rescue "Could not create the config yml file"
+ `cp "#{File.join(kit_root,"config",file)}" "#{File.join(Caboodle::App.root,"config",".")}"` rescue "Could not create the config yml file"
puts "\nThis kit has a separate configuration file which you must edit:\n #{File.expand_path(File.join(Caboodle::App.root,"config",file))}\n"
end
end
end
end
+
+ def files array_of_files
+ configure do
+ array_of_files.each do |file|
+ target_path = File.expand_path(File.join(Caboodle::App.root,"config",file))
+ unless File.exists?(target_path)
+ `cp "#{File.join(kit_root,"config",file)}" "#{File.join(Caboodle::App.root,"config",".")}"` rescue "Could not create the config yml file"
+ end
+ end
+ end
+ end
+
+ def description string
+ puts "\n"
+ puts "#{name.to_s.split("::").last}: #{string}"
+ end
def setup
require_all
use_all
end
@@ -167,11 +190,11 @@
if Caboodle::Site[r].blank?
ask_user r
end
end
optional_settings.each do |r|
- if Caboodle::Site[r].blank?
+ unless defined?(Caboodle::Site[r])
ask_user r, true
end
end
end
@@ -291,29 +314,34 @@
end
def credit url
#todo there must be an easier way
class_eval "def credit_link
- \"<a rel='me' href='#{url}' rel='me'>#{self.name.split("::").last}</a>\"
+ \"<a rel='me' href='#{url}'>#{self.name.split("::").last}</a>\"
end"
end
def required_settings
- RequiredSettings[self.ancestors.first.to_s.split("::").last] ||= []
- RequiredSettings[self.ancestors.first.to_s.split("::").last]
+ RequiredSettings[kit_name] ||= []
+ RequiredSettings[kit_name]
end
def optional_settings
- OptionalSettings[self.ancestors.first.to_s.split("::").last] ||= []
- OptionalSettings[self.ancestors.first.to_s.split("::").last]
+ OptionalSettings[kit_name] ||= []
+ OptionalSettings[kit_name]
end
+ def kit_name
+ self.ancestors.first.to_s.split("::").last
+ end
+
def available_kits
Dir.new(File.join(File.dirname(__FILE__),"kits")).entries.delete_if{|a| a[0,1]=="."}
end
def start
+
errors = []
self.required_settings.each do |s|
if Site[s].blank?
errors << " :#{s} has not been set"
end
@@ -321,12 +349,12 @@
if errors.empty?
Caboodle::App.use self
else
STDERR.puts " "
- STDERR.puts "Warning - #{self.ancestors.first} is disabled because:"
+ STDERR.puts "Warning - #{kit_name} is disabled because:"
STDERR.puts errors.join("\n")
- Caboodle::Errors << Hashie::Mash.new(:title=>"#{self.ancestors.first} is disable", :reason=>errors.join(";"))
+ Caboodle::Errors << Hashie::Mash.new(:title=>"#{kit_name} is disable", :reason=>errors.join(";"))
end
end
end
end
end
\ No newline at end of file