Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to pass a templatePath variable into ng-constants to a... #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,17 @@ module.exports = function(grunt) {
'constant2': undefined
}
}
]
],
template_options:{
dest:'tmp/template_options.js',
name:'templateOptionsModule',
options:{
templatePath:'test/custom.tpl.ejs'
},
constants: {
'constant1': 'value1'
}
}
},

// Unit tests.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ Optional

A boolean to toggle coffeescript output instead of javascript, using [`js2coffee`](https://github.com/rstacruz/js2coffee). Can also be assigned on a per-target basis.

#### options.templatePath
Type: `String`
Default value: `constant.tpl.ejs`
Optional

Location of a custom template file for creating the output configuration file. Defaults to the provided constants template file if none provided.

### Usage Examples

#### Default Options
Expand Down
7 changes: 4 additions & 3 deletions tasks/ngconstant.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ module.exports = function (grunt) {
deps: [],
wrap: false,
coffee: false,
constants: {}
constants: {},
templatePath:TEMPLATE_PATH
});
// Pick all option variables which are available per module
var defaultModuleOptions = _.pick(options, ['space', 'deps', 'wrap', 'coffee']);
var template = grunt.file.read(TEMPLATE_PATH);
var defaultModuleOptions = _.pick(options, ['space', 'deps', 'wrap', 'coffee', 'templatePath']);
var template = grunt.file.read(defaultModuleOptions.templatePath);
var compiler = _.template(template);
var modules = toArray(this.data);

Expand Down
10 changes: 10 additions & 0 deletions test/custom.tpl.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*jshint -W109*/
define(function (require) {
'use strict';

var angular = require('angular');

angular.module("<%- moduleName %>"<% if (deps) { %>, <%= JSON.stringify(deps) %><% } %>)
<% constants.forEach(function(constant) { %>.constant("<%- constant.name %>", <%= constant.value %>)<% }) %>;

})
10 changes: 10 additions & 0 deletions test/expected/template_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*jshint -W109*/
define(function (require) {
'use strict';

var angular = require('angular');

angular.module("templateOptionsModule", [])
.constant("constant1", "value1");

});
7 changes: 7 additions & 0 deletions test/ngconstant_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ exports.ng_constant = {
test.equal(actual, expected, 'should output module in coffeescript');

test.done();
},
template_options: function(test){
test.expect(1);
var actual = grunt.file.read('tmp/template_options.js');
var expected = grunt.file.read('test/expected/template_options.js');
test.equal(actual, expected, 'should output module with custom template');
test.done();
}


Expand Down