lib/caboodle/kit.rb in caboodle-0.1.3 vs lib/caboodle/kit.rb in caboodle-0.1.4

- old
+ new

@@ -7,15 +7,28 @@ set :logging, true set :root, File.expand_path(File.join(File.dirname(__FILE__),"app")) set :public, Proc.new { File.join(root, "public") } set :haml, {:format => :html5 } + helpers Sinatra::CaboodleHelpers + template :layout do @@template ||= File.open(File.join(File.dirname(__FILE__),"app","views","layout.haml")).read end class << self + + def inherited subclass + 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) + subclass.set :public, pub if File.exists?(pub) + super + end + def is_a_caboodle_kit true end def load_config p @@ -44,11 +57,11 @@ unless name.blank? kit_name = name.to_s.split("::").last || name kit_name = kit_name.downcase puts "Loading Kit: #{kit_name}" orig = Caboodle.constants - require "caboodle/kits/#{kit_name}/#{kit_name}" rescue puts "Warning! No such kit: #{kit_name}" + require "caboodle/kits/#{kit_name}/#{kit_name}" rescue puts "Problem loading Kit: #{kit_name}" added = Caboodle.constants - orig added.each do |d| c = Caboodle.const_get(d) if c.respond_to?(:is_a_caboodle_kit) c.register @@ -62,11 +75,11 @@ unless name.blank? kit_name = name.to_s.split("::").last || name kit_name = kit_name.downcase puts "Loading Kit: #{kit_name}" orig = Caboodle.constants - require "caboodle/kits/#{kit_name}/#{kit_name}" rescue puts "Warning! No such kit: #{kit_name}" + require "caboodle/kits/#{kit_name}/#{kit_name}" rescue puts "Problem loading Kit: #{kit_name}" added = Caboodle.constants - orig added.each do |d| c = Caboodle.const_get(d) if c.respond_to?(:is_a_caboodle_kit) c.unregister @@ -128,9 +141,21 @@ end def javascripts array_of_js_files array_of_js_files.each { |a| Caboodle::Javascripts << a } Caboodle::Javascripts.uniq! + end + + def add_to_layout hash_of_items + hash_of_items.each do |k,v| + unless Caboodle::Layout[k.to_sym].blank? + Caboodle::Layout[k.to_sym] << "\n" + Caboodle::Layout[k.to_sym] << v + else + Caboodle::Layout[k.to_sym] = v + end + end + puts Caboodle::Layout.inspect end def defaults hash if hash.class == Hash hash.each {|k,v| Site[k] = v } \ No newline at end of file