Skip to content

Commit 6135806

Browse files
committed
added: framework.view(), framework.mail()
1 parent a05a6b2 commit 6135806

6 files changed

Lines changed: 95 additions & 20 deletions

File tree

index.js

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,6 +4108,63 @@ Framework.prototype._log = function(a, b, c, d) {
41084108
}, 1000);
41094109
};
41104110

4111+
/**
4112+
* Send e-mail
4113+
* @param {String or Array} address E-mail address.
4114+
* @param {String} subject E-mail subject.
4115+
* @param {String} view View name.
4116+
* @param {Object} model Optional.
4117+
* @param {Function(err)} callback Optional.
4118+
* @return {Framework}
4119+
*/
4120+
Framework.prototype.mail = function(address, subject, view, model, callback) {
4121+
4122+
var controller = new Controller('', null, null, null);
4123+
4124+
if (typeof(layout) === OBJECT) {
4125+
var tmp = repository;
4126+
repository = layout;
4127+
layout = tmp;
4128+
}
4129+
4130+
controller.layoutName = layout || '';
4131+
4132+
if (typeof(repository) === OBJECT && repository !== null)
4133+
controller.repository = repository;
4134+
4135+
controller.mail.apply(controller, arguments);
4136+
return self;
4137+
};
4138+
4139+
4140+
/**
4141+
* Render view
4142+
* @param {String} name View name.
4143+
* @param {Object} model Model.
4144+
* @param {String} layout Layout for the view, optional. Default without layout.
4145+
* @param {Object} repository A repository object, optional. Default empty.
4146+
* @return {String}
4147+
*/
4148+
Framework.prototype.view = function(name, model, layout, repository) {
4149+
4150+
var controller = new Controller('', null, null, null);
4151+
4152+
if (typeof(layout) === OBJECT) {
4153+
var tmp = repository;
4154+
repository = layout;
4155+
layout = tmp;
4156+
}
4157+
4158+
controller.layoutName = layout || '';
4159+
4160+
if (typeof(repository) === OBJECT && repository !== null)
4161+
controller.repository = repository;
4162+
4163+
var output = controller.view(name, model, true);
4164+
controller = null;
4165+
return output;
4166+
};
4167+
41114168
/**
41124169
* Add a test function or test request
41134170
* @param {String} name Test name.
@@ -6666,10 +6723,19 @@ function Controller(name, req, res, subscribe) {
66666723
this._currentVideo = '';
66676724
this._currentJS = '';
66686725
this._currentCSS = '';
6669-
this._currentView = name[0] !== '#' && name !== 'default' ? '/' + name + '/' : '';
6726+
this._currentView = name[0] !== '#' && name !== 'default' && name !== '' ? '/' + name + '/' : '';
6727+
6728+
if (!this.req) {
6729+
var empty = {};
6730+
this.req = { uri: empty };
6731+
}
6732+
6733+
if (!this.res)
6734+
this.res = {};
66706735

66716736
// Assign controller to Response
6672-
this.res.controller = this;
6737+
if (this.res)
6738+
this.res.controller = this;
66736739
}
66746740

66756741
Controller.prototype = {
@@ -9922,7 +9988,7 @@ Controller.prototype.view = function(name, model, headers, isPartial) {
99229988
headers = null;
99239989
}
99249990

9925-
if (self.res.success && !isPartial)
9991+
if (!isPartial && self.res && self.res.success)
99269992
return self;
99279993

99289994
var skip = name[0] === '~';
@@ -9972,9 +10038,10 @@ Controller.prototype.view = function(name, model, headers, isPartial) {
997210038
}
997310039

997410040
var helpers = framework.helpers;
9975-
9976-
try {
10041+
/*
10042+
try {*/
997710043
value = generator.call(self, self, self.repository, model, self.session, self.get, self.post, self.url, framework.global, helpers, self.user, self.config, framework.functions, 0, sitemap, isPartial ? self.outputPartial : self.output, self.date);
10044+
/*
997810045
} catch (ex) {
997910046
998010047
var err = new Error('View: ' + name + ' - ' + ex.toString());
@@ -9996,7 +10063,7 @@ Controller.prototype.view = function(name, model, headers, isPartial) {
999610063
999710064
isLayout = false;
999810065
return value;
9999-
}
10066+
}*/
1000010067

1000110068
if (!isLayout && self.precache && self.status === 200)
1000210069
self.precache(value, CONTENTTYPE_TEXTHTML, headers, true);

internal.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,6 @@ MultipartParser.prototype.explain = function() {
17041704
function View(controller) {
17051705
this.controller = controller;
17061706
this.cache = controller.cache;
1707-
this.prefix = controller.prefix;
17081707
}
17091708

17101709
/**
@@ -1948,7 +1947,6 @@ function view_prepare(command, dynamicCommand, functions) {
19481947
case '!FUNCTION':
19491948
return '(' + command.substring(1) + ')';
19501949

1951-
19521950
case 'resource':
19531951
case 'RESOURCE':
19541952
return '(self.' + command + ').toString().encode()';
@@ -2060,7 +2058,6 @@ function view_prepare(command, dynamicCommand, functions) {
20602058
case 'viewToggle':
20612059
return 'self.$' + command;
20622060

2063-
20642061
case 'radio':
20652062
case 'text':
20662063
case 'checkbox':
@@ -2431,7 +2428,7 @@ View.prototype.load = function(name, filename) {
24312428

24322429
generator = self.read(filename);
24332430

2434-
if (!self.controller.isDebug)
2431+
if (!framework.isDebug)
24352432
framework.temporary.views[key] = generator;
24362433

24372434
return generator;
@@ -2451,9 +2448,9 @@ View.prototype.dynamic = function(content) {
24512448
if (generator !== null)
24522449
return generator;
24532450

2454-
generator = view_parse(content, self.controller, framework.config['allow-compress-html']);
2451+
generator = view_parse(content, framework.config['allow-compress-html']);
24552452

2456-
if (!self.controller.isDebug)
2453+
if (!framework.isDebug)
24572454
framework.temporary.views[key] = generator;
24582455

24592456
return generator;

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.

test/modules/inline-view.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var assert = require('assert');
2+
3+
exports.install = function(framework) {
4+
setTimeout(function() {
5+
assert.ok(framework.view('view') === '<div>total.js</div><script>var a=1+1;</script>', 'framework.view()');
6+
}, 100);
7+
};

test/views/view.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>@{config['name']}</div>
2+
<script>
3+
var a = 1 + 1;
4+
</script>

0 commit comments

Comments
 (0)