Skip to content

Commit 7a79cb6

Browse files
committed
fixed: HTML compressor
1 parent 8c3f873 commit 7a79cb6

9 files changed

Lines changed: 59 additions & 26 deletions

File tree

index.js

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

190190
this.id = null;
191191
this.version = 1810;
192-
this.version_header = '1.8.1-12';
192+
this.version_header = '1.8.1-13';
193193

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

internal.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var NUMBER = 'number';
2020
var REG_1 = /[\n\r\t]+/g;
2121
var REG_2 = /\s{2,}/g;
2222
var REG_3 = /\/{1,}/g;
23-
var REG_4 = /\n\s{2,}/g;
23+
var REG_4 = /\n\s{2,}./g;
2424
var REG_5 = />\n\s{1,}</g;
2525

2626
var HTTPVERBS = { 'GET': true, 'POST': true, 'OPTIONS': true, 'PUT': true, 'DELETE': true, 'PATCH': true, 'upload': true, 'HEAD': true, 'TRACE': true, 'PROPFIND': true };
@@ -1659,16 +1659,23 @@ function view_parse(content, minify) {
16591659
var compressed = '';
16601660

16611661
function escaper(value) {
1662+
1663+
var is = value.match(/[^\>]\n\s{1,}$/);
16621664
value = compressHTML(value, minify);
1663-
if (value === '' || value === ' ')
1665+
1666+
if (value === '')
16641667
return '$EMPTY';
16651668

16661669
if (value[0] === ' ' && value[1] === '<')
16671670
value = value.substring(1);
16681671

1672+
if (is)
1673+
value += ' ';
1674+
16691675
// if (value.match(/\n|\t|\r|\'|\\/) !== null)
16701676
if (value.match(/\n|\r|\'|\\/) !== null)
16711677
return DELIMITER_UNESCAPE + escape(value) + DELIMITER_UNESCAPE_END;
1678+
16721679
return DELIMITER + value + DELIMITER;
16731680
}
16741681

@@ -2375,7 +2382,12 @@ function compressHTML(html, minify) {
23752382
// html = html.replace(/>\n\s+/g, '>').replace(/\w\n\s+</g, function(text) {
23762383
html = html.replace(/>\n\s+/g, '>').replace(/(\w|\W)\n\s+</g, function(text) {
23772384
return text.trim().replace(/\s/g, '');
2378-
}).replace(REG_5, '><').replace(REG_4, ' ').replace(REG_1, '').replace(REG_2, '');
2385+
}).replace(REG_5, '><').replace(REG_4, function(text) {
2386+
var c = text[text.length - 1];
2387+
if (c === '<')
2388+
return c;
2389+
return ' ' + c;
2390+
}).replace(REG_1, '').replace(REG_2, '');
23792391

23802392
// html = html.replace(REG_1, '').replace(REG_2, '');
23812393

minify/merged/total.js

Lines changed: 11 additions & 8 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: 1 addition & 1 deletion
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
@@ -65,5 +65,5 @@
6565
"scripts": {
6666
"test": "echo \"Error: no test specified\" && exit 1"
6767
},
68-
"version": "1.8.1-12"
68+
"version": "1.8.1-13"
6969
}

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-12"
68+
"version": "1.8.1-13"
6969
}

test/test-framework-debug.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ function test_routing(next) {
8989

9090
var async = new utils.Async();
9191

92+
async.await('html compressor', function(complete) {
93+
utils.request(url + 'html-compressor/', ['get'], null, function(error, data, code, headers) {
94+
if (error)
95+
throw error;
96+
assert(data === '<div><p>a b c d</p><div>Price 30 &euro;</div></div><div>Name: Peter</div><div>Name: Peter</div><div>Price: 1000 1 000.00</div><div>13</div><div>Name: Peter</div>', 'HTML compressor');
97+
complete();
98+
});
99+
});
100+
92101
async.await('0', function(complete) {
93102
utils.request(url + 'share/', 'GET', null, function(error, data, code, headers) {
94103
if (error)
@@ -140,15 +149,6 @@ function test_routing(next) {
140149
});
141150
});
142151

143-
async.await('html compressor', function(complete) {
144-
utils.request(url + 'html-compressor/', ['get'], null, function(error, data, code, headers) {
145-
if (error)
146-
throw error;
147-
assert(data === '<div><p>a b c d</p><div>Price 30 &euro;</div></div><div>Name: Peter</div><div>Name: Peter</div>', 'HTML compressor');
148-
complete();
149-
});
150-
});
151-
152152
async.await('rest GET', function(complete) {
153153
utils.request(url + 'rest/', ['get'], null, function(error, data, code, headers) {
154154
if (error)

test/views/compress.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
@{layout('')}
2+
@{repository.price = 1000}
3+
@{repository.c='3'}
4+
@{repository.a='1'}
25

36
<div>
47
<p>
@@ -21,3 +24,18 @@
2124
Name:
2225
@{model.name}
2326
</div>
27+
28+
<div>
29+
Price:
30+
@{repository.price} @{repository.price.format(2)}
31+
</div>
32+
33+
<div>
34+
@{repository.a}
35+
@{repository.b}
36+
@{repository.c}
37+
</div>
38+
39+
<div>
40+
Name: @{model.name}
41+
</div>

0 commit comments

Comments
 (0)