You could start by looking at ISparkExtension and
ISparkExtensionFactory.It is essentially a hook-in mechanism in the
spark compiler. You need to provide an implementation for:
public interface ISparkExtensionFactory
{
ISparkExtension CreateExtension(VisitorContext context,
ElementNode node);
}
In that method you can evaluate, given the visitor context and the
node, whether you want to return a custom extension. Then you can use
your custom extension to either do custom output rendering in the
render method of the view (that is in the VisitChunk) and similar.
public interface ISparkExtension
{
void VisitNode(INodeVisitor visitor, IList<Node> body,
IList<Chunk> chunks);
void VisitChunk(IChunkVisitor visitor, OutputLocation
location, IList<Chunk> body, StringBuilder output);
}
public enum OutputLocation
{
NotWriting,
UsingNamespace,
ClassMembers,
RenderMethod,
}
You can look here for a somewhat advanced usage example:
- http://github.com/loudej/spark/blob/master/src/Castle.MonoRail.Views.Spark/ViewComponentExtensionFactory.cs
- http://github.com/loudej/spark/blob/master/src/Castle.MonoRail.Views.Spark/ViewComponentExtension.cs
Those are a bit hard to swallow if you haven't heard of the visitor
pattern and how most parsers/compilers and such walk through an
abstract syntax tree...
Perhaps someone (louis ;) could give you a simple example ...
Hope this helps :)
VisitNode is where interpretation and manipulation of spark template
contents when they are in a node phase or representation that is
similar to that of xml.
VisitChunk is where the template is in its textual code
representation, i.e. where you output code to the render method,
generate class members and so on.
By introducing your own visitor of some kind, you can suddenly
recognize unknown tags or attributes that Spark would not handle. It
is quite flexible in that regard.
Again, you could call out for Louis to get an example of the params in
those two methods in order to get some concrete simple scenario
explained.. He is after all the bright head that did all of this
amazing work :)
Cheers :)
--
You received this message because you are subscribed to the Google Groups "Spark View Engine Dev" group.
To post to this group, send email to spar...@googlegroups.com.
To unsubscribe from this group, send email to spark-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spark-dev?hl=en.