@dazejs/framework
Version:
Daze.js - A powerful web framework for Node.js
56 lines • 1.74 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.View = void 0;
const path_1 = __importDefault(require("path"));
const container_1 = require("../container");
const FINAL_VARS = Symbol('View#finalVars');
class View {
constructor(template = '', vars = {}) {
this.app = container_1.Container.get('app');
this.vars = {};
this.template = '';
this.template = template;
this.vars = vars;
}
[FINAL_VARS](vars = {}) {
return Object.assign({}, this.vars, vars);
}
assign(name, value) {
if (name && typeof name === 'object') {
this.vars = Object.assign(this.vars, name);
}
else if (typeof name === 'string') {
this.vars[name] = value;
}
return this;
}
render(template = '', vars = {}) {
let newTemplate = template;
let newVars = vars;
if (newTemplate && typeof newTemplate === 'object') {
newVars = newTemplate;
newTemplate = '';
}
if (newTemplate)
this.template = newTemplate;
if (newVars)
this.vars = this[FINAL_VARS](newVars);
return this;
}
getTemplate() {
const config = this.app.get('config');
const ext = config.get('app.viewExtension', 'html');
if (path_1.default.extname(this.template) === '') {
return `${this.template}.${ext}`;
}
return this.template;
}
getVars() {
return this.vars;
}
}
exports.View = View;
//# sourceMappingURL=index.js.map