lib/caboodle/kit.rb in caboodle-0.2.1 vs lib/caboodle/kit.rb in caboodle-0.2.2

- old
+ new

@@ -1,9 +1,8 @@ module Caboodle class Kit < Sinatra::Base - #register Sinatra::Compass set :app_file, __FILE__ set :logging, true set :root, File.expand_path(File.join(File.dirname(__FILE__),"app")) set :public, Proc.new { File.join(root, "public") } @@ -19,10 +18,19 @@ Caboodle::Site.cache_for ||= 600 response.headers['Cache-Control'] = "public, max-age=#{Caboodle::Site.cache_for}" end class << self + attr_accessor :credit_link + + def configure + config_path = File.expand_path(File.join(Caboodle::App.root,"config","site.yml")) + if File.exists?(config_path) + Caboodle::Kit.load_config(config_path) + Caboodle::Kit.setup + end + end def inherited subclass c = caller[0].split(":") f = File.dirname(File.expand_path("#{c[0]}")) views = File.join(f, "views") @@ -43,16 +51,20 @@ Caboodle::Site[k.to_s] = v } rescue puts "Warning! Skipping #{p}" Caboodle::Site.kits.uniq! end def dump_config - puts "Dump config" - p = File.expand_path(File.join(Caboodle::App.root,"config","site.yml")) - d = Caboodle::Site.clone - e = d.to_hash - e.delete("required_settings") - File.open(p, 'w') {|f| f.write(YAML::dump(e))} + begin + puts "Dump config" + p = File.expand_path(File.join(Caboodle::App.root,"config","site.yml")) + d = Caboodle::Site.clone + e = d.to_hash + e.delete("required_settings") + File.open(p, 'w') {|f| f.write(YAML::dump(e))} + rescue + puts "Cannot write config file" + end end def setup require_all use_all @@ -153,10 +165,19 @@ Caboodle::Stylesheets << array_of_css_files.to_s end Caboodle::Stylesheets.uniq! end + def add_sass array_of_sass_files + if array_of_sass_files.class == Array + array_of_sass_files.each { |a| Caboodle::SASS << a.to_s } + else + Caboodle::SASS << array_of_sass_files.to_s + end + Caboodle::SASS.uniq! + end + alias_method :stylesheet, :stylesheets def javascripts array_of_js_files if array_of_js_files.class == Array array_of_js_files.each { |a| Caboodle::Javascripts << a.to_s } @@ -193,12 +214,15 @@ if hash.class == Hash hash.each {|k,v| Site[k] = v } end end - def original url - set :credit, "<a href='#{url}' rel='me'>via #{self.class.name.split("::").last}</a>" + 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>\" + end" end def required_settings r = RequiredSettings[self.ancestors.first.to_s.split("::").last] ||= [:title, :description, :logo_url, :author] RequiredSettings[self.ancestors.first.to_s.split("::").last] @@ -216,9 +240,10 @@ Caboodle::App.use self else STDERR.puts " " STDERR.puts "Warning - #{self.ancestors.first} is disabled because:" STDERR.puts errors.join("\n") + Caboodle::Errors << Hashie::Mash.new(:title=>"#{self.ancestors.first} is disable", :reason=>errors.join(";")) end end end end end \ No newline at end of file