Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

feat(customTemplates): show a warning when a template doesnt exist in…

… the template cache

Closes #422
  • Loading branch information...
Matt Lewis
Matt Lewis committed Aug 10, 2016
1 parent c84e9ab commit a7eee2a8193df398390329244d474baa5ae253f0
@@ -4,18 +4,24 @@ var angular = require('angular');

angular
.module('mwl.calendar')
.controller('MwlDynamicDirectiveTemplateCtrl', function($compile, $scope, $attrs, $element, $templateCache, calendarConfig) {
.controller('MwlDynamicDirectiveTemplateCtrl', function($compile, $scope, $attrs, $element, $templateCache, $log, calendarConfig) {

$scope.$watch($attrs.overrides, function(overrides) {

var templateName = calendarConfig.templates[$attrs.name];
if (
overrides &&
angular.isObject(overrides) &&
overrides[$attrs.name] &&
$templateCache.get(overrides[$attrs.name])
overrides[$attrs.name]
) {
templateName = overrides[$attrs.name];
if ($templateCache.get(overrides[$attrs.name])) {
templateName = overrides[$attrs.name];
} else {
$log.warn('Bootstrap Calendar', 'The custom template for ' + overrides[$attrs.name] +
' was not found in the template cache. Please ensure it is pre-loaded via a script tag ' +
'<script type="text/ng-template" id="' + overrides[$attrs.name] + '">Custom template content</script> or ' +
'via a tool such as https://www.npmjs.com/package/gulp-angular-templatecache');
}
}
var template = $templateCache.get(templateName);
$element.html(template);
@@ -6,10 +6,11 @@ describe('dynamicDirectiveTemplate directive', function() {

beforeEach(angular.mock.module('mwl.calendar'));

var scope, elm, calendarConfig, $templateCache;
beforeEach(inject(function($rootScope, $compile, _$templateCache_, _calendarConfig_) {
var scope, elm, calendarConfig, $templateCache, $log;
beforeEach(inject(function($rootScope, $compile, _$templateCache_, _calendarConfig_, _$log_) {
$templateCache = _$templateCache_;
calendarConfig = _calendarConfig_;
$log = _$log_;
scope = $rootScope.$new();
calendarConfig.templates = {
foo: 'foo.html'
@@ -46,4 +47,13 @@ describe('dynamicDirectiveTemplate directive', function() {
expect(elm.text()).to.equal('bar baz');
});

it('should log a warning when the template is not in the cache', function() {
$log.warn = sinon.spy();
scope.overrides = {
foo: 'bam.html'
};
scope.$apply();
expect($log.warn).to.have.been.calledOnce;
});

});

0 comments on commit a7eee2a

Please sign in to comment.
You can’t perform that action at this time.