Loading macro's and vipers
The <modules> section in the Smartite.config file declares the modules to be loaded, the macros that will be available at runtime and settings to be used by them.
The modules section can best be read as a set of methods sequentially applied to the runtime: there are Add, Set and Remove statements that will be applied in the given order.
Loading assemblies
First, modules are loaded from the given assembly locations:
XML | Copy Code |
---|---|
<add path="/bin/" /> |
Shared presets
Then, shared presets are declared:
XML | Copy Code |
---|---|
<presets> <preset name="coollinks"> <set parameter="resultformat"> <![CDATA[<ul class="cool">{this.result()}</ul>]]> </set> <set parameter="rowformat"> <![CDATA[ <li> <a href="{this.location()}">{this.title()}</a> </li> ]]> </set> </preset> </presets> |
These shared presets can be applied to a list of macros:
XML | Copy Code |
---|---|
<add macro="xlinks"> <apply preset="coollinks"/> </add> |
Dedicated presets
If a preset is applicable to only one macro, it can be declared directly when adding/updating a macro.
XML | Copy Code |
---|---|
<add macro="xlinks"> <set parameter="resultformat"> <![CDATA[<ul class="cool">{this.result()}</ul>]]> </set> <set parameter="rowformat"> <![CDATA[ <li> <a href="{this.location()}">{this.title()}</a> </li> ]]> </set> </add> |
Both in the apply and in the set methods, an overridable attribute can be used to specify whether the property/preset will be user-settable. When overridable is set to "false", the propertywill be fixed. Otherwise, it will merely be a default setting.
Inherited macros
You can add new macros declaratively by using the inherit attribute. Below is an example of a macro inheriting from the SqlQuery macro, using a fixed connection:
XML | Copy Code |
---|---|
<add macro="sqlquery.advworks" inherit="sqlquery" description="Represents a customized SqlQuery macro to view data in the AdventureWorks database." > <set parameter="connection" overridable="false" >AdventureWorks</set> </add> |
Specialized macros can be created by inheriting from other macros and setting defaults or fixed parameters, but can also have their own 'virtual' parameters. Below, a copyright macro is created using the text macro and declaring some virtual properties:
XML | Copy Code |
---|---|
<!-- Create new macro named 'copyright' from 'text' --> <add macro="copyright" inherit="text" description="Represents a customizable Copyright notice." > <set parameter="author" description="Sets the author for the copyright notice">Marc van Neerven</set> <set parameter="email" description="Sets the e-mail address for the copyright notice">marc@smartsite.nl</set> <set parameter="year" description="Sets the year for the copyright notice">marc@smartsite.nl</set> <set parameter="value"> <![CDATA[ <div id="copyright">© {this.getparameter('year', default=datetime.getyear(datetime.now()))} <a href="mailto:{this.getparameter(email)}">{this.getparameter(author)}</a><div> ]]> </set> </add> |
Removing macros
After customizing and inheriting, you can remove macros explicitly so they cannot be used at runtime (but macros that inherited from them can!) :
XML | Copy Code |
---|---|
<remove macro="sqlquery"/> <remove macro="code"/> |