Parsing formulas on the fly via @Eval and @While
Category show-n-tell thursday
Here's the scenario: configuration documents are used to define content (i.e. selectable values in a drop-down), but that content must be a mixture of statically and dynamically defined information, and how the dynamically defined content is determined needs to be adaptable over time. If you're at R6 or above, this is easy: place any formula that should be evaluated at run-time within wiki-style markup in the configuration data, then parse it using @While and @Eval.
strContent := (reference to configuration data, such as a field on the current document or a DbLookup);
@While( @Contains(strContent;"[formula]");
strLeftOfMarkup := @Left(strContent;"[formula]");
strRightOfMarkup := @Right(strContent;"[/formula]");
strRunTimeFormula := @Right(@Left(strContent;"[/formula]");"[formula]");
strContent := strLeftOfMarkup + @Eval(strRunTimeFormula) + strRightOfMarkup
);
strContent
This could be used, for example, to dynamically specify dynamic information at the top of a web page:
Welcome to the [formula]@DbTitle[/formula] website. You are currently logged in as [formula]@Name([CN];@UserName)[/formula].
Then if you later decide to change what information is displayed or how it is determined (i.e. evaluate a querystring), you can do so simply by updating the configuration data, instead of having to update the application's code.
Here's the scenario: configuration documents are used to define content (i.e. selectable values in a drop-down), but that content must be a mixture of statically and dynamically defined information, and how the dynamically defined content is determined needs to be adaptable over time. If you're at R6 or above, this is easy: place any formula that should be evaluated at run-time within wiki-style markup in the configuration data, then parse it using @While and @Eval.
strContent := (reference to configuration data, such as a field on the current document or a DbLookup);
@While( @Contains(strContent;"[formula]");
strLeftOfMarkup := @Left(strContent;"[formula]");
strRightOfMarkup := @Right(strContent;"[/formula]");
strRunTimeFormula := @Right(@Left(strContent;"[/formula]");"[formula]");
strContent := strLeftOfMarkup + @Eval(strRunTimeFormula) + strRightOfMarkup
);
strContent
This could be used, for example, to dynamically specify dynamic information at the top of a web page:
Welcome to the [formula]@DbTitle[/formula] website. You are currently logged in as [formula]@Name([CN];@UserName)[/formula].
Then if you later decide to change what information is displayed or how it is determined (i.e. evaluate a querystring), you can do so simply by updating the configuration data, instead of having to update the application's code.








Comments
Sean---
Posted by Sean Burgess At 13:18:51 On 07/07/2006 | - Website - |