Skip to content

Commit 4a2ff1d

Browse files
committed
added: framework.onCompileView()
1 parent 1cbc7d4 commit 4a2ff1d

13 files changed

Lines changed: 70 additions & 27 deletions

File tree

changes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ source-code: "tabs" instead of "spaces"
2626
- added: `config['default-maximum-file-descriptors'] = 0` (0 = the watcher is disabled)
2727
- added: Utils.resolve(url, callback(err, uri)) DNS cache
2828
- added: Utils.clearDNS() clears DNS cache
29+
- added: framework.onCompileView(name, content, model)
30+
- added: `@{compile handlerbars}CONTENT TO COMPILE@{end}`
31+
- added: `@{compile}CONTENT TO COMPILE@{end}`
2932

3033
- updated: (IMPORTANT): for evaluation multiple roles in routing (@role) framework validates only one role
3134
- updated: GZIP compression for static files (added .md, .json)

index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function Framework() {
169169

170170
this.id = null;
171171
this.version = 1730;
172-
this.version_header = '1.7.3 (build: 26)';
172+
this.version_header = '1.7.3 (build: 27)';
173173

174174
var version = process.version.toString().replace('v', '').replace(/\./g, '');
175175

@@ -2496,6 +2496,17 @@ Framework.prototype.usage = function(detailed) {
24962496
return output;
24972497
};
24982498

2499+
/**
2500+
* Compiles content in the view @{compile}...@{end}. The function has controller context, this === controler.
2501+
* @param {String} name
2502+
* @param {String} html HTML content to compile
2503+
* @param {Object} model
2504+
* @return {String}
2505+
*/
2506+
Framework.prototype.onCompileView = function(name, html, model) {
2507+
return html;
2508+
};
2509+
24992510
/*
25002511
3rd CSS compiler (Sync)
25012512
@filename {String}

internal.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,8 +1682,10 @@ function view_parse(content, minify) {
16821682
var functionsName = [];
16831683
var isFN = false;
16841684
var isSECTION = false;
1685+
var isCOMPILATION = false;
16851686
var builderTMP = '';
16861687
var sectionName = '';
1688+
var compileName = '';
16871689
var isSitemap = false;
16881690
var text;
16891691

@@ -1707,16 +1709,25 @@ function view_parse(content, minify) {
17071709

17081710
var cmd = content.substring(command.beg + 2, command.end);
17091711
var cmd8 = cmd.substring(0, 8);
1712+
var cmd7 = cmd.substring(0, 7);
17101713

1711-
if (cmd8 === 'section ' && cmd.lastIndexOf(')') === -1) {
1714+
if (cmd7 === 'compile' && cmd.lastIndexOf(')') === -1) {
1715+
1716+
builderTMP = builder + '+(framework.onCompileView.call(self,\'' + (cmd8[7] === ' ' ? cmd.substring(8) : '') + '\',';
1717+
builder = '';
1718+
sectionName = cmd.substring(8);
1719+
isCOMPILATION = true;
1720+
isFN = true;
1721+
1722+
} else if (cmd8 === 'section ' && cmd.lastIndexOf(')') === -1) {
17121723

17131724
builderTMP = builder;
17141725
builder = '+(function(){var $output=$EMPTY';
17151726
sectionName = cmd.substring(8);
17161727
isSECTION = true;
17171728
isFN = true;
17181729

1719-
} else if (cmd.substring(0, 7) === 'helper ') {
1730+
} else if (cmd7 === 'helper ') {
17201731

17211732
builderTMP = builder;
17221733
builder = 'function ' + cmd.substring(7).trim() + '{var $output=$EMPTY';
@@ -1737,10 +1748,12 @@ function view_parse(content, minify) {
17371748
} else if (cmd === 'end') {
17381749

17391750
if (isFN && counter <= 0) {
1740-
17411751
counter = 0;
17421752

1743-
if (isSECTION) {
1753+
if (isCOMPILATION) {
1754+
builder = builderTMP + 'unescape($EMPTY' + builder + '),model) || $EMPTY)';
1755+
builderTMP = '';
1756+
} else if (isSECTION) {
17441757
builder = builderTMP + builder + ';repository[\'$section_' + sectionName + '\']=$output;return $EMPTY})()';
17451758
builderTMP = '';
17461759
} else {
@@ -1751,6 +1764,7 @@ function view_parse(content, minify) {
17511764
}
17521765

17531766
isSECTION = false;
1767+
isCOMPILATION = false;
17541768
isFN = false;
17551769

17561770
} else {

minify/merged/total.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minify/total.js/builders.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minify/total.js/index.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minify/total.js/internal.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minify/total.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@
6767
"scripts": {
6868
"test": "echo \"Error: no test specified\" && exit 1"
6969
},
70-
"version": "1.7.3-26"
70+
"version": "1.7.3-27"
7171
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@
6767
"scripts": {
6868
"test": "echo \"Error: no test specified\" && exit 1"
6969
},
70-
"version": "1.7.3-26"
70+
"version": "1.7.3-27"
7171
}

test/controllers/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ function viewViews() {
515515
assert.ok(output.contains('HELPER:1-<count>1</count><next>0</next>'), name + 'inline helper + foreach 1');
516516
assert.ok(output.contains('HELPER:2-<count>2</count><next>1</next>'), name + 'inline helper + foreach 2');
517517
assert.ok(output.contains('<section>SECTION</section>'), name + 'section');
518-
518+
assert.ok(output.contains('COMPILE_TANGULARCOMPILED'), name + 'onCompileView with name');
519+
assert.ok(output.contains('COMPILE_WITHOUTCOMPILED'), name + 'onCompileView without name');
519520
assert.ok(output.contains('<div>4</div><div>4</div><div>FOREACH</div>'), name + 'foreach');
520521
assert.ok(output.contains('<div>3</div><div>3</div><div></div><div>C:10</div><div>C:11</div><div>C:12</div>'), name + 'foreach - nested');
521522
assert.ok(output.contains('<INLINE>5</INLINE>'), name + 'Inline assign value');

0 commit comments

Comments
 (0)