Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 905f94940c71b0ff368112e5dc710080a86bca8b @DamonOehlman committed Apr 13, 2012
Showing with 277 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 .npmignore
  3. +22 −0 LICENSE-MIT
  4. +28 −0 README.md
  5. +2 −0 bin/grunt-rigger
  6. +40 −0 grunt.js
  7. +42 −0 package.json
  8. +104 −0 tasks/rig.js
  9. +36 −0 test/rigger_test.js
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules
@@ -0,0 +1 @@
+/node_modules/
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Damon Oehlman <damon.oehlman@sidelab.com>
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
+# grunt-rigger
+
+Rigging tasks for elegant includes
+
+## Getting Started
+Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-rigger`
+
+Then add this line to your project's `grunt.js` gruntfile:
+
+```javascript
+grunt.loadNpmTasks('grunt-rigger');
+```
+
+[grunt]: https://github.com/cowboy/grunt
+[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
+
+## Documentation
+_(Coming soon)_
+
+## Contributing
+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][grunt].
+
+## Release History
+_(Nothing yet)_
+
+## License
+Copyright (c) 2012 Damon Oehlman <damon.oehlman@sidelab.com>
+Licensed under the MIT license.
@@ -0,0 +1,2 @@
+#!/usr/bin/env node
+require('grunt').npmTasks('grunt-rigger').cli();
@@ -0,0 +1,40 @@
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ test: {
+ files: ['test/**/*.js']
+ },
+ lint: {
+ files: ['grunt.js', 'tasks/**/*.js', 'test/**/*.js']
+ },
+ watch: {
+ files: '<config:lint.files>',
+ tasks: 'default'
+ },
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ node: true,
+ es5: true
+ },
+ globals: {}
+ }
+ });
+
+ // Load local tasks.
+ grunt.loadTasks('tasks');
+
+ // Default task.
+ grunt.registerTask('default', 'lint test');
+
+};
@@ -0,0 +1,42 @@
+{
+ "name": "grunt-rigger",
+ "description": "Rigging tasks for elegant includes",
+ "version": "0.1.0",
+ "homepage": "https://github.com/DamonOehlman/grunt-rigger",
+ "author": {
+ "name": "Damon Oehlman <damon.oehlman@sidelab.com>",
+ "email": "damon.oehlman@sidelab.com"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/DamonOehlman/grunt-rigger.git"
+ },
+ "bugs": {
+ "url": "https://github.com/DamonOehlman/grunt-rigger/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/DamonOehlman/grunt-rigger/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "grunt.js",
+ "bin": "bin/grunt-rigger",
+ "engines": {
+ "node": "*"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "dependencies": {
+ "async": "0.1.x",
+ "grunt": "~0.3.8",
+ "rigger": "0.2.x"
+ },
+ "devDependencies": {
+ "grunt": "~0.3.8"
+ },
+ "keywords": [
+ "gruntplugin"
+ ]
+}
@@ -0,0 +1,104 @@
+/*
+ * grunt-rigger
+ * https://github.com/damo/grunt-rigger
+ *
+ * Copyright (c) 2012 Damon Oehlman <damon.oehlman@sidelab.com>
+ * Licensed under the MIT license.
+ */
+
+var reFileTask = /^file\_/i,
+ path = require('path'),
+ async = require('async'),
+ rigger = require('rigger');
+
+module.exports = function(grunt) {
+
+ // Please see the grunt documentation for more information regarding task and
+ // helper creation: https://github.com/cowboy/grunt/blob/master/docs/toc.md
+
+ // ==========================================================================
+ // TASKS
+ // ==========================================================================
+
+ grunt.registerMultiTask('rig', 'Your task description goes here.', function() {
+ // get the files
+ var files = grunt.file.expandFiles(this.file.src),
+ callback = this.async(),
+ rigTask = this;
+
+ grunt.helper('rig', files, function(err, data) {
+ // write the output file
+ grunt.file.write(rigTask.file.dest, data);
+ grunt.log.writeln('File "' + rigTask.file.dest + '" created.');
+
+ // TODO: error handling for async
+
+ // trigger the callback
+ callback();
+ });
+ });
+
+ // ==========================================================================
+ // HELPERS
+ // ==========================================================================
+
+ grunt.registerHelper('rig', function(files, options, callback) {
+ // expand the directives
+ var fileOpts = files.map(function(filepath) {
+ var directive = grunt.task.getDirectiveParts(filepath);
+
+ // if the directive is a file directive, then extract the basepath
+ if (directive && reFileTask.test(directive[0])) {
+ filepath = directive[1];
+ }
+ // otherwise if we are dealing with a directive, then reset the filepath
+ else if (directive) {
+ filepath = '';
+ }
+
+ // return the directory for the path
+ return filepath ? {
+ cwd: path.resolve(path.dirname(filepath)),
+ filetype: path.extname(filepath).slice(1)
+ } : null;
+ }),
+
+ // get the file contents
+ fileContents = files.map(function(filepath) {
+ return grunt.task.directive(filepath, grunt.file.read);
+ }),
+
+ // define a file index to sync the contents map with basePath
+ // it's a bit hacky but async doesn't tell us
+ fileIndex = 0;
+
+ // remap options if required
+ if (typeof options === 'function') {
+ callback = options;
+ options = {};
+ }
+
+ // ensure we have options
+ options = options || {};
+
+ // default the separate to linefeed as per concat
+ options = grunt.utils._.defaults(options || {}, {
+ separator: grunt.utils.linefeed
+ });
+
+ // process each of the files that need to be rigged
+ async.map(
+ fileContents,
+
+ function(data, itemCallback) {
+ rigger.process(data, fileOpts[fileIndex++], itemCallback);
+ },
+
+ function(err, results) {
+ console.log(results);
+ callback(err, results.join(grunt.utils.normalizelf(options.separator)));
+ }
+ );
+ });
+
+};
@@ -0,0 +1,36 @@
+var grunt = require('grunt');
+
+/*
+ ======== A Handy Little Nodeunit Reference ========
+ https://github.com/caolan/nodeunit
+
+ Test methods:
+ test.expect(numAssertions)
+ test.done()
+ Test assertions:
+ test.ok(value, [message])
+ test.equal(actual, expected, [message])
+ test.notEqual(actual, expected, [message])
+ test.deepEqual(actual, expected, [message])
+ test.notDeepEqual(actual, expected, [message])
+ test.strictEqual(actual, expected, [message])
+ test.notStrictEqual(actual, expected, [message])
+ test.throws(block, [error], [message])
+ test.doesNotThrow(block, [error], [message])
+ test.ifError(value)
+*/
+
+exports['rigger'] = {
+ setUp: function(done) {
+ // setup here
+ done();
+ },
+ 'helper': function(test) {
+ // test.expect(1);
+ // tests here
+ // test.equal(grunt.helper('rigger'), 'rigger!!!', 'should return the correct value.');
+ // TODO: tests
+
+ test.done();
+ }
+};

0 comments on commit 905f949

Please sign in to comment.