Hi Betrand,
this is what we want:
...I still think having a
level of inheriance and aspect-orientation in rendering is something
we want, because it eases the development process....
I agree that this might be useful in some cases - but do you think we
can achieve this efficiently and simply with a path-based system for
selecting scripts? I fear that it might be very hard to find rules for
conflict resolution and priorities that work for all users.
What about doing it this way:
In Sling, we already have a concept of delegation. This means, a
resource delegates the rendering of the children to the children's
scripts by calling
Sling.include(path)
Thinking of XSLT, this is similar to <xsl:apply-templates />
Continuing to think about XSLT, what is the equivalent of <xsl:apply-
imports /> that is used in XSLT to build complex modular stylesheets?
My proposal would be to add
Sling.handle()
Sling.handle(type)
Sling.handle(type, selector)
to the API.
Sling.handle() would simply delegate the rendering/script execution to
all declared supertypes/mixins. Those that have a script (for this
selector) execute it. You could also add Sling.handle() as a default
fallback script, provided there is no script defined for
slingResourceType.
Sling.handle(type) delegates rendering/script execution to the mixing
or supertype specified. No script is defined for this type, nothing is
done. This makes it possible to include a <%
Sling.handle("mix:versionable") %> in the sidebar of the page,
rendering the version history if there is one. It also serves the
separation of concerns, as the main script only renders what it knows
and mixin-specific scripts render mixin-specific content.
Sling.handle(type, selector) is basically the same, but allows the
user to change the selector while delegating. It can be useful if you
want to have different views of a mixin, giving you the same
flexibility you have with the original content.
With this approach you have both: inheritance in rendering through
Sling.handle() and aspect-orientation through Sling.handle(type)
This combines your meta-script idea with a handling of mixins, allows
for an implementation that does not traverse the node tree or type
graph and is easy to understand.
Open questions for me are following:
- do we want to establish a precedence order for Sling.handle()
- do we want to add something like Sling.skip() that will skip the
execution of a script and Sling.skipIfNext() that skips the execution
if and only if there is another script in the execution chain that
does not skip.
regards,
Lars