Skip to content

Commit

Permalink
Bars v0.4.0
Browse files Browse the repository at this point in the history
  - New comiler using CompileIt.
  - Pre-compile to mini-JSON (arrays).
  - Block {{else <block>}}.
  - Update tree shrinking.
  • Loading branch information
Michaelangelo Jong committed Oct 8, 2016
1 parent 8e5d686 commit 1d1b3c1
Show file tree
Hide file tree
Showing 15 changed files with 2,117 additions and 2,366 deletions.
157 changes: 79 additions & 78 deletions benchmark/bars.js

Large diffs are not rendered by default.

157 changes: 79 additions & 78 deletions demo/bars.js

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
</script>
<script id="bars-template" type="text/x-handlebars-template">
<ul>
{{#each @sort(persons, 'length')}}
<li>{{@number(@index) + 1}} - {{.}}<input type="text" /></li>
{{#each @sort(persons, 'name')}}
<li>{{@number(@index) + 1}} - {{name}}</li>
{{/each}}
</ul>

{{#if x < 5}}
<span>x is less then 5</span>
{{else if x > 5}}
<span>x is greater then 5</span>
{{else}}
<span>x is not less then 5</span>
<span>x is equal to 5</span>
{{/if}}

<br>
<br>

{{>title}}

</script>
<script src="bars.js"></script>
</head>
Expand All @@ -32,12 +37,9 @@

window.barsData = {
persons: [
// { name: 'John' },
// { name: 'Jane' },
// { name: 'Jim' },
'John',
'Jane',
'Jim'
{ name: 'John' },
{ name: 'Jane' },
{ name: 'Jim' },
],
x: 2,
title: 'The Cat in the Hat'
Expand All @@ -50,7 +52,10 @@
});
});

window.domFrag = bars.compile(template).render();
preCompiled = [0,"0.4.0","DOM",[1,[[3,"ul",[],0,[[5,"each",[10,"sort",[[9,["persons"]],[8,"length"]]],null,[1,[[3,"li",[],0,[[6,[11,"+",[[10,"number",[[9,["@","index"]]]],[8,1]]]],[2," - "],[6,[9,[]]],[3,"input",[[4,"type",[[2,"text"]],0]],0,[],0]],1]],1],null]],1],[5,"if",[11,"<",[[9,["x"]],[8,5]]],null,[1,[[3,"span",[],0,[[2,"x is less then 5"]],0]],1],[5,"if",[11,">",[[9,["x"]],[8,5]]],null,[1,[[3,"span",[],0,[[2,"x is greater then 5"]],0]],0],[1,[[3,"span",[],0,[[2,"x is equal to 5"]],0]],0]]],[3,"br",[],0,[],0],[3,"br",[],0,[],0],[7,"title",null,null,null]],1]];

// window.domFrag = bars.compile(template).render();
window.domFrag = bars.build(preCompiled).render();
window.domFrag.appendTo(document.getElementById('bars-output'));
window.domFrag.update(barsData);

Expand Down
12 changes: 10 additions & 2 deletions lib/bars-runtime.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Generator = require('generate-js'),
Renderer = require('./renderer'),
Token = require('./compiler/tokens'),
Blocks = require('./blocks'),
Transform = require('./transforms'),
packageJSON = require('../package');
Expand All @@ -17,9 +18,16 @@ var Bars = Generator.generate(function Bars() {
Bars.definePrototype({
version: packageJSON.version,
build: function build(parsedTemplate) {
var _ = this;
var _ = this,
program = parsedTemplate;

if (Array.isArray(parsedTemplate)) {
program = new Token.tokens.program();

program.fromArray(parsedTemplate);
}

return new Renderer(_, parsedTemplate);
return new Renderer(_, program.fragment);
},

registerBlock: function registerBlock(name, block) {
Expand Down
5 changes: 2 additions & 3 deletions lib/bars.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
var Bars = require('./bars-runtime'),
compile = require('./compiler/compiler3');
compile = require('./compiler');


Bars.definePrototype({
compile: function compile(template, filename, mode, flags) {
var _ = this;
return _.build(_.parse(template, filename, mode, flags)
.fragment);
return _.build(_.parse(template, filename, mode, flags));
},

parse: function parse(template, filename, mode, flags) {
Expand Down
152 changes: 0 additions & 152 deletions lib/compiler/code-buffer.js

This file was deleted.

Loading

0 comments on commit 1d1b3c1

Please sign in to comment.