Skip to content
Browse files

Merge branch 'release/0.0.2'

  • Loading branch information...
2 parents c87d5f3 + 24c6737 commit 7978020c403603ac270207b491a2fe533edb6ddb @davidtucker committed Aug 1, 2013
Showing with 204 additions and 68 deletions.
  1. +50 −0 Gruntfile.js
  2. +104 −3 README.md
  3. +0 −40 grunt.js
  4. +12 −7 package.json
  5. +38 −18 tasks/wintersmith.js
View
50 Gruntfile.js
@@ -0,0 +1,50 @@
+module.exports = function(grunt) {
+
+ // Project configuration
+ grunt.initConfig({
+
+ cfg: {
+ files: [
+ 'Gruntfile.js',
+ 'tasks/**/*.js',
+ 'test/**/*.js'
+ ]
+ },
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ node: true
+ },
+ globals: {},
+ dev: '<%= cfg.files %>'
+ },
+ watch: {
+ js: {
+ files: '<%= cfg.files %>',
+ tasks: ['jshint']
+ }
+ }
+
+ });
+
+ // Load npm tasks
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-watch');
+
+ // Load local tasks
+ grunt.loadTasks('tasks');
+
+ // Default task
+ grunt.registerTask('default', ['jshint:dev']);
+ grunt.registerTask('develop', ['watch']);
+
+};
View
107 README.md
@@ -1,4 +1,105 @@
-grunt-wintersmith
-=================
+# grunt-wintersmith
-A grunt task and helpers for invoking the Wintersmith static site generator
+A grunt task for working with the [Wintersmith](https://github.com/jnordberg/wintersmith) static site generator.
+
+## Getting Started
+This plugin requires Grunt `~0.4.0`
+
+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:
+
+```shell
+npm install grunt-wintersmith --save-dev
+```
+
+Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
+
+```js
+grunt.loadNpmTasks('grunt-wintersmith');
+```
+
+* This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that [you upgrade](http://gruntjs.com/upgrading-from-0.3-to-0.4).
+
+* This plugin was designed to work with Wintersmith 2.x. If you're still using v1.x, you should upgrade.
+
+## Wintersmith task
+
+_Run this task with the `grunt wintersmith` command._
+
+Each task may include options for setting both the action and the configuration file to be used.
+
+### Options
+
+#### action
+
+Type: `String`
+Default: `'build'`
+
+This value currently supports `'build'` or `'preview'`. If you use `'build'` it will build the site with Wintersmith using either the default or the user defined config file. If you use `'preview'`, it will run the Wintersmith preview server for either the default or the user defined config file. Any other value will result in an error.
+
+> It is important to note that `'preview'` is an asychronous task which will run until you end it. If you want to utilize this alongside a similar task (like [grunt-contrib-watch](https://github.com/gruntjs/grunt-contrib-watch)), you will either need to use another command line window or utilize a grunt plugin which allows for concurrent tasks (like [grunt-concurrent](https://github.com/sindresorhus/grunt-concurrent)).
+
+#### config
+
+Type: `String`
+Default: `'./config.json'`
+
+The configuration file to use for the specified task. By default it utilizes `'./config.json'`, but if you need another value, you may specify it here.
+
+## Sample Grunt Files
+
+If you are utilizing the standard value for config, (which is `./config.json`), then you can simply define your tasks as follows:
+
+```js
+module.exports = function(grunt) {
+
+ grunt.initConfig({
+
+ wintersmith: {
+ build: {},
+ preview: {
+ options: {
+ action: "preview"
+ }
+ }
+ }
+
+ });
+
+ // Load NPM Task
+ grunt.loadNpmTasks('grunt-wintersmith');
+
+};
+```
+
+In situations where you want to define separate environments which have separate configurations, or if you need to utilize another configuration file, you can include the `config` option within the options object:
+
+```js
+module.exports = function(grunt) {
+
+ grunt.initConfig({
+
+ wintersmith: {
+ staging: {
+ options: {
+ config: './config-staging.json'
+ }
+ },
+ production: {
+ options: {
+ config: './config-production.json'
+ }
+ },
+ preview: {
+ options: {
+ action: "preview",
+ config: './config-preview.json'
+ }
+ }
+ }
+ });
+
+ // Load NPM Task
+ grunt.loadNpmTasks('grunt-wintersmith');
+
+};
+```
View
40 grunt.js
@@ -1,40 +0,0 @@
-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');
-
-};
View
19 package.json
@@ -1,31 +1,36 @@
{
"author": "adam j. sontag <ajpiano@ajpiano.com> (http://ajpiano.com)",
+ "contributors": [
+ "David Tucker <david@davidtucker.net> (http://davidtucker.net)"
+ ],
"name": "grunt-wintersmith",
"description": "A grunt task and helpers for invoking the Wintersmith static site generator",
- "version": "0.0.1",
- "homepage": "https://github.com/ajpiano/grunt-wintersmith",
+ "version": "0.0.2",
+ "homepage": "https://github.com/davidtucker/grunt-wintersmith",
"repository": {
"type": "git",
- "url": "git://github.com/ajpiano/grunt-wintersmith.git"
+ "url": "git://github.com/davidtucker/grunt-wintersmith.git"
},
- "licenses": [
+ "licenses": [
{
"type": "MIT",
"url": "https://github.com/ajpiano/grunt-wintersmith/blob/master/LICENSE-MIT"
}
],
- "main": "grunt.js",
+ "main": "Gruntfile.js",
"dependencies": {
"grunt": "~0.4.1",
"wintersmith": "~2.0.5"
},
"devDependencies": {
"grunt": "~0.4.1",
- "wintersmith": "~2.0.5"
+ "wintersmith": "~2.0.5",
+ "grunt-contrib-jshint": "~0.6.1",
+ "grunt-contrib-watch": "~0.5.1"
},
"keywords": [
"gruntplugin"
- ],
+ ],
"engines": {
"node": "*"
}
View
56 tasks/wintersmith.js
@@ -1,29 +1,49 @@
+var wintersmith = require("wintersmith");
+
module.exports = function(grunt) {
- var wintersmith = require("wintersmith");
+ var done = {};
- grunt.registerMultiTask("wintersmith", "Use the wintersmith static site generator", function () {
- var options = this.options({
- // create the sites environment, can also be called with a config object. e.g.
- // {contents: '/some/contents', locals: {powerLevel: 10}}, ..}
- config: "./config.json"
- }),
- done = this.async();
-
- // build site
- grunt.helper("wintersmith", options, function (error) {
- if (error) { throw error; }
+ var callback = function(error) {
+ if(error) {
+ throw error;
+ done(false);
+ }
+ if(done) {
done();
+ }
+ };
+
+ grunt.registerMultiTask("wintersmith", "Use the wintersmith static site generator", function () {
+
+ var options = this.options();
+ grunt.verbose.writeflags(options, 'Options');
+ var _ = grunt.util._;
+
+ // Create options object by merging user defined options and default options
+ options = _.defaults(options, {
+ action: 'build',
+ config: './config.json'
});
- });
+ // This is an async task, so we need to get the done function
+ done = this.async();
- grunt.registerHelper("wintersmith", function (options, callback) {
- // create the sites environment, can also be called with a config object. e.g.
- // {contents: '/some/contents', locals: {powerLevel: 10}}, ..}
+ // Create the Wintersmith environment using config file
var env = wintersmith(options.config);
- // build site
- env.build(callback);
+
+ if(options.action === 'build') {
+ // Build the site using the specified options
+ env.build(callback);
+ } else if(options.action === 'preview') {
+ // This is asynchronous and needs to continue - be sure done isn't called
+ done = null;
+ env.preview(callback);
+ } else {
+ grunt.log.error('Action not supported. May be build or preview.');
+ done(false);
+ }
+
});
};

0 comments on commit 7978020

Please sign in to comment.
Something went wrong with that request. Please try again.