Skip to content

Commit 05d6164

Browse files
committed
Extend view engine.
1 parent d1a650d commit 05d6164

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

changes.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
- added: NoSQL backuping documents while they are updating/removing in `DatabaseBuilder.backup([user])`
3131
- added: `CLONE(obj)` alias for `U.clone()`
3232
- added: `GROUP(flags, fn)` alias for `F.group()`
33-
- addeD: `F.cache.set2()` it creates a persistent cache (persistent items are stored in a file)
33+
- added: `F.cache.set2()` it creates a persistent cache (persistent items are stored in a file)
34+
- added: new View Engine command `@{'%config'}` which reads a value from config directly
3435

3536
- updated: (IMPORTANT) packages compress/decompress function supports streaming data
3637
- updated: (IMPORTANT) `NOSQL().backup()` !!! was changed !!!!

internal.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,12 @@ function view_parse(content, minify, filename, controller) {
17981798
});
17991799

18001800
if (cmd[0] === '\'' || cmd[0] === '"') {
1801-
builder += '+' + DELIMITER + (new Function('self', 'return self.$import(' + cmd[0] + '!' + cmd.substring(1) + ')'))(controller) + DELIMITER;
1801+
if (cmd[1] === '%') {
1802+
var t = F.config[cmd.substring(2, cmd.length - 1)];
1803+
if (t != null)
1804+
builder += '+' + DELIMITER + t + DELIMITER;
1805+
} else
1806+
builder += '+' + DELIMITER + (new Function('self', 'return self.$import(' + cmd[0] + '!' + cmd.substring(1) + ')'))(controller) + DELIMITER;
18021807
} else if (cmd7 === 'compile' && cmd.lastIndexOf(')') === -1) {
18031808

18041809
builderTMP = builder + '+(F.onCompileView.call(self,\'' + (cmd8[7] === ' ' ? cmd.substring(8) : '') + '\',';

test/controllers/default.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ function viewViews() {
574574
assert.ok(output.contains('#absolute1=<script src="http://127.0.0.1:8001/js/filename.js"></script>#'), name + 'absolute problem without hostname');
575575
assert.ok(output.contains('#absolute2=<script src="https://www.google.sk/js/filename.js"></script>#'), name + 'aboslute problem with hostname');
576576
assert.ok(output.contains('#absolute3=<script src="http://localhost:8000/js/default.js"></script><script src="http://localhost:8000/js/home.js"></script>#'), name + 'aboslute problem array + with hostname');
577+
assert.ok(output.contains('#CONFIGNAME1=Total.js#'), name + 'inline config value with value');
578+
assert.ok(output.contains('#CONFIGNAME2=#'), name + 'inline config value without value');
577579

578580
assert.ok(output.contains('#d429c9c776604a9e15d04d9bd90dba27e0155965=a+b+c#'), name + 'https://github.com/totaljs/framework/commit/d429c9c776604a9e15d04d9bd90dba27e0155965');
579581

test/views/a.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@
8686
#absolute2=@{absolute('filename.js', 'https://www.google.sk')}#
8787
#absolute3=@{absolute(['default.js', 'home.js'], 'http://localhost:8000')}#
8888
#d429c9c776604a9e15d04d9bd90dba27e0155965=@{repository.a}+@{repository.b}+@{repository.c}#
89+
#CONFIGNAME1=@{'%name'}#
90+
#CONFIGNAME2=@{'%fet'}#

0 commit comments

Comments
 (0)