From 15d55e301ad7bbc643115d7146fcedb6554b9db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 10 Sep 2011 23:36:38 +0200 Subject: rewrite example application --- examples/layout/css.haml | 5 +++ examples/layout/default.haml | 2 +- examples/layout/other.haml | 4 +- examples/sample.ru | 85 +++++++++++++++++++++++++++++++++++-------- examples/view/url1/alt.haml | 15 -------- examples/view/url1/index.haml | 15 ++------ examples/view/url1/meth0.haml | 7 ++++ examples/view/url3/index.haml | 6 +++ 8 files changed, 94 insertions(+), 45 deletions(-) create mode 100644 examples/layout/css.haml delete mode 100644 examples/view/url1/alt.haml create mode 100644 examples/view/url1/meth0.haml create mode 100644 examples/view/url3/index.haml diff --git a/examples/layout/css.haml b/examples/layout/css.haml new file mode 100644 index 0000000..c9e35db --- /dev/null +++ b/examples/layout/css.haml @@ -0,0 +1,5 @@ +%h1=@title +%p="xx css layout xx" +%p="Css #{css.inspect}" +%p=@content +%p="xx -- xx" diff --git a/examples/layout/default.haml b/examples/layout/default.haml index 9c84f4d..6af5e38 100644 --- a/examples/layout/default.haml +++ b/examples/layout/default.haml @@ -1,4 +1,4 @@ %h1=@title -%p="xx -- xx" +%p="xx default layout xx" %p=@content %p="xx -- xx" diff --git a/examples/layout/other.haml b/examples/layout/other.haml index ac6f300..601b305 100644 --- a/examples/layout/other.haml +++ b/examples/layout/other.haml @@ -1,4 +1,4 @@ %h1=@title -%p="xx - OTHER - xx" +%p="xx other layout - xx" %p=@content -%p="xx - OTHER - xx" +%p="xx -- xx" diff --git a/examples/sample.ru b/examples/sample.ru index e05aebe..5692ef5 100644 --- a/examples/sample.ru +++ b/examples/sample.ru @@ -7,7 +7,7 @@ require 'zorglub' 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.register_engine 'tmp-engine', 'haml', HAML_PROC # Zorglub::Config.engine = 'haml' Zorglub::Config.session_on = true @@ -15,17 +15,31 @@ Zorglub::Config.root = File.dirname( File.absolute_path(__FILE__) ) # class Node1 < Zorglub::Node # - include Zorglub::Helpers::Css - css 'class_level.css' - # def index a1, *a2 @title='Index' - css 'instance_level.css' + @links = LINKS + # there's a view so the below will be lost ! + "should never be seeen" + end + # + def meth0 *args + @title='meth0' + @links = LINKS + # method level engine + engine 'tmp-engine' + # there's a view so the below will be lost ! + "should never be seeen" end # - def alt *args - @title='Alt' - "Node1:alt#{html}" + def meth1 *args + @title='meth1' + @links = LINKS + # method level engine (layout/other.haml) + layout 'other' + # specific method view (view/url1/meth0.haml) + view File.join( 'url1','meth0') + # there's a view so the below will be lost ! + "should never be seeen" end # end @@ -39,18 +53,31 @@ class Node2 < Zorglub::Node include Zorglub::Helpers::Css # map APP, '/url2' - engine 'my-engine' # not available - layout 'my-layout' # not available + layout 'css' + # class level engine + engine 'tmp-engine' + # class level css + css 'class_level.css' # def index *args - "Node2:alt#{html}" + "Node2:indexSTART#{html}next
END" end # - def alt *args - @title = "Alt 2" - engine 'temp-engine' # haml renamed - layout 'other' # use layout/other.haml template - view File.join( 'url1','alt') # use view/url1/alt.haml template + def meth0 *args + # instance level css + css 'instance_level.css' + "Node2:meth0START#{html}back
END" + end + # +end +# +class Node3 < Zorglub::Node + # + map APP, '/url3' + layout '' + # + def index *args + @title = "Session tests" if not session.exists? @data = "NO SESSION" else @@ -68,6 +95,32 @@ class Node2 < Zorglub::Node end # end +# # +# def redir +# redirect Node0.r +# end +# +class Node0 < Zorglub::Node + # + map APP, '/' + # + def index + html = "" + html + end + # +end +# +Node1::LINKS= [ + [Node1.r('index','arg1','arg2','arg3'),'index'], + [Node1.r('meth0'),'meth0'], + [Node1.r('meth1','one','two'),'meth1 with args'], + [Node0.r,'back'], +] # puts APP.to_hash.inspect # diff --git a/examples/view/url1/alt.haml b/examples/view/url1/alt.haml deleted file mode 100644 index dfd04d5..0000000 --- a/examples/view/url1/alt.haml +++ /dev/null @@ -1,15 +0,0 @@ -%h3='Alt template' --action.each do |k,v| - %p="#{k} => #{v}" -%p="Css #{css.inspect}" -%p - %a{:href=>Node1.r('index','arg1','arg2')}="Node1::index" -%p - %a{:href=>Node1.r('alt')}="Node1::alt" -%p - %a{:href=>Node2.r('index')}="Node2::index" -%p - %a{:href=>Node2.r('alt')}="Node2::alt" -%p - %a{:href=>Node1.r('pour', 'voir')}="nowhere" -%p="Time #{@data}" diff --git a/examples/view/url1/index.haml b/examples/view/url1/index.haml index eb52535..7bbf8be 100644 --- a/examples/view/url1/index.haml +++ b/examples/view/url1/index.haml @@ -1,14 +1,7 @@ -%h3='Index template' +%h3='url1 index view' -action.each do |k,v| %p="#{k} => #{v}" -%p="Css #{css.inspect}" %p - %a{:href=>Node1.r('index','arg1','arg2')}="Node1::index" -%p - %a{:href=>Node1.r('alt')}="Node1::alt" -%p - %a{:href=>Node2.r('index')}="Node2::index" -%p - %a{:href=>Node2.r('alt')}="Node2::alt" -%p - %a{:href=>Node1.r('pour', 'voir')}="nowhere" + - @links.each do |href,name| + %a{:href=>href}=name + %br diff --git a/examples/view/url1/meth0.haml b/examples/view/url1/meth0.haml new file mode 100644 index 0000000..89a7ab9 --- /dev/null +++ b/examples/view/url1/meth0.haml @@ -0,0 +1,7 @@ +%h3='url1 meth0 view' +-action.each do |k,v| + %p="#{k} => #{v}" +%p + - @links.each do |href,name| + %a{:href=>href}=name + %br diff --git a/examples/view/url3/index.haml b/examples/view/url3/index.haml new file mode 100644 index 0000000..ff91a0b --- /dev/null +++ b/examples/view/url3/index.haml @@ -0,0 +1,6 @@ +%h2=@title +%p=Time.now.strftime '%H:%M:%S' +%p=@data +%a{:href=>Node3.r}="reload" +%br +%a{:href=>Node0.r}="back" -- cgit v1.1-2-g2b99