summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/sample.ru17
-rw-r--r--lib/zorglub/config.rb19
-rw-r--r--lib/zorglub/node.rb12
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
#