iVelocity is a light template engine that support iOS and VTL. It will useful to generate a html from template file and NSDictionary data in iOS. And JSON can easy to become a NSDictionary to use. Now, the iOS App is more easy than ever!
iVelocity Data Flow
Template: <test1>#set($b[0]=1)</test1><test2>#set($b[1]=2)</test2>
Render Result: <test1></test1><test2></test2>
Template: <test3>#foreach($a in $b) $a #end</test3>
Render Result: <test3> 1 2 </test3>
Template: <test3>#if(1)<yes>#else<no>#end</test3>
Render Result: <test3><yes></test3>
-
Use:
- (int) initWithTemplate:(NSString *)temp // VTL String withKey:(NSString *)key // VTL String Name, used for cache forceFlush:(BOOL)mustflush; // YES: parse the VTL even if cache match! // NO: used the cached object if match.
-
to load a VTL(velocity template file).
- (int) initWithFile:(NSString *)filename // xxx.vm file that support VTL forceFlush:(BOOL)mustflush; // YES: parse the VTL even if cache match! // NO: used the cached object if match.
to load a VTL from File base on resources in iOS.
-
Then generate render result by:
- (RenderStatus) renderBlockWithData:(NSMutableDictionary *)dictionaryData returnString:(NSMutableString *)strResult;
the result is return by strResult. and the data is saved or modified in dictionaryData.
-
If you has confused with the syntax of template file that parsed by iVelocity, can use print method to print the syntax structure in Console.
- (void) print;
-
check the version of iVelocity.
- (NSString *) version;
svn checkout http://ivelocity.googlecode.com/svn/trunk/ ivelocity-read-only
Snap Shot
(1) Q:If the data is from more than one dictionary?
A: iVelocity support more than one dictionary. for example: VTL: $a,$b,$c call render with dictionary1(a,b) call render with dictionary2(a,c) the result $a use dictionary2, but $b use dictionary1, $c use dictionary2.