JavaScript::Ectype - A JavaScript Preprocessor designed for large scale javascript development
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.
use JavaScript::Ectype; JavaScript::Ectype->convert( target => $script_name, path => $TEST_PATH, );
JavaScript::Ectype interprets "//=foobar" style macros in javascript code.
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.
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; });
if your js code has "//=depends" macro,
//=depends full.qualified.name;
"full.qualified.name".namespace().depends();
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.
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;
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; }); }); }); }
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 ); });
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] */ });});
Daichi Hiroki, <hirokidaichi<AT>gmail.com>
<hirokidaichi<AT>gmail.com>
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.
To install JavaScript::Ectype, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JavaScript::Ectype
CPAN shell
perl -MCPAN -e shell install JavaScript::Ectype
For more information on module installation, please visit the detailed CPAN module installation guide.