Skip to content

Commit 7fa22f2

Browse files
committed
added: new view tags (nocompress)
1 parent e1c448d commit 7fa22f2

9 files changed

Lines changed: 94 additions & 11 deletions

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ BETA ======= 1.8.1
4343
- added: versions supports auto-mapping
4444
- added: sync2(), e.g. sync2(fn), diff with v1: sync(fn)() and v2: sync2(fn)
4545
- added: "dependencies" file for installing dependencies (modules, packages, etc.)
46+
- added: @{nocompress html}, @{nocompress js}, @{nocompress css}, @{nocompress all}
4647

4748
- updated: (IMPORTANT) routing: `json` flag is not required for receiving incomming data as JSON
4849
- updated: `F.mail(address, subject, view, [model], [callback], [language])` added language

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function Framework() {
198198

199199
this.id = null;
200200
this.version = 1810;
201-
this.version_header = '1.8.1-47';
201+
this.version_header = '1.8.1-48';
202202

203203
var version = process.version.toString().replace('v', '').replace(/\./g, '');
204204
if (version[1] === '0')

internal.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,44 @@ function view_parse(content, minify, filename) {
17121712
if (minify)
17131713
content = removeComments(content);
17141714

1715-
content = compressCSS(compressJS(content, 0, filename), 0, filename);
1715+
var nocompressHTML = false;
1716+
var nocompressJS = false;
1717+
var nocompressCSS = false;
1718+
1719+
content = content.replace(/@\{nocompress\s\w+}/gi, function(text) {
1720+
1721+
var index = text.lastIndexOf(' ');
1722+
if (index === -1)
1723+
return '';
1724+
1725+
switch (text.substring(index, text.length - 1).trim()) {
1726+
case 'all':
1727+
nocompressHTML = true;
1728+
nocompressJS = true;
1729+
nocompressCSS = true;
1730+
break;
1731+
case 'html':
1732+
nocompressHTML = true;
1733+
break;
1734+
case 'js':
1735+
case 'script':
1736+
case 'javascript':
1737+
nocompressJS = true;
1738+
break;
1739+
case 'css':
1740+
case 'style':
1741+
nocompressCSS = true;
1742+
break;
1743+
}
1744+
1745+
return '';
1746+
}).trim();
1747+
1748+
if (!nocompressJS)
1749+
content = compressJS(content, 0, filename);
1750+
if (!nocompressCSS)
1751+
content = compressCSS(content, 0, filename);
1752+
17161753
content = framework._version_prepare(content);
17171754

17181755
var DELIMITER = '\'';
@@ -1722,22 +1759,29 @@ function view_parse(content, minify, filename) {
17221759
var builder = 'var $EMPTY=\'\';var $length=0;var $source=null;var $tmp=index;var $output=$EMPTY';
17231760
var command = view_find_command(content, 0);
17241761
var compressed = '';
1762+
var nocompress = false;
1763+
var isFirst = false;
17251764

17261765
function escaper(value) {
17271766

17281767
var is = value.match(/[^\>]\n\s{1,}$/);
1729-
value = compressHTML(value, minify);
1768+
1769+
if (!nocompressHTML)
1770+
value = compressHTML(value, minify);
1771+
else if (!isFirst) {
1772+
isFirst = true;
1773+
value = value.replace(/^\s+/, '');
1774+
}
17301775

17311776
if (value === '')
17321777
return '$EMPTY';
17331778

1734-
if (value[0] === ' ' && value[1] === '<')
1779+
if (!nocompressHTML && value[0] === ' ' && value[1] === '<')
17351780
value = value.substring(1);
17361781

1737-
if (is)
1782+
if (!nocompressHTML && is)
17381783
value += ' ';
17391784

1740-
// if (value.match(/\n|\t|\r|\'|\\/) !== null)
17411785
if (value.match(/\n|\r|\'|\\/) !== null)
17421786
return DELIMITER_UNESCAPE + escape(value) + DELIMITER_UNESCAPE_END;
17431787

@@ -1858,7 +1902,11 @@ function view_parse(content, minify, filename) {
18581902
} else if (cmd === 'endif' || cmd === 'fi') {
18591903
builder += '}$output+=$EMPTY';
18601904
} else {
1861-
tmp = view_prepare(command.command, newCommand, functionsName);
1905+
1906+
tmp = view_prepare(command.command, newCommand, functionsName, function() {
1907+
nocompress = true;
1908+
});
1909+
18621910
if (tmp) {
18631911
if (view_parse_plus(builder))
18641912
builder += '+';
@@ -1921,6 +1969,7 @@ function view_prepare(command, dynamicCommand, functions) {
19211969
return '$STRING(' + command.substring(1) + ')';
19221970

19231971
switch (name) {
1972+
19241973
case 'foreach':
19251974
case 'end':
19261975
return '';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@
6565
"scripts": {
6666
"test": "echo \"Error: no test specified\" && exit 1"
6767
},
68-
"version": "1.8.1-47"
68+
"version": "1.8.1-48"
6969
}

test/controllers/default.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ exports.install = function() {
3131
});
3232

3333
framework.route('/html-compressor/', view_compressor);
34+
framework.route('/html-nocompress/', view_nocompress);
3435
framework.route('/sync/', synchronize);
3536
framework.route('/package/', '@testpackage/test');
3637
framework.route('/precompile/', view_precomile);
@@ -680,6 +681,11 @@ function view_compressor() {
680681
self.view('compress', { name: 'Peter' });
681682
}
682683

684+
function view_nocompress() {
685+
var self = this;
686+
self.view('nocompress');
687+
}
688+
683689
function regexp(number) {
684690
this.plain(number);
685691
}

test/test-framework-debug.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ function test_routing(next) {
110110
});
111111
});
112112

113+
async.await('html nocompress', function(complete) {
114+
utils.request(url + 'html-nocompress/', ['get'], null, function(error, data, code, headers) {
115+
if (error)
116+
throw error;
117+
assert(data.indexOf('<div>\nA\n</div>') !== -1, 'HTML nocompress');
118+
complete();
119+
});
120+
});
121+
113122
async.await('0', function(complete) {
114123
utils.request(url + 'share/', 'GET', null, function(error, data, code, headers) {
115124
if (error)

test/test-framework-release.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var url = 'http://127.0.0.1:8001/';
66
var errorStatus = 0;
77
var max = 100;
88

9-
//INSTALL('module', 'https://www.totaljs.com/framework/include.js', { test: true });
9+
// INSTALL('module', 'https://www.totaljs.com/framework/include.js', { test: true });
1010

1111
//framework.map('/minify/', '@testpackage', ['.html', 'js']);
1212
//framework.map('/minify/', 'models');
@@ -110,6 +110,15 @@ function test_routing(next) {
110110
});
111111
});
112112

113+
async.await('html nocompress', function(complete) {
114+
utils.request(url + 'html-nocompress/', ['get'], null, function(error, data, code, headers) {
115+
if (error)
116+
throw error;
117+
assert(data.indexOf('<div>\nA\n</div>') !== -1, 'HTML nocompress');
118+
complete();
119+
});
120+
});
121+
113122
async.await('0', function(complete) {
114123
utils.request(url + 'share/', 'GET', null, function(error, data, code, headers) {
115124
if (error)
@@ -648,4 +657,4 @@ framework.on('load', function() {
648657
}, 2000);
649658
});
650659

651-
framework.useConfig('my-config.txt').useConfig('/configs/my-config.config').http('false', { port: 8001 });
660+
framework.useConfig('my-config.txt').useConfig('/configs/my-config.config').http('release', { port: 8001 });

test/views/fromURL.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/views/nocompress.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@{nocompress all}
2+
@{layout('')}
3+
4+
<div>
5+
A
6+
</div>
7+
8+
<script>
9+
var a = 0;
10+
</script>

0 commit comments

Comments
 (0)