AS3 Implementing a simple Templating System

A simple as3 templating system based on key=values.

Usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// dinamically declaring properties over our "dynamic" class

var tmp:TemplateVariables = new TemplateVariables();
tmp.helloWorld = "HELLO WORLD";
tmp.date = new Date();
trace( TemplateParser.parse( "${helloWorld} :: ${date}", tmp ) )

// passing an object to the constructor

import es.xperiments.utils.*;
var tmp1:TemplateVariables = new TemplateVariables( { helloWorld:'HELLO WORLD', date:new Date() } );
trace( TemplateParser.parse( "${helloWorld} :: ${date}", tmp1 ) )

// passing an old LoadVars String

import es.xperiments.utils.*;
var tmp2:TemplateVariables = new TemplateVariables( 'helloWorld=HELLO WORLD&date='+new Date() );
trace( TemplateParser.parse( "${helloWorld} :: ${date}", tmp2 ) )

templateparser.as

templatevariables.as

Comment are closed.