Toupl
Encyclopedia
Toupl is a multi target language simplified generic template engine
Template engine
A template engine is software that is designed to process web templates and content information to produce output web documents. It runs in the context of a template system.-Types:...

. It works on the principle of compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

 \ preprocessor
Preprocessor
In computer science, a preprocessor is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers...

, producing target language source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

. Syntax based on Foobar 2000 Tagz Script, but modified and extended for template engine
Template engine
A template engine is software that is designed to process web templates and content information to produce output web documents. It runs in the context of a template system.-Types:...

 purposes.
Currently supporting generation to:
  • C++
    C++
    C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

  • C#
  • Java
    Java (programming language)
    Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

  • JavaScript
    JavaScript
    JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

  • ECMAScript
    ECMAScript
    ECMAScript is the scripting language standardized by Ecma International in the ECMA-262 specification and ISO/IEC 16262. The language is widely used for client-side scripting on the web, in the form of several well-known dialects such as JavaScript, JScript, and ActionScript.- History :JavaScript...

  • Lua
    Lua
    Lua may refer to:* Lua , a Roman goddess* Lua , a traditional Hawaiian martial art* Lua , a lightweight, extensible programming language* Lua , a single by the folk rock band Bright Eyes...

  • PHP
    PHP
    PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

  • Python
    Python (programming language)
    Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

  • Visual Basic
    Visual Basic
    Visual Basic is the third-generation event-driven programming language and integrated development environment from Microsoft for its COM programming model...

    .

Syntax

Text may be simply outputted as is.

Hello world!


This are no other operator except variable\expression output, condition variable\expression output and target language code include. Other operators such as for while etc. must be written in terms of target language operators.

Target language target language variable or expression can be outputted by enclosing in % % tags

Variable var0 is equivalent %var0%
1+2=%1+2%


Target language code can be included by enclosing in ?% %? tags

?%
int i;
int n=100;

while(i {
%?%i*i% ?%
++i;
}
%?


Native condition output must by following construction

?%
var _genImage=function(src,alt,width,height)
{
%?
&%alt%&%][%
?%
return fpText;
}
%?

Conditional text putted between [% %] tags and will be outputted if all condition variables inside not null.
Conditional variables same as ordinary variables but enclosing by &% %& instead % %.

As in any language - there is a own comments

/%
block comment
%/
//% line comment


In situation, when you need output text, that contains elements\tags of toupl,you can enclose this in special ignore tags !% %!

!% all /% this % text ?% outputted %]
even !% you can output %!
!% if you want to output %!%! - simply twice is %!

Example of generation

For example. Simple HTML
HTML
HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....

 table generation.

/%
Generate html table
%/

?%
var _genTable=function(table)
{
var fpText="";
%?

?%
for(var i=0;i {
%?

?%
for(var j=0;j {
%?

?%
}
%?
?%
}
%?
[%&%table[i][j]%&%]

?%
return fpText;
}
%?


After generation we get

var _genTable=function(table)
{
fpText="";
fpText+="\n\n";

for(var i=0;i {
fpText+="
\n";

for(var j=0;j {
fpText+="
\n";

}
fpText+=" \n";

}
fpText+="
";
var fpVar188;
var fpVar190;
fpVar188=(fpVar190=table[i][j],_fpT(fpVar190));
if(fpVar188)
{
fpText+=fpVar190;
}
fpText+="
\n";

return fpText;
}

Next we must define _fpT test function

var _fpT=function(obj)
{
return typeof(obj)!="undefined" && obj!=null;
}


And calling this code

document.write(_genTable(1,2],[null,4));


we get










1 2
4

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK