Le 19 mai 2013 à 06:34, Bahman Movaqar <
b.mo...@gmail.com> a écrit :
> After looking over the tutorial and samples, it appears to me that presentation is done by creating HTML with Python or using meld. I don't know meld but going through PresentationTier, it looks to me like templating is done at page-level (please correct me if I'm wrong). This, IMHO, contrasts with the clever component-model of Nagare.
>
> Is there any way to define a component along with its XHTML snippet without knowing/caring about the whole page design?
Yes, it's possible at the component level. In fact, it's just how we use meld templating.
For example, here is now the `counter` component with a meld view:
# --
# File: counter.py
import os
from nagare import presentation
class Counter(object):
def __init__(self):
self.val = 0
def increase(self):
self.val += 1
def decrease(self):
self.val -= 1
@presentation.render_for(Counter)
def render(counter, h, comp, *args):
# 1. Parse the template into a DOM
filename = os.path.join(os.path.dirname(__file__), 'counter.xml')
template = h.parse_html(filename, xhtml=True)
# 2. Dynamize the DOM
template.findmeld('value').fill(counter.val)
template.findmeld('decrease').action(counter.decrease)
template.findmeld('increase').action(counter.increase)
# 3. Return the DOM
return template
# --
# File: counter.xml
<div xmlns:meld="
http://www.plope.com/software/meld3">
<div meld:id='value'>0</div>
<a meld:id='decrease'>--</a> | <a meld:id='increase'>++</a>
</div>
Exactly like the pseudo-code you wanted:
> For example consider the following pseudo-code:
>
> # component1.py
> class Component1:
> def __init__(self):
> self.value1 = 10
>
> @presentation.render_for(Component1)
> def render(comp, h, *args):
> # set value for 'placeholder1'
> template.get("placeholder1").set(comp.value1)
>
> # component1.xhtml
> <div id="placeholder1"></div>
>
> And then package component1.py and component1.xhtml together as one re-usable unit.
>
> Is it possible? Am I getting something wrong?
>
> TIA,
> --
> Bahman
Best regards,
Alain