Skip to content

Commit

Permalink
Moved the generated files into dest\tmp folder to make it easier to c…
Browse files Browse the repository at this point in the history
…lean the project.
  • Loading branch information
petebacondarwin committed Sep 18, 2012
1 parent 0c8fb0a commit a6d26a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
node_modules
dist
*.tpl.html.js
src/modules/templates.js
dist
19 changes: 11 additions & 8 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function (grunt) {
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
},
src: {
js: ['src/**/*.js'],
js: ['src/**/*.js', 'dist/tmp/**/*.js'],
html: ['src/index.html'],
tpl: ['src/**/*.tpl.html'],
less: ['src/modules/*/less/*.less'] // recess:build doesn't accept ** in its file patterns
Expand All @@ -27,7 +27,8 @@ module.exports = function (grunt) {
},
html2js: {
src: ['<config:src.tpl>'],
base: 'src/modules'
base: 'src/modules',
dest: 'dist/tmp'
},
concat:{
dist:{
Expand Down Expand Up @@ -141,7 +142,7 @@ module.exports = function (grunt) {

// HTML-2-JS Templates
var path = require('path');
var TPL = 'angular.module("<%= file %>", []).run(["$templateCache", function($templateCache) {\n $templateCache.put("<%= file %>",\n "<%= content %>");\n}]);\n';
var TPL = 'angular.module("<%= id %>", []).run(["$templateCache", function($templateCache) {\n $templateCache.put("<%= id %>",\n "<%= content %>");\n}]);\n';
var templateModule = "angular.module('templates', [<%= templates %>]);";
var escapeContent = function(content) {
return content.replace(/"/g, '\\"').replace(/\r?\n/g, '" +\n "');
Expand All @@ -154,18 +155,20 @@ module.exports = function (grunt) {
};

grunt.registerTask('html2js', 'Generate js version of html template.', function() {
this.requiresConfig('html2js.src');
var files = grunt.file.expandFiles(grunt.config.process('html2js.src'));
var base = grunt.config.process('html2js.base') || '.';
var dest = grunt.config.process('html2js.dest') || '.';
var templates = [];
files.forEach(function(file) {
var name = normalizePath(path.relative(base, file));
templates.push("'" + name + "'");
grunt.file.write(file + '.js', grunt.template.process(TPL, {
file: name,
var id = normalizePath(path.relative(base, file));
templates.push("'" + id + "'");
grunt.file.write(path.resolve(dest, id + '.js'), grunt.template.process(TPL, {
id: id,
content: escapeContent(grunt.file.read(file))
}));
});
grunt.file.write(path.join(base,'templates.js'), grunt.template.process(templateModule, {
grunt.file.write(path.resolve(dest,'templates.js'), grunt.template.process(templateModule, {
templates: templates.join(', ')
}));
});
Expand Down
3 changes: 2 additions & 1 deletion test/config/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ files = [
'test/lib/angular/angular-mocks.js',
'src/lib/**/*.js',
'src/**/*.js',
'test/**/unit/**/*Spec.js'
'test/**/unit/**/*Spec.js',
'dist/tmp/**/*.js'
];

// list of files to exclude
Expand Down

0 comments on commit a6d26a1

Please sign in to comment.