8000 Delint twig.exports.js · twigjs/twig.js@ce66373 · GitHub
[go: up one dir, main page]

Skip to content

Commit ce66373

Browse files
committed
Delint twig.exports.js
1 parent b1e08d8 commit ce66373

File tree

1 file changed

+64
-60
lines changed

1 file changed

+64
-60
lines changed

src/twig.exports.js

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This file provides extension points and other hooks into the twig functionality.
44

55
module.exports = function (Twig) {
6-
"use strict";
6+
'use strict';
77
Twig.exports = {
88
VERSION: Twig.VERSION
99
};
@@ -15,17 +15,17 @@ module.exports = function (Twig) {
1515
*
1616
* @return {Twig.Template} A Twig template ready for rendering.
1717
*/
18-
Twig.exports.twig = function twig(params) {
18+
Twig.exports.twig = function (params) {
1919
'use strict';
20-
var id = params.id,
21-
options = {
22-
strict_variables: params.strict_variables || false,
23-
// TODO: turn autoscape on in the next major version
24-
autoescape: params.autoescape != null && params.autoescape || false,
25-
allowInlineIncludes: params.allowInlineIncludes || false,
26-
rethrow: params.rethrow || false,
27-
namespaces: params.namespaces
28-
};
20+
const {id} = params;
21+
const options = {
22+
strictVariables: params.strictVariables || false,
23+
// TODO: turn autoscape on in the next major version
24+
autoescape: (params.autoescape !== null && params.autoescape) || false,
25+
allowInlineIncludes: params.allowInlineIncludes || false,
26+
rethrow: params.rethrow || false,
27+
namespaces: params.namespaces
28+
};
2929

3030
if (Twig.cache && id) {
3131
Twig.validateId(id);
@@ -34,96 +34,101 @@ module.exports = function (Twig) {
3434
if (params.debug !== undefined) {
3535
Twig.debug = params.debug;
3636
}
37+
3738
if (params.trace !== undefined) {
3839
Twig.trace = params.trace;
3940
}
4041

4142
if (params.data !== undefined) {
4243
return Twig.Templates.parsers.twig({
4344
data: params.data,
44-
path: params.hasOwnProperty('path') ? params.path : undefined,
45+
path: Object.hasOwnProperty.call(params, 'path') ? params.path : undefined,
4546
module: params.module,
46-
id: id,
47-
options: options
47+
id,
48+
options
4849
});
50+
}
4951

50-
} else if (params.ref !== undefined) {
52+
if (params.ref !== undefined) {
5153
if (params.id !== undefined) {
52-
throw new Twig.Error("Both ref and id cannot be set on a twig.js template.");
54+
throw new Twig.Error('Both ref and id cannot be set on a twig.js template.');
5355
}
56+
5457
return Twig.Templates.load(params.ref);
58+
}
5559

56-
} else if (params.method !== undefined) {
60+
if (params.method !== undefined) {
5761
if (!Twig.Templates.isRegisteredLoader(params.method)) {
5862
throw new Twig.Error('Loader for "' + params.method + '" is not defined.');
5963
}
64+
6065
return Twig.Templates.loadRemote 1E0A (params.name || params.href || params.path || id || undefined, {
61-
id: id,
66+
id,
6267
method: params.method,
6368
parser: params.parser || 'twig',
6469
base: params.base,
6570
module: params.module,
6671
precompiled: params.precompiled,
6772
async: params.async,
68-
options: options
73+
options
6974

7075
}, params.load, params.error);
76+
}
7177

72-
} else if (params.href !== undefined) {
78+
if (params.href !== undefined) {
7379
return Twig.Templates.loadRemote(params.href, {
74-
id: id,
80+
id,
7581
method: 'ajax',
7682
parser: params.parser || 'twig',
7783
base: params.base,
7884
module: params.module,
7985
precompiled: params.precompiled,
8086
async: params.async,
81-
options: options
87+
options
8288

8389
}, params.load, params.error);
90+
}
8491

85-
} else if (params.path !== undefined) {
92+
if (params.path !== undefined) {
8693
return Twig.Templates.loadRemote(params.path, {
87-
id: id,
94+
id,
8895
method: 'fs',
8996
parser: params.parser || 'twig',
9097
base: params.base,
9198
module: params.module,
9299
precompiled: params.precompiled,
93100
async: params.async,
94-
options: options
95-
101+
options
96102
}, params.load, params.error);
97103
}
98104
};
99105

100106
// Extend Twig with a new filter.
101-
Twig.exports.extendFilter = function(filter, definition) {
107+
Twig.exports.extendFilter = function (filter, definition) {
102108
Twig.filter.extend(filter, definition);
103109
};
104110

105111
// Extend Twig with a new function.
106-
Twig.exports.extendFunction = function(fn, definition) {
112+
Twig.exports.extendFunction = function (fn, definition) {
107113
Twig._function.extend(fn, definition);
108114
};
109115

110116
// Extend Twig with a new test.
111-
Twig.exports.extendTest = function(test, definition) {
117+
Twig.exports.extendTest = function (test, definition) {
112118
Twig.test.extend(test, definition);
113119
};
114120

115121
// Extend Twig with a new definition.
116-
Twig.exports.extendTag = function(definition) {
122+
Twig.exports.extendTag = function (definition) {
117123
Twig.logic.extend(definition);
118124
};
119125

120126
// Provide an environment for extending Twig core.
121127
// Calls fn with the internal Twig object.
122-
Twig.exports.extend = function(fn) {
128+
Twig.exports.extend = function (fn) {
123129
fn(Twig);
124130
};
125131

126-
127132
/**
128133
* Provide an extension for use with express 2.
129134
*
@@ -132,20 +137,19 @@ module.exports = function (Twig) {
132137
*
133138
* @return {string} The rendered template.
134139
*/
135-
Twig.exports.compile = function(markup, options) {
136-
var id = options.filename,
137-
path = options.filename,
138-
template;
140+
Twig.exports.compile = function (markup, options) {
141+
const id = options.filename;
142+
const path = options.filename;
139143

140144
// Try to load the template from the cache
141-
template = new Twig.Template({
145+
const template = new Twig.Template({
142146
data: markup,
143-
path: path,
144-
id: id,
147+
path,
148+
id,
145149
options: options.settings['twig options']
146150
}); // Twig.Templates.load(id) ||
147151

148-
return function(context) {
152+
return function (context) {
149153
retur A851 n template.render(context);
150154
};
151155
};
@@ -159,39 +163,39 @@ module.exports = function (Twig) {
159163
*
160164
* @throws Twig.Error
161165
*/
162-
Twig.exports.renderFile = function(path, options, fn) {
163-
// handle callback in options
166+
Twig.exports.renderFile = function (path, options, fn) {
167+
// Handle callback in options
164168
if (typeof options === 'function') {
165169
fn = options;
166170
options = {};
167171
}
168172

169173
options = options || {};
170174

171-
var settings = options.settings || {};
175+
const settings = options.settings || {};
172176

173-
// mixin any options provided to the express app.
174-
var view_options = settings['twig options'];
177+
// Mixin any options provided to the express app.
178+
const viewOptions = settings['twig options'];
175179

176-
var params = {
177-
path: path,
180+
const params = {
181+
path,
178182
base: settings.views,
179-
load: function(template) {
180-
// render and return template as a simple string, see https://github.com/twigjs/twig.js/pull/348 for more information
181-
if (!view_options || !view_options.allow_async) {
182-
fn(null, '' + template.render(options));
183+
load(template) {
184+
// Render and return template as a simple string, see https://github.com/twigjs/twig.js/pull/348 for more information
185+
if (!viewOptions || !viewOptions.allow_async) {
186+
fn(null, String(template.render(options)));
183187
return;
184188
}
185189

186190
template.renderAsync(options)
187-
.then(function(out) { fn(null, out); }, fn);
191+
.then(out => fn(null, out), fn);
188192
}
189193
};
190194

191-
if (view_options) {
192-
for (var option in view_options) {
193-
if (view_options.hasOwnProperty(option)) {
194-
params[option] = view_options[option];
195+
if (viewOptions) {
196+
for (const option in viewOptions) {
197+
if (Object.hasOwnProperty.call(viewOptions, option)) {
198+
params[option] = viewOptions[option];
195199
}
196200
}
197201
}
@@ -209,15 +213,15 @@ module.exports = function (Twig) {
209213
*
210214
* @param {boolean} cache
211215
*/
212-
Twig.exports.cache = function(cache) {
216+
Twig.exports.cache = function (cache) {
213217
Twig.cache = cache;
214218
};
215219

216-
//We need to export the path module so we can effectively test it
220+
// We need to export the path module so we can effectively test it
217221
Twig.exports.path = Twig.path;
218222

219-
//Export our filters.
220-
//Resolves #307
223+
// Export our filters.
224+
// Resolves #307
221225
Twig.exports.filters = Twig.filters;
222226

223227
Twig.exports.Promise = Twig.Promise;

0 commit comments

Comments
 (0)
0