[Nitro] Nitro: cannot control the current path of a controller when skins are called
Jimmy Jazz
Jimmy.Jazz at gmx.net
Tue Jun 26 19:41:17 EDT 2007
Arne Brasseur a écrit :
> If I understand you correctly, you have a blog model and a related
> controller. You expect a blog model object's to_href method to return a
> link that is mapped to the blog controller, and it's not working. Is
> that where your problem is?
Yes, that's it. The problem will be the same with templates associated
with the blog controller. <a href="index.html"> doesn't return
http://yourserver:9000/blog/index.html as it should (/blog/ is lost). It
returns http://yourserver:9000/index.html instead.
> Source tree layout can be pretty much any way you like in Nitro, that
> doesn't matter very much. On the other hand you didn't say much about
> how your classes are laid out. More information could be helpful.
Also, i didn't get too far. For the moment, i'm just concentrate to
understand how skins are working with controllers. The most of the code
i'm using as learning aid comes from Flare, Spark and other examples
that i could gather from nitro sites.
To simplify, i will just describe how i organised the blog page :)
in run.rb i have declared,
require 'src/controller'
require 'src/controllers/blog'
...
Server.map = {
'/' => SiteController,
'/blog' => BlogController,
...
}
A generic class Page < Nitro::Element that is shared between pages is
defined in src/skin.rb. The other classes render a portion of a page.
Example:
class Page < Nitro::Element
include GenericPage
def header
%~
<div id="header">
<div id="header_inner">
[...]
~
end
def render
%~
#{doctype}
<html xmlns="http://www.w3.org/1999/xhtml">
#{head}
<body>
<div id="page">
#{header}
#{content}
#{footer}
</div>
</body>
</html>
~
end
end
[...]
class Sidebar < Nitro::Element
def render
%{
<div id="sidebar">
#{content}
</div>
}
end
end
the skin of the blog resides in 'src/skins/blog.rb'.
The controller 'src/controllers/blog.rb contains
require 'nitro/controller'
require 'src/models/blog'
class BlogController < Nitro::Controller
helper :pager, :javascript, :benchmark
before :login_filter
cache_output :index, :article, :category
def index
@articles, @pager = paginate(Article, :order => 'oid DESC',
:per_page => 5)
end
def article(oid)
@article = Article[oid]
end
[...]
end
The model 'src/models/blog.rb is the model.rb you will find in Flare
the quote where i took the example is,
# A category of items.
class Category < Content
is Orderable
has_many Article
def to_href
"category/#@oid"
end
end
the skin 'src/skins/blog.rb contains,
require 'nitro/element'
require 'src/skin'
class BlogPage < Nitro::Element::Page
[...]
end
Here, i can redefine header, footer, css etc. that differ from the other
pages.
All the templates of the blog reside in templates/blog/
index.xhtml contains something like,
<BlogPage>
<MenuBar>
<render href="/bar" />
</MenuBar>
<Center>
<render href="/blog/articles" />
</Center>
</BlogPage>
articles.xhtml comes from Flare.
Actually, the local path for the blog or what i called relative path is
/blog and is defined in Server.map.
If i add either in run.rb or in the blog controller
'src/controllers/blog.rb' the following line:
require 'src/skins/blog.rb'
to define the new skin for the page, the "local" path in model,
controller and templates that belong to the blog page will suddenly
change to '/' instead of been left to '/blog' and that will confuse
nitro server.
To summarize, the local path should not change at all.
Jj
--
|\ _,,,---,,_
ZZZzz /,`.-'`' -. ;-;;,_
|,4- ) )-,_. ,\ ( `'-'
'---''(_/--' `-'\_)
More information about the Nitro-general
mailing list