Skip to content

Commit

Permalink
打包为npm
Browse files Browse the repository at this point in the history
  • Loading branch information
penglei committed Dec 21, 2013
1 parent 2d8ef53 commit 22625e9
Show file tree
Hide file tree
Showing 137 changed files with 215 additions and 294 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
node_modules
resource/cs
test/dev/resource/cs

# Editor backup files
*.bak
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ parse:

#jison clearsilver.y clearsilver.l -m amd


parse-debug:
@cd parse && \
jison clearsilver.y clearsilver.l --debug true
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ clearsilver template engine with debugger

##usage

1.安装依赖

npm -g install express
npm -g install socket.io

2.使用示例

git clone https://github.com/penglei/jencs
cd jencs
node test.js --enable-debugger
Usage: jencs <path> [data] [options]

path clearsilver template file
data hdf data file

Options:
--debug enable debugger [false]
--debug-brk enable debugger and break on first line. [false]
--include the dir of include command <?cs include:... ?> [.]
--ignore-whitespace ignore \r\n\t of clearsilver template file [false]
82 changes: 65 additions & 17 deletions bin/jencs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,78 @@
var fs = require('fs');
var path = require('path');

var CSInterpreter = require('../interpreter');

var CSInterpreter = require('jencs');
var Engine = CSInterpreter.Engine;
var AST = CSInterpreter.AST;

var dataHdfFile;
var entryCsFile;
//内容\n\r\t过滤器
function ContentWhiteFilter(valueStr, astNode){
return astNode instanceof AST.AST_Content ? valueStr.replace(/[\r\n\t]/g, '') : valueStr;
}

process.argv.forEach(function (val, index, array) {
if (/\.cs$/.test(val)){
entryCsFile = val;
} else if (/\.hdf$/.test(val)){
dataHdfFile = val;
}
});
var opts = require('nomnom')
.script("jencs")
.options({
"path": {
position: 0,
required: true,
help: "clearsilver template file",
list: false
},
"data": {
position: 1,
required: false,
help: "hdf data file"
},
"debug": {
//flag: true,
default: false,
help: "enable debugger"
},
"debug-brk": {
//flag: true,
default: false,
help: "enable debugger and break on first line."
},
"include":{
type:"string",
help: "the dir of include command <?cs include:... ?>",
default: '.'
},
"ignore-whitespace": {
help: "ignore \\r\\n\\t of clearsilver template file",
default: false
}
}).parse();

if (opts["debug-brk"]) opts["debug"] = true;

var mainCsSource = fs.readFileSync(opts.path, "utf8");
var csIncludeRoot = path.resolve(opts.include || ".");

if (opts.data){
var dataSource = fs.readFileSync(path.resolve(opts.data), "utf8");
} else {
var dataSource = "";
}

var mainCsSource = fs.readFileSync(entryCsFile, "utf8");
var dataSource = fs.readFileSync(dataHdfFile, "utf8");
var csEngine = new Engine();

var TestCSEngine = new Engine();
//必须先设置inlcude的回调,否者分析源码时会找不到包含的文件
csEngine.setLexerInclude(function(filename){
return fs.readFileSync(path.resolve(csIncludeRoot, filename), "utf8");
});

if (opts["ignore-whitespace"]) csEngine.addOutputFilter(ContentWhiteFilter);

csEngine.setConfig({
"debug": opts.debug,
"includeBase": csIncludeRoot//包含文件的起始路径。暂时只给调试器使用这个选项
});

TestCSEngine.initEntrySource(mainCsSource);
TestCSEngine.setEndListener(function(){
csEngine.setEndListener(function(result){
process.stdout.write(this.result);
});

TestCSEngine.run(dataSource);
csEngine.initEntrySource(mainCsSource, opts.path);
csEngine.run(dataSource);
16 changes: 2 additions & 14 deletions interpreter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var Executer = require("./executer").Executer;

var DebugService = require("./debugger").DebugService;

//放在这里而不是executer里面,是因为executer里的def_execute会被它们用到,这就会形成循环依赖
require("./block");
require("./statement");
require("./expr");
Expand Down Expand Up @@ -49,19 +48,6 @@ function Engine(csString){
this._onRenderListeners = [];
}

Engine.prototype.request = function(type, val, cb){/*
if (type == "fetchVarValue"){
var csSubParser = new ClearSilverParser();
val = "<?cs " + val + "?>";
try{
var valast = csSubParser.parse(source);
} catch(e){
if (cb();
}
}
*/
};

//include在语法分析阶段就完成要方便得多
Engine.prototype._lexInclude = function(includeName) {
var self = this;
Expand Down Expand Up @@ -199,6 +185,8 @@ Engine.prototype.setConfig = function(opts){
Engine.prototype.run = function(hdfData){
if (typeof hdfData == "string"){
hdfData = HDF.parse(hdfData);
} else {
hdfData = {};
}

this.result = "";
Expand Down
6 changes: 3 additions & 3 deletions interpreter/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ Context.prototype = {
},
"output": function(str, astNode){
if (str === undefined) return;
try{
//try{
str = this._runFilters(str, astNode);
this._renderSinppetsCallback(str);
} catch(msg){
//} catch(msg){
//do nothing
}
//}
},
"pushEscapeFilter": function(type){
if (type == "html") this._escapeFilters.push(internalHtmlFilter);
Expand Down
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "jencs",
"version": "0.1.0",
"description": "clearsilver render engine, with a debugger",
"keywords": [
"clearsilver",
"debugger"
],
"author": {
"name": "soulfree",
"email": "[email protected]"
},
"dependencies": {
"nomnom": ">= 1.6.0",
"socket.io" : "~0.9.16",
"express": "~3.4"
},
"devDependencies": {
},
"main": "interpreter/index.js",
"bin": {
"jencs": "bin/jencs"
},
"engines": {
"node": ">= 0.7.0"
}
}
38 changes: 0 additions & 38 deletions resource/test.js

This file was deleted.

1 change: 0 additions & 1 deletion resource/wupdata.hdf

This file was deleted.

79 changes: 0 additions & 79 deletions test.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions test/dev/resource/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
all:test_my

MY_TESTS_DATA=wupdata-1.hdf wupdata-2.hdf
test_my:
@echo "Running wup cs tests";
@failed=0;\
for wupdata in $(MY_TESTS_DATA); do \
jencs cs/wupmain.cs $$wupdata --include=./cs/module > $$wupdata.out.html; \
diff $$wupdata.out.html $$wupdata.gold.html > $$wupdata.diff; \
return_code=$$?; \
if [ $$return_code -ne 0 ]; then \
echo "$$wupdata" test failed!; \
failed=1; \
else \
rm -rf $$wupdata.out.html; \
rm -rf $$wupdata.diff; \
fi; \
done; \
if [ $$failed -eq 1 ]; then \
echo "Test wupdata Failed!"; \
else \
echo "All wupdata test passed!"; \
fi;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion unit/interpreter/test.cs → test/dev/test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<?cs #include:"test_d_macrodef.cs"?>
-----if-------

<?cs set:a = 333?>
<?cs set:a = "<b>sss</b>"?>

<?cs var:a?>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions test/hdf/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
node test
Loading

0 comments on commit 22625e9

Please sign in to comment.