Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
refactor(templates): allow templates to be overriden in the config phase
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lewis committed Dec 31, 2015
1 parent 8fc02fe commit ac2723f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
44 changes: 30 additions & 14 deletions src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,40 @@ function requireAll(r) {
r.keys().forEach(r);
}

module.exports = angular
.module('mwl.calendar', [])
.run(function($templateCache, calendarConfig) {
var templates = {};

if (EXCLUDE_TEMPLATES === false) {

if (EXCLUDE_TEMPLATES === false) {
var templatesContext = require.context('./templates', false, /\.html/);

var templatesContext = require.context('./templates', false, /\.html/);
templatesContext.keys().forEach(function(templateName) {
var templateNameWithoutPrefix = templateName.replace('./', '');
var cacheTemplateName = 'mwl/' + templateNameWithoutPrefix;
var configTemplateName = templateNameWithoutPrefix.replace('.html', '');
templates[configTemplateName] = {
cacheTemplateName: cacheTemplateName,
template: templatesContext(templateName)
};
});

templatesContext.keys().forEach(function(templateName) {
var templateNameWithoutPrefix = templateName.replace('./', '');
var cacheTemplateName = 'mwl/' + templateNameWithoutPrefix;
if (!$templateCache.get(cacheTemplateName)) {
$templateCache.put(cacheTemplateName, templatesContext(templateName));
calendarConfig.templates[templateNameWithoutPrefix.replace('.html', '')] = cacheTemplateName;
}
});
}

}
module.exports = angular
.module('mwl.calendar', [])
.config(function(calendarConfig) {
angular.forEach(templates, function(template, templateName) {
if (!calendarConfig.templates[templateName]) {
calendarConfig.templates[templateName] = template.cacheTemplateName;
}
});
})
.run(function($templateCache) {

angular.forEach(templates, function(template) {
if (!$templateCache.get(template.cacheTemplateName)) {
$templateCache.put(template.cacheTemplateName, template.template);
}
});

}).name;

Expand Down
2 changes: 1 addition & 1 deletion src/services/calendarConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var angular = require('angular');

angular
.module('mwl.calendar')
.value('calendarConfig', {
.constant('calendarConfig', {
allDateFormats: {
angular: {
date: {
Expand Down

0 comments on commit ac2723f

Please sign in to comment.