Skip to content

Commit b73630d

Browse files
committed
Merge pull request Urigo#1355 from kamilkisiela/templates-settings
feat(templates): optional error and warning of missing template
2 parents 695c096 + 5657db4 commit b73630d

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

packages/angular-templates/templates-handler.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,36 @@ angular.module('angular-templates', []).config([
1414
function ($provide) {
1515
var templatesFileExtension = ['html', 'tpl', 'tmpl', 'template', 'view'];
1616

17-
$provide.decorator('$templateCache', ['$delegate', function($delegate) {
18-
var originalGet = $delegate.get;
17+
$provide.decorator('$templateCache', ['$delegate', '$angularTemplatesSettings',
18+
function($delegate, $angularTemplatesSettings) {
19+
var originalGet = $delegate.get;
1920

20-
$delegate.get = function(templatePath) {
21-
var originalResult = originalGet(templatePath);
21+
$delegate.get = function(templatePath) {
22+
var originalResult = originalGet(templatePath);
2223

23-
if (angular.isUndefined(originalResult)) {
24-
var fileExtension = ((templatePath.split('.') || []).pop() || '').toLowerCase();
24+
if (angular.isUndefined(originalResult)) {
25+
var fileExtension = ((templatePath.split('.') || []).pop() || '').toLowerCase();
2526

26-
if (templatesFileExtension.indexOf(fileExtension) > -1) {
27-
throw new Error('[angular-meteor][err][404] ' + templatePath + ' - HTML template does not exists!');
27+
if (templatesFileExtension.indexOf(fileExtension) > -1) {
28+
function getMsg(type) {
29+
return '[angular-meteor][err][404] ' + templatePath + ' - HTML template does not exists! You can disable this ' + type + ' by following this guide http://www.angular-meteor.com/api/1.3.11/templates';
30+
}
31+
32+
if ($angularTemplatesSettings.error === true) {
33+
throw new Error(getMsg('error'));
34+
} else if ($angularTemplatesSettings.warning === true) {
35+
console.warn(getMsg('warning'));
36+
}
37+
}
2838
}
29-
}
3039

31-
return originalResult;
32-
};
40+
return originalResult;
41+
};
3342

34-
return $delegate;
43+
return $delegate;
3544
}]);
3645
}
37-
]);
46+
]).constant('$angularTemplatesSettings', {
47+
error: true,
48+
warning: true
49+
});;

0 commit comments

Comments
 (0)