Skip to content
This repository was archived by the owner on Jan 15, 2022. It is now read-only.

Commit 1a48407

Browse files
committed
Initial commit
0 parents  commit 1a48407

File tree

17 files changed

+377
-0
lines changed

17 files changed

+377
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
npm-debug.log
3+
tmp

.jshintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"curly": true,
3+
"eqeqeq": true,
4+
"immed": true,
5+
"latedef": true,
6+
"newcap": true,
7+
"noarg": true,
8+
"sub": true,
9+
"undef": true,
10+
"boss": true,
11+
"eqnull": true,
12+
"node": true
13+
}

Gruntfile.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* grunt-angular-combine
3+
* https://github.com/astik/grunt-angular-combine
4+
*
5+
* Copyright (c) 2013 Romain Gonord
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function (grunt) {
12+
13+
// Project configuration.
14+
grunt.initConfig({
15+
jshint : {
16+
all : [ 'Gruntfile.js', 'tasks/*.js', '<%= nodeunit.tests %>', ],
17+
options : {
18+
jshintrc : '.jshintrc',
19+
},
20+
},
21+
22+
// Before generating any new files, remove any previously-created files.
23+
clean : {
24+
tests : [ 'tmp' ],
25+
},
26+
27+
// Configuration to be run (and then tested).
28+
angular_combine : {
29+
combine : {
30+
options : {
31+
appBaseDir : "test/fixtures",
32+
targetDir : "tmp/combined"
33+
},
34+
folders : [ 'test1', 'test2', 'test3' ]
35+
},
36+
},
37+
38+
// Unit tests.
39+
nodeunit : {
40+
tests : [ 'test/*_test.js' ],
41+
},
42+
43+
});
44+
45+
// Actually load this plugin's task(s).
46+
grunt.loadTasks('tasks');
47+
48+
// These plugins provide necessary tasks.
49+
grunt.loadNpmTasks('grunt-contrib-jshint');
50+
grunt.loadNpmTasks('grunt-contrib-clean');
51+
grunt.loadNpmTasks('grunt-contrib-nodeunit');
52+
53+
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
54+
// plugin's task(s), then test the result.
55+
grunt.registerTask('test', [ 'clean', 'angular_combine', 'nodeunit' ]);
56+
57+
// By default, lint and run all tests.
58+
grunt.registerTask('default', [ 'jshint', 'test' ]);
59+
60+
};

LICENSE-MIT

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2013 Romain Gonord
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# grunt-angular-combine
2+
3+
> Combine AngularJS partials into a single HTML file.
4+
5+
## Getting Started
6+
This plugin requires Grunt `~0.4.1`
7+
8+
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
9+
10+
```shell
11+
npm install grunt-angular-combine --save-dev
12+
```
13+
14+
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
15+
16+
```js
17+
grunt.loadNpmTasks('grunt-angular-combine');
18+
```
19+
20+
## The "angular_combine" task
21+
22+
### Overview
23+
In your project's Gruntfile, add a section named `angular_combine` to the data object passed into `grunt.initConfig()`.
24+
25+
```js
26+
grunt.initConfig({
27+
angular_combine: {
28+
combine: {
29+
options : {
30+
appBaseDir : "app",
31+
targetDir : "target"
32+
},
33+
folders : [ 'directives' ]
34+
},
35+
},
36+
})
37+
```
38+
39+
### Options
40+
41+
#### options.appBaseDir
42+
Type: `String`
43+
Default value: `''`
44+
45+
A string value that is used to define the app directory.
46+
47+
#### options.targetDir
48+
Type: `String`
49+
Default value: `''`
50+
51+
A string value that is used to define where combined files should be created.
52+
53+
### Usage Examples
54+
55+
#### Options
56+
In this example, all HTML files located into app/directives will be merged into a single file : target/directives.html.
57+
58+
```js
59+
grunt.initConfig({
60+
angular_combine: {
61+
combine: {
62+
options : {
63+
appBaseDir : "app",
64+
targetDir : "target"
65+
},
66+
folders : [ 'directives' ]
67+
},
68+
},
69+
})
70+
```
71+
72+
By defaults, it works in the current base directory.
73+
74+
## Contributing
75+
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
76+
77+
## Release History
78+
0.1.0 : initial version

package.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "grunt-angular-combine",
3+
"description": "Combine AngularJS partials into a single HTML file.",
4+
"version": "0.1.0",
5+
"homepage": "https://github.com/astik/grunt-angular-combine",
6+
"author": {
7+
"name": "Romain Gonord",
8+
"email": "romain.gonord.opensource@neteyes.org"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git://github.com/astik/grunt-angular-combine.git"
13+
},
14+
"bugs": {
15+
"url": "https://github.com/astik/grunt-angular-combine/issues"
16+
},
17+
"licenses": [
18+
{
19+
"type": "MIT",
20+
"url": "https://github.com/astik/grunt-angular-combine/blob/master/LICENSE-MIT"
21+
}
22+
],
23+
"main": "Gruntfile.js",
24+
"engines": {
25+
"node": ">= 0.8.0"
26+
},
27+
"scripts": {
28+
"test": "grunt test"
29+
},
30+
"devDependencies": {
31+
"grunt-contrib-jshint": "~0.6.0",
32+
"grunt-contrib-clean": "~0.4.0",
33+
"grunt-contrib-nodeunit": "~0.2.0",
34+
"grunt": "~0.4.1"
35+
},
36+
"peerDependencies": {
37+
"grunt": "~0.4.1"
38+
},
39+
"keywords": [
40+
"gruntplugin"
41+
]
42+
}

tasks/angular_combine.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* grunt-angular-combine
3+
* https://github.com/astik/grunt-angular-combine
4+
*
5+
* Copyright (c) 2013 Romain Gonord
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function (grunt) {
12+
grunt.registerMultiTask('angular_combine', 'Combine AngularJS partials into a single HTML file.', function () {
13+
var options = this.options({
14+
appBaseDir : '',
15+
targetDir : ''
16+
});
17+
18+
this.data.folders.forEach(function (folderRelativePath) {
19+
20+
var currentFolderPath = options.appBaseDir + "/" + folderRelativePath;
21+
grunt.log.writeln("currentFolderPath =", currentFolderPath);
22+
23+
var destFilePath = options.targetDir + "/" + folderRelativePath + ".html";
24+
grunt.log.writeln("destFilePath =", destFilePath);
25+
26+
var destFileContent = "";
27+
destFileContent += "<!-- Merge of " + currentFolderPath + " -->/\n";
28+
29+
grunt.file.recurse(currentFolderPath, function(abspath, rootdir, subdir, filename) {
30+
grunt.log.writeln("file =", filename);
31+
destFileContent += "<script type='text/ng-template' id='" + folderRelativePath + "/" + filename + "'>\n";
32+
destFileContent += grunt.file.read(currentFolderPath + "/" + filename);
33+
destFileContent += "</script>\n";
34+
});
35+
36+
grunt.file.write(destFilePath, destFileContent);
37+
});
38+
});
39+
40+
};

test/angular_combine_test.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict';
2+
3+
var grunt = require('grunt');
4+
5+
/*
6+
======== A Handy Little Nodeunit Reference ========
7+
https://github.com/caolan/nodeunit
8+
9+
Test methods:
10+
test.expect(numAssertions)
11+
test.done()
12+
Test assertions:
13+
test.ok(value, [message])
14+
test.equal(actual, expected, [message])
15+
test.notEqual(actual, expected, [message])
16+
test.deepEqual(actual, expected, [message])
17+
test.notDeepEqual(actual, expected, [message])
18+
test.strictEqual(actual, expected, [message])
19+
test.notStrictEqual(actual, expected, [message])
20+
test.throws(block, [error], [message])
21+
test.doesNotThrow(block, [error], [message])
22+
test.ifError(value)
23+
*/
24+
25+
exports.angular_combine = {
26+
setUp : function (done) {
27+
// setup here if necessary
28+
done();
29+
},
30+
test1 : function (test) {
31+
var actual = grunt.file.read('tmp/combined/test1.html');
32+
var expected = grunt.file.read('test/expected/test1.html');
33+
test.equal(actual, expected, 'test1 files should be equals.');
34+
test.done();
35+
},
36+
test2 : function (test) {
37+
var actual = grunt.file.read('tmp/combined/test2.html');
38+
var expected = grunt.file.read('test/expected/test2.html');
39+
test.equal(actual, expected, 'test2 files should be equals.');
40+
test.done();
41+
},
42+
test3 : function (test) {
43+
var actual = grunt.file.read('tmp/combined/test3.html');
44+
var expected = grunt.file.read('test/expected/test3.html');
45+
test.equal(actual, expected, 'test3 files should be equals.');
46+
test.done();
47+
}
48+
};
49+
//default_options: function(test) {
50+
//test.expect(1);
51+
//
52+
//var actual = grunt.file.read('tmp/default_options');
53+
//var expected = grunt.file.read('test/expected/default_options');
54+
//test.equal(actual, expected, 'should describe what the default behavior
55+
//is.');
56+
//
57+
//test.done();
58+
//},
59+
//custom_options: function(test) {
60+
//test.expect(1);
61+
//
62+
//var actual = grunt.file.read('tmp/custom_options');
63+
//var expected = grunt.file.read('test/expected/custom_options');
64+
//test.equal(actual, expected, 'should describe what the custom option(s)
65+
//behavior is.');
66+
//
67+
//test.done();
68+
//},

test/expected/test1.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Merge of test/fixtures/test1 -->/
2+
<script type='text/ng-template' id='test1/bar.html'>
3+
<div>
4+
Bar
5+
</div>
6+
</script>
7+
<script type='text/ng-template' id='test1/woot.html'>
8+
<div>
9+
Woot
10+
</div>
11+
</script>

test/expected/test2.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Merge of test/fixtures/test2 -->/
2+
<script type='text/ng-template' id='test2/bar.html'>
3+
<div>
4+
Bar
5+
</div>
6+
</script>
7+
<script type='text/ng-template' id='test2/foo.html'>
8+
<div>
9+
Foo
10+
</div>
11+
</script>

0 commit comments

Comments
 (0)