Skip to content

Commit

Permalink
Merge pull request #28 from m0nzderr/2.0.0-wip
Browse files Browse the repository at this point in the history
0.0.21-alpha
  • Loading branch information
m0nzderr committed Sep 22, 2016
2 parents 96422a5 + 4a57614 commit 21755a9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clearest",
"version": "0.0.20-alpha",
"version": "0.0.21-alpha",
"description": "Clearest Framework",
"main": "index.js",
"repository": {
Expand Down Expand Up @@ -30,7 +30,7 @@
"istanbul": "^0.4.0",
"istanbul-coveralls": "^1.0.3",
"mocha": "^2.3.3",
"mocha-phantomjs": "^4.0.1",
"mocha-phantomjs": "^4.1.0",
"mocha-phantomjs-istanbul": "0.0.2",
"should": "^7.1.0"
},
Expand Down
23 changes: 22 additions & 1 deletion test/tool/xvdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe('tool / xvdl instructions', function () {
it("s:*", function () {
//TODO: $filter
//TODO: $bind
//TODO: $orderby


compiler.compile(dom.parseFromString('<s:bar/>'))
.should.be.exactly('S(P.sel($context,"bar"))');
Expand All @@ -351,6 +351,27 @@ describe('tool / xvdl instructions', function () {
compiler.compile(dom.parseFromString('<s:bar from="foo" where="bar-expression" orderby="order-expression"><t:context/></s:bar>'))
.should.be.exactly('S(P.sel(foo,"bar",function(bar,bar$index){return bar},function(bar,bar$index){return bar-expression},function(bar,bar$index){return order-expression}))');

// $order-function

compiler.compile(dom.parseFromString('<s:bar from="foo" order="myfun"><t:context/></s:bar>'))
.should.be.exactly('S(P.sel(foo,"bar",function(bar,bar$index){return bar},false,myfun))');

compiler.compile(dom.parseFromString('<s:bar from="foo" where="bar-expression" order="myfun"><t:context/></s:bar>'))
.should.be.exactly('S(P.sel(foo,"bar",function(bar,bar$index){return bar},function(bar,bar$index){return bar-expression},myfun))');

});

// alternative to s:* with explicit syntax
it("t:select", function () {

// direct js
compiler.compile(dom.parseFromString('<t:select property="foo+bar"/>'))
.should.be.exactly('S(P.sel($context,foo+bar))');

// sub-select expression
compiler.compile(dom.parseFromString('<t:select property="{{bar}}" from="foo"/>'))
.should.be.exactly('S(P.get(function($1){return P.sel(foo,$1)},[P.sel($context,"bar")]))');

});

it("$e:* (handler code generation)", function () {
Expand Down
8 changes: 5 additions & 3 deletions tool/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,24 @@ module.exports = {

file.path = processor.outputFilename(file.path); // rename output file (as compiler/processor would see it)

var noop = function(e){return e;}
var opts = {
currentLocation: originalPath,
// extend environment vaiables with path information
environment: extend(true,
config.environment, {
config.environment, (config.computeEnvironment||noop)({
source: {
file: path.basename(originalPath),
path: originalPath,
dir: path.dirname(originalPath)
dir: path.dirname(originalPath),
rel: file.relative
},
target: {
file: path.basename(file.path),
path: file.path,
dir: config.targetDir
}
})
}))
};

if (config.targetDir)
Expand Down
58 changes: 49 additions & 9 deletions tool/xvdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,40 @@ function XvdlCompiler(userConfig) {
return elementInstructions.template.get(acc, node, extend({}, scope, {$context: newContext}))
}
},

/**
* t:select - explicit select
* <t:select property="{{foo}}+{{bar}}" from="bar"/>
*/
select: function (acc, node, scope) {
if (!node.hasAttribute("property"))
throw compilerError("@propery attribute not specified", node);
var flags = {};
var properyExpression = compileExpression(node.getAttributeNode("property"),scope,true,flags);

if (flags.needAggregatorCall) {
// has select inside,

var buff=[];
elementInstructions.select(buff, node, scope, '$1');

acc.push(
apicall(API.get, [
// template closure
codegen.closure({
args: codegen.list(['$1']),
ret: buff[0]
}),
codegen.array([properyExpression])
])
);

return true;
} else
// plain js expression
return elementInstructions.select(acc, node, scope, properyExpression)
},

get: function (acc, node, scope) {

// <t:get foo="expression"/>
Expand Down Expand Up @@ -961,9 +995,9 @@ function XvdlCompiler(userConfig) {

/**
* Select instruction
* s:* [@from @as (@where @orderby || @filter)]
* s:* [@from @as (@where (@orderby || @order)|| @filter)]
*/
select: function (acc, node, scope) {
select: function (acc, node, scope, propertyExpression) {

// deal witrh @from attribute
var context = node.getAttribute("from") || scope.$context;
Expand All @@ -976,7 +1010,7 @@ function XvdlCompiler(userConfig) {
if (isEmpty(node)) {
// <s:foo/>

selectArgs = [context, codegen.string(node.localName)];
selectArgs = [context, propertyExpression || codegen.string(node.localName)];

if (node.hasAttribute("where")) {
selectArgs.push("false"); // filler
Expand All @@ -995,8 +1029,9 @@ function XvdlCompiler(userConfig) {
args: codegen.list(itemClosureArgs),
ret: compileExpression(node.getAttribute("orderby"), scope, true)
}));
} else if (node.hasAttribute("order")) {
selectArgs.push(node.getAttribute("order"));
}

}
else {
// <s:foo>...</s:foo>
Expand Down Expand Up @@ -1027,13 +1062,18 @@ function XvdlCompiler(userConfig) {
}));
}

if (node.hasAttribute("orderby")) {
if (node.hasAttribute("orderby") || node.hasAttribute("order")) {
if (!node.hasAttribute("where"))
selectArgs.push("false"); // filler
selectArgs.push(codegen.closure({
args: codegen.list(itemClosureArgs),
ret: compileExpression(node.getAttribute("orderby"), scope, true)
}));

if (!node.hasAttribute("order")) {
selectArgs.push(codegen.closure({
args: codegen.list(itemClosureArgs),
ret: compileExpression(node.getAttribute("orderby"), scope, true)
}));
} else {
selectArgs.push(node.getAttribute("order"));
}
}

//TODO: implement @filter
Expand Down

0 comments on commit 21755a9

Please sign in to comment.