summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-06-16 15:15:26 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-06-16 15:15:26 +0200
commitd80e07cc22a4ebaee68eb75c90383df0e7789754 (patch)
tree4d8c29e8e8b13d61728c83bea2e27cf42116a18c
parent8135a99aa065b2616e69647b7fa3149609f0978a (diff)
downloadzorglub-d80e07cc22a4ebaee68eb75c90383df0e7789754.zip
zorglub-d80e07cc22a4ebaee68eb75c90383df0e7789754.tar.gz
add Node#engine, Node#layout, Node#view, Node#args, Node#map, Node#r
-rw-r--r--lib/zorglub/app.rb1
-rw-r--r--lib/zorglub/node.rb50
2 files changed, 44 insertions, 7 deletions
diff --git a/lib/zorglub/app.rb b/lib/zorglub/app.rb
index d568d26..0de4336 100644
--- a/lib/zorglub/app.rb
+++ b/lib/zorglub/app.rb
@@ -16,6 +16,7 @@ module Zorglub
def map location, object
return unless location and object
raise Exception.new "#{@map[location]} already mapped to #{location}" if @map.has_key? location
+ object.app = self
@map.merge! location.to_s=>object
remap @map
end
diff --git a/lib/zorglub/node.rb b/lib/zorglub/node.rb
index e57a299..89b0cf2 100644
--- a/lib/zorglub/node.rb
+++ b/lib/zorglub/node.rb
@@ -6,7 +6,17 @@ module Zorglub
#
class << self
#
- attr_reader :map
+ def engine engine=nil
+ @engine = engine unless engine.nil?
+ @engine ||= Config.engine
+ end
+ #
+ def layout name=nil
+ @layout = name unless name.nil?
+ @layout ||= Config.default_layout
+ end
+ #
+ attr_writer :app
def map app, location
@app = app
@app.map location, self
@@ -17,12 +27,10 @@ module Zorglub
end
#
def call env
- node = self.new Rack::Request.new(env), Rack::Response.new
meth, *args = env['PATH_INFO'][1..-1].split '/'
meth||= 'index'
+ node = self.new Rack::Request.new(env), Rack::Response.new, {:engine=>engine,:layout=>layout,:view=>File.join(r,meth),:method=>meth,:args=>args}
return error_404 node if not node.respond_to? meth
- # TODO use layout
- # TODO use view
# TODO session
node.send meth, *args
end
@@ -37,17 +45,45 @@ module Zorglub
#
end
#
- attr_reader :request, :response
+ attr_reader :request, :response, :action
#
- def initialize req, res
+ def initialize req, res, act
+ @action = act
@request = req
@response = res
end
#
- def r
+ def engine engine=nil
+ @action[:engine] = engine unless engine.nil?
+ @action[:engine]
+ end
+ #
+ def layout name=nil
+ @action[:layout] = name unless name.nil?
+ File.join(Config.layout_base_path, @action[:layout])+'.'+ Config.engine_ext(@action[:engine])
+ end
+ #
+ def view path=nil
+ @action[:view] = path unless path.nil?
+ File.join(Config.view_base_path, @action[:view])+'.'+Config.engine_ext(@action[:engine])
+ end
+ #
+ def args
+ @action[:args]
+ end
+ #
+ def map
self.class.r
end
#
+ def r
+ File.join map, @action[:method]
+ end
+ #
+ def html
+ [ :map, :r, :args, :engine, :layout, :view ].inject('') { |s,sym| s+="<p>#{sym} => #{self.send sym}</p>"; s }
+ end
+ #
end
#
end