1 | /**
|
2 | * Copyright 2014 Skytap Inc.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | **/
|
16 |
|
17 | var fs = require('fs'),
|
18 | Promise = require('bluebird'),
|
19 | Filesystem = require('./filesystem'),
|
20 | Logger = require('./logger');
|
21 |
|
22 | /**
|
23 | * Module to load and register template mixins.
|
24 | **/
|
25 | var Template = {
|
26 |
|
27 | mixins : {},
|
28 |
|
29 | //////////////////////////////////////////////////////////////////////////
|
30 | // Public methods ///////////////////////////////////////////////////////
|
31 | ////////////////////////////////////////////////////////////////////////
|
32 |
|
33 | /**
|
34 | * Template.getMixins() -> Object
|
35 | **/
|
36 | getMixins : function() {
|
37 | return this.mixins;
|
38 | },
|
39 |
|
40 | /**
|
41 | * Template.loadMixins(path) -> Object
|
42 | * - path (String): Path to the template mixins
|
43 | **/
|
44 | loadMixins : function (path) {
|
45 | var self = this,
|
46 | start = Date.now();
|
47 |
|
48 | if (!fs.existsSync(path)) {
|
49 | return Promise.resolve();
|
50 | }
|
51 |
|
52 | return Filesystem.requireFilesInDirectory(path)
|
53 | .then(function(mixins) {
|
54 | self.mixins = mixins;
|
55 | Logger.profile('Load template mixins', start);
|
56 | });
|
57 | }
|
58 | };
|
59 |
|
60 | module.exports = Template; |
\ | No newline at end of file |