diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-06-16 17:33:41 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-06-16 17:33:41 +0200 |
commit | ae5cd024e07960002f4f9bbae23b6ccb3b73b3eb (patch) | |
tree | 8281cd099d7d95ae35fd51cbfc8375834525b514 | |
parent | 9afeb6e5a87e50eef1c87844e1c2923cc2680f73 (diff) | |
download | zorglub-ae5cd024e07960002f4f9bbae23b6ccb3b73b3eb.zip zorglub-ae5cd024e07960002f4f9bbae23b6ccb3b73b3eb.tar.gz |
enable view and layout usage
-rw-r--r-- | examples/sample.ru | 17 | ||||
-rw-r--r-- | lib/zorglub/config.rb | 19 | ||||
-rw-r--r-- | lib/zorglub/node.rb | 12 |
3 files changed, 30 insertions, 18 deletions
diff --git a/examples/sample.ru b/examples/sample.ru index b318f86..009eaae 100644 --- a/examples/sample.ru +++ b/examples/sample.ru @@ -4,14 +4,19 @@ $LOAD_PATH << File.join(File.dirname( File.absolute_path(__FILE__)), '..', 'lib' # require 'zorglub' # -Zorglub::Config.register_engine 'my-engine', 'my-ext' -Zorglub::Config.register_engine 'temp-engine', 'tmp' +require 'haml' +HAML_PROC = Proc.new { |path,obj| Haml::Engine.new( File.open(path,'r').read ).render(obj) } +Zorglub::Config.register_engine 'haml', 'haml', HAML_PROC +Zorglub::Config.register_engine 'temp-engine', 'haml', HAML_PROC +# +Zorglub::Config.engine = 'haml' Zorglub::Config.root = File.dirname( File.absolute_path(__FILE__) ) # class Node1 < Zorglub::Node # def index a1, *a2 - "<title>Node1:index</title><p>a1 : #{a1.inspect}</p><p>a2 : #{a2.inspect}</p>#{html}" + @title='Node2' + #"<title>Node1:index</title><p>a1 : #{a1.inspect}</p><p>a2 : #{a2.inspect}</p>#{html}" end # def alt *args @@ -27,11 +32,11 @@ end class Node2 < Zorglub::Node # map APP, '/url2' - engine 'my-engine' - layout 'my-layout' + engine 'my-engine' # not available + layout 'my-layout' # not available # def index *args - "<title>Node2</title>#{html}" + "<title>Node2:alt</title>#{html}" end # def alt *args diff --git a/lib/zorglub/config.rb b/lib/zorglub/config.rb index 8b5ae37..5c43a1b 100644 --- a/lib/zorglub/config.rb +++ b/lib/zorglub/config.rb @@ -5,14 +5,12 @@ module Zorglub class Config @options = { :root => '.', - :engine => 'haml', + :engine => nil, :view_dir => 'view', :layout_dir => 'layout', :default_layout => 'default' } - @engines = { - 'haml' => 'haml' - } + @engines = { } class << self # def [] k @@ -39,14 +37,21 @@ module Zorglub end end # - def register_engine name, ext + def register_engine name, ext, proc return unless name and ext - @engines[name]=ext + @engines[name]=[ ext, proc ] end # def engine_ext engine - @engines[engine] + e = @engines[engine] + ( e.nil? ? '' : e[0] ) + end + # + def engine_proc engine + e = @engines[engine] + ( e.nil? ? nil : e[1] ) end + # end # def self.method_missing m, *args, &block diff --git a/lib/zorglub/node.rb b/lib/zorglub/node.rb index 99d6c5d..08214a3 100644 --- a/lib/zorglub/node.rb +++ b/lib/zorglub/node.rb @@ -55,11 +55,13 @@ module Zorglub end # def realize - # TODO - # - use view - # - use layout - r = self.send @action[:method], *@action[:args] - response.write r + @content = self.send @action[:method], *@action[:args] + e = Config.engine_proc @action[:engine] + v = view + l = layout + @content = e.call v, self if e and File.exists? v + @content = e.call l, self if e and File.exists? l + response.write @content response.finish end # |