Skip to content
Snippets Groups Projects
Commit 758bd8ab authored by deuce's avatar deuce
Browse files

A much better xjs handler... works as follows:

1) If the *.xjs.ssjs file exists and is newer than the *.xjs file, simply
   load()s the *.xjs.ssjs file.
2) Otherwise, generates the *.xjs.ssjs file from the *.xjs file as follows:
   Anything inside the tag <?xjs ... ?> is SSJS.

A simple welcome.xjs page would then be as follows:
<html>
<head>
<title><?xjs write(system.name)?></title>
</head>
<body>
Your SysOp <?xjs write(system.operator)?> would like to welcome you to
<?xjs write(system.name) ?>
</body>
</html>

This is converted to welcome.xjs.ssjs as follows:
writeln('<html>');
writeln('<head>');
write('<title>');
write(system.name);
writeln('</title>');
writeln('</head>');
writeln('<body>');
write('Your SysOp ');
write(system.operator);
writeln(' would like to welcome you to');
write('');
write(system.name) ;
writeln('</body>');
writeln('</html>');

Now all you PHP folks out there can get comfortable writing XJS scripts
if I understand how PHP embedding works.
parent 95d932ee
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,79 @@
/* $Id$ */
var file = new File(http_request.real_path);
if(!file.open("r")) {
writeln("!ERROR " + file.error + " opening " + http_request.real_path);
exit();
var filename;
if(this.http_request!=undefined) /* Requested through web-server */
filename = http_request.real_path;
else
filename = argv[0];
var ssjs_filename=filename+".ssjs";
// Probably a race condition on Win32
if(file_exists(ssjs_filename)) {
if(file_date(ssjs_filename)<=file_date(filename)) {
file_remove(ssjs_filename);
}
}
if(!file_exists(ssjs_filename)) {
var file = new File(filename);
if(!file.open("r",true,8192)) {
writeln("!ERROR " + file.error + " opening " + filename);
exit();
}
var text = file.readAll(8192);
file.close();
var script="";
var in_xjs=false;
for (line in text) {
var str=text[line];
while(str != '') {
if(!in_xjs) {
if(str.search(/<\?xjs\s+/)==-1) {
script += "writeln("+escape_quotes(str)+");\r\n";
str='';
}
else {
str=str.replace(/^(.*?)<\?xjs\s+/,
function (str, p1, offset, s) {
script += "write("+escape_quotes(p1)+");\r\n";
in_xjs=true;
return '';
}
);
}
}
else {
if(str.search(/\?>/)==-1) {
script += str;
str='';
}
else {
str=str.replace(/^(.*?)\?>/,
function (str, p1, offset, s) {
script += p1+";\r\n";
in_xjs=false;
return '';
}
);
}
}
}
}
var f=new File(ssjs_filename);
if(f.open("w",false)) {
f.write(script);
f.close();
}
}
load(ssjs_filename);
function escape_quotes(arg) {
return("'"+arg.replace(/'/g,"'+"+'"'+"'"+'"+'+"'")+"'");
}
var text = file.readAll();
file.close();
write(text.join(" ").replace(/<%([^%]*)%>/g, function (str, arg) { return eval(arg); } ));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment