diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/zorglub/app.rb | 1 | ||||
| -rw-r--r-- | lib/zorglub/node.rb | 50 | 
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  | 
