From 8135a99aa065b2616e69647b7fa3149609f0978a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 16 Jun 2011 15:11:50 +0200 Subject: add class Zorglub::Config --- lib/zorglub.rb | 5 ++-- lib/zorglub/config.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 lib/zorglub/config.rb diff --git a/lib/zorglub.rb b/lib/zorglub.rb index f93b4c1..60917c6 100644 --- a/lib/zorglub.rb +++ b/lib/zorglub.rb @@ -5,8 +5,9 @@ module Zorglub # VERSION = '0.0.1' # - autoload :App, './lib/zorglub/app.rb' - autoload :Node, './lib/zorglub/node.rb' + autoload :App, './lib/zorglub/app.rb' + autoload :Config, './lib/zorglub/config.rb' + autoload :Node, './lib/zorglub/node.rb' # end # diff --git a/lib/zorglub/config.rb b/lib/zorglub/config.rb new file mode 100644 index 0000000..8b5ae37 --- /dev/null +++ b/lib/zorglub/config.rb @@ -0,0 +1,63 @@ +#! /usr/bin/ruby +# +module Zorglub + # + class Config + @options = { + :root => '.', + :engine => 'haml', + :view_dir => 'view', + :layout_dir => 'layout', + :default_layout => 'default' + } + @engines = { + 'haml' => 'haml' + } + class << self + # + def [] k + options[k] + end + # + def []= k, v + option[k]=v + end + # + def view_base_path + if @options.has_key? :view_path + @options[:view_path] + else + File.join @options[:root], @options[:view_dir] + end + end + # + def layout_base_path + if @options.has_key? :layout_path + @options[:layout_path] + else + File.join @options[:root], @options[:layout_dir] + end + end + # + def register_engine name, ext + return unless name and ext + @engines[name]=ext + end + # + def engine_ext engine + @engines[engine] + end + end + # + def self.method_missing m, *args, &block + if m=~/(.*)=$/ + @options[$1.to_sym]=args[0] + else + @options[m.to_sym] + end + end + # + end + # +end +# -- cgit v1.1-2-g2b99