NAME
JavaScript::Ectype - A JavaScript Preprocessor designed for large scale javascript development
DESCRIPTION
JavaScript::Ectype Preprocessor can extend some features to javascript code with macro like syntax. These features are designed for large scale developping with javascript, concatenating other files ,providing namespace as like as Java or Scala and file-level-scope.
SYNOPSYS
use JavaScript::Ectype;
JavaScript::Ectype->convert(
target => $script_name,
path => $TEST_PATH,
);
convert get converted javascript code
use JavaScript::Ectype;
JavaScript::Ectype->convert(
target => $script_name,
path => $TEST_PATH,
);
new
file_path
is_converted
load
related_files
converted_data
SUPPORT SYNTAX
JavaScript::Ectype interprets "//=foobar" style macros in javascript code.
auto file scope
JavaScript has no file-level-scope,so every js file is in a flat hierarchy. A file level scope automatically gives to every output of Ectype Preprocessor.
The code descriving in a js file wrapped like this:
(function(){
# your great code
})();
This makes the code forced well-mannered style, which can reduce unintentional change of global variables.
declare package;
if your js code has "//=package" macro,
//=package full.qualified.name;
SOME_CODE;
convert like this:
"full.qualified.name".namespace().using( function(_namespace_) {
SOME_CODE;
});
declare dependency
if your js code has "//=depends" macro,
//=depends full.qualified.name;
convert like this:
"full.qualified.name".namespace().depends();
load file recursively
if your js code has "//=require" macro,
//=require full.qualified.name;
load /path/full/qualified/name.js or /path/full/qualified/name.ectype.js at head of your parent js file.
import from namespace
if your js code has "//=import" macro,
//=package apps.net.secure;
//=import apps.lang.class;
//=import apps.net ->XMLHTTPRequest:http,WebSocket:socket,LongPoll:comet;
//=import apps.crypt ->encrypt,decrypt,hmac;
SOMECODE;
convert like this:
with("apps.lang.class".namespace().stash()){
// all object exported in "apps.lang.class" is available in this scope.
"apps.net".namespace().within(["XMLHTTPRequest","WebScoket","LongPoll"],function(http,socket,comet){
// A,B,C in "ectype.net" namespace is available as a,b,c
"apps.crypt".namespace().within(["encrypt","decrypt","hmac"],function(encrypt,decrypt,hmac){
"apps.net.secure".namespace().using(function(_namespace_){
SOMECODE;
});
});
});
}
//=include full.qualified.name
the file is developed in the place.
//=package data.base64;
//=include lib/data/base64.js
_namespace_.publish(
encode : base64encode,
decode : base64decode
);
converted like this:
"data.base64".namespace().using(function(_namespace_){
/* content of lib/data/base64.js */
function base64encode(){}
function base64decode(){}
_namespace_.publish(
encode : base64encode,
decode : base64decode
);
});
FILE FORMAT
The code generated through Ectype Preprocessor follows the fixed file format. So, converted data does not change whereever the macros descrived.
/* [ REQUIRE SECTION ] */
/* - load other files recursively,which follow same format.*/
/* [ DEPENDENCY CHECK SECTION ] */
/* - throw error if descrived namespace does'nt declared. */
"package_own.fuga".namespace().depends();
"package_own.hoge".namespace().depends();
/* [ IMPORT HEADER SECTION ] */
"package_own.fuga.package".namespace().within(["Load"],function(Load){
"package_own.hoge.package".namespace().within(["Ext"],function(Ext){
/* [ OWN PACKAGE SECTION ] */
"package_own".namespace().using(function(_namespace_){
var Test=Class.create({initialize:function(name){this.name=name:}});
new Test("<TMPL_VAR NAME=text>");
});
/* [ IMPORT FOOTER SECTION] */
});});
AUTHOR
Daichi Hiroki, <hirokidaichi<AT>gmail.com>
LICENSE AND COPYRIGHT
Copyright 2009 Daichi Hiroki.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.