From e9518fedeb9ac63c2ed46cb3e7d43f659b0c6415 Mon Sep 17 00:00:00 2001 From: Hariadi Hinta Date: Mon, 10 Mar 2014 23:53:45 +0800 Subject: [PATCH] initial commit commited.. --- .editorconfig | 13 +++ .gitignore | 2 + .jshintrc | 21 ++++ .travis.yml | 7 ++ README.md | 52 ++++++++++ app/USAGE | 3 + app/index.js | 98 +++++++++++++++++++ app/templates/Makefile | 8 ++ app/templates/README.md | 10 ++ app/templates/_layouts/post.html | 10 ++ app/templates/_metalsmith.json | 19 ++++ app/templates/_package.json | 21 ++++ app/templates/_posts/2012-08-20-first-post.md | 7 ++ .../_posts/2012-08-23-second-post.md | 7 ++ app/templates/_posts/2012-09-28-third-post.md | 7 ++ .../_posts/2012-12-07-fourth-post.md | 7 ++ app/templates/gitignore | 1 + package.json | 46 +++++++++ test/test-creation.js | 46 +++++++++ test/test-load.js | 10 ++ 20 files changed, 395 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 app/USAGE create mode 100644 app/index.js create mode 100644 app/templates/Makefile create mode 100644 app/templates/README.md create mode 100644 app/templates/_layouts/post.html create mode 100644 app/templates/_metalsmith.json create mode 100644 app/templates/_package.json create mode 100644 app/templates/_posts/2012-08-20-first-post.md create mode 100644 app/templates/_posts/2012-08-23-second-post.md create mode 100644 app/templates/_posts/2012-09-28-third-post.md create mode 100644 app/templates/_posts/2012-12-07-fourth-post.md create mode 100644 app/templates/gitignore create mode 100644 package.json create mode 100644 test/test-creation.js create mode 100644 test/test-load.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e717f5e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..206ba3c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +temp/ diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..448c0bc --- /dev/null +++ b/.jshintrc @@ -0,0 +1,21 @@ +{ + "node": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": "single", + "regexp": true, + "undef": true, + "unused": true, + "strict": true, + "trailing": true, + "smarttabs": true, + "white": true +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..18e3fac --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - '0.10' +before_install: + - currentfolder=${PWD##*/} + - if [ "$currentfolder" != 'generator-metalsmith' ]; then cd .. && eval "mv $currentfolder generator-metalsmith" && cd generator-metalsmith; fi + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a718a49 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# generator-metalsmith [![Build Status](https://secure.travis-ci.org/hariadi/generator-metalsmith.png?branch=master)](https://travis-ci.org/hariadi/generator-metalsmith) + +> [Yeoman](http://yeoman.io) generator for [Metalsmith](http://metalsmith.io) + + +## Getting Started + +### What is Yeoman? + +Trick question. It's not a thing. It's this guy: + +![](http://i.imgur.com/JHaAlBJ.png) + +Basically, he wears a top hat, lives in your computer, and waits for you to tell him what kind of application you wish to create. + +Not every new computer comes with a Yeoman pre-installed. He lives in the [npm](https://npmjs.org) package repository. You only have to ask for him once, then he packs up and moves into your hard drive. *Make sure you clean up, he likes new and shiny things.* + +``` +$ npm install -g yo +``` + +### Yeoman Generators + +Yeoman travels light. He didn't pack any generators when he moved in. You can think of a generator like a plug-in. You get to choose what type of application you wish to create, such as a Backbone application or even a Chrome extension. + +To install generator-metalsmith from npm, run: + +``` +$ npm install -g generator-metalsmith +``` + +Finally, initiate the generator: + +``` +$ yo metalsmith +``` + +### Getting To Know Yeoman + +Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced. + +If you'd like to get to know Yeoman better and meet some of his friends, [Grunt](http://gruntjs.com) and [Bower](http://bower.io), check out the complete [Getting Started Guide](https://github.com/yeoman/yeoman/wiki/Getting-Started). + + +## License + +Copyright (c) 2014, Hariadi Hinta + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + diff --git a/app/USAGE b/app/USAGE new file mode 100644 index 0000000..7fd0d7b --- /dev/null +++ b/app/USAGE @@ -0,0 +1,3 @@ +Example: + yo metalsmith + yo metalsmith [--skip-install] [--skip-welcome-message] diff --git a/app/index.js b/app/index.js new file mode 100644 index 0000000..2adff68 --- /dev/null +++ b/app/index.js @@ -0,0 +1,98 @@ +'use strict'; + +var yeoman = require('yeoman-generator'); +var chalk = require('chalk'); + +var MetalsmithGenerator = yeoman.generators.Base.extend({ + + init: function () { + this.pkg = require('../package.json'); + + this.on('end', function () { + this.installDependencies({ + skipInstall: this.options['skip-install'] || this.options['s'], + callback: function () { + this.spawnCommand('make', ['build']); + }.bind(this) + }); + }); + + }, + + askFor: function () { + var done = this.async(); + + if (!this.options['skip-welcome-message'] || !this.options['w']) { + this.log(this.yeoman); + } + + this.log(chalk.magenta('You\'re using the fantastic Metalsmith generator.')); + + /* + TODO: + 1. build type + 2. metalsmith-templates engine + */ + + var prompts = [{ + type : 'input', + name : 'msTitle', + message : 'Site Title', + default : this.appname + }, { + type : 'input', + name : 'msDesc', + message : 'Site Description', + default : 'My Metalsmith-Powered Site' + }, { + type : "input", + name : "msAuthor", + message : "Author name", + default : this.user.git.username || 'Metal Smith' + }, { + type : "input", + name : "msGithubUser", + message : "Would you mind telling me your username on Github?", + default : process.env.username || 'metalsmith' + }]; + + this.prompt(prompts, function (answers) { + + for (var key in answers) { + if (answers.hasOwnProperty(key)) { + this[key] = answers[key]; + } + } + + done(); + }.bind(this)); + }, + + site: function () { + this.mkdir('_site'); + }, + + layouts: function () { + this.mkdir('_layouts'); + this.directory('_layouts', '_layouts'); + }, + + posts: function () { + this.mkdir('_posts'); + this.directory('_posts', '_posts'); + }, + + gitfiles: function () { + this.copy('gitignore', '.gitignore'); + }, + + app: function () { + this.copy('_package.json', 'package.json'); + this.copy('_metalsmith.json', 'metalsmith.json'); + this.copy('Makefile', 'Makefile'); + this.copy('README.md', 'README.md'); + }, + +}); + +module.exports = MetalsmithGenerator; diff --git a/app/templates/Makefile b/app/templates/Makefile new file mode 100644 index 0000000..cc31de3 --- /dev/null +++ b/app/templates/Makefile @@ -0,0 +1,8 @@ + +build: node_modules + node_modules/.bin/metalsmith + +node_modules: package.json + npm install + +.PHONY: build \ No newline at end of file diff --git a/app/templates/README.md b/app/templates/README.md new file mode 100644 index 0000000..f517a09 --- /dev/null +++ b/app/templates/README.md @@ -0,0 +1,10 @@ +# <%= _.capitalize(msTitle) %> + +> <%= _.capitalize(msDesc) %>. + +This boilerplate static site uses Metalsmith to emulate a Jekyll static site. To test it out yourself just run: + + $ make + +## Release History + * <%= (new Date).toISOString().split('T')[0] %>   v0.1.0   Generated by the [Yeoman Generator](https://github.com/hariadi/generator-metalsmith) for [Metalsmith](http://metalsmith.io/) diff --git a/app/templates/_layouts/post.html b/app/templates/_layouts/post.html new file mode 100644 index 0000000..ad6f1c7 --- /dev/null +++ b/app/templates/_layouts/post.html @@ -0,0 +1,10 @@ + + + <%= _.capitalize(msTitle) %> + + +

{{ title }}

+ + {{ contents | safe }} + + diff --git a/app/templates/_metalsmith.json b/app/templates/_metalsmith.json new file mode 100644 index 0000000..b0835b6 --- /dev/null +++ b/app/templates/_metalsmith.json @@ -0,0 +1,19 @@ +{ + "source": "./_posts", + "destination": "./_site", + "metadata": { + "title": "<%= _.capitalize(msTitle) %>", + "description": "<%= msDesc %>" + }, + "plugins": { + "metalsmith-drafts": {}, + "metalsmith-markdown": {}, + "metalsmith-permalinks": { + "pattern": ":title" + }, + "metalsmith-templates": { + "engine": "swig", + "directory": "_layouts" + } + } +} diff --git a/app/templates/_package.json b/app/templates/_package.json new file mode 100644 index 0000000..a1ea3e7 --- /dev/null +++ b/app/templates/_package.json @@ -0,0 +1,21 @@ +{ + "name": "<%= _.slugify(msTitle) %>", + "version": "0.1.0", + "description": "<%= msDesc %>", + "author": { + "name": "<%= msAuthor %>", + "url": "https://github.com/<%= msGithubUser %>" + }, + "repository": { + "type": "git", + "url": "https://github.com/<%= msGithubUser %>/<%= _.slugify(msTitle) %>" + }, + "dependencies": { + "metalsmith-drafts": "0.0.1", + "metalsmith-templates": "^0.1.0", + "metalsmith-markdown": "^0.2.1", + "metalsmith-permalinks": "^0.1.0", + "swig": "^1.3.2", + "metalsmith": "^0.2.3" + } +} diff --git a/app/templates/_posts/2012-08-20-first-post.md b/app/templates/_posts/2012-08-20-first-post.md new file mode 100644 index 0000000..0af8501 --- /dev/null +++ b/app/templates/_posts/2012-08-20-first-post.md @@ -0,0 +1,7 @@ +--- +title: First Post +date: 2012-08-20 +template: post.html +--- + +An interesting post about how it's going to be different this time around. I'm going write a lot more nowadays and use this blog to improve my writing. \ No newline at end of file diff --git a/app/templates/_posts/2012-08-23-second-post.md b/app/templates/_posts/2012-08-23-second-post.md new file mode 100644 index 0000000..1c9a167 --- /dev/null +++ b/app/templates/_posts/2012-08-23-second-post.md @@ -0,0 +1,7 @@ +--- +title: Second Post +date: 2012-08-23 +template: post.html +--- + +A super-interesting piece of prose I had already written weeks ago. \ No newline at end of file diff --git a/app/templates/_posts/2012-09-28-third-post.md b/app/templates/_posts/2012-09-28-third-post.md new file mode 100644 index 0000000..4f16235 --- /dev/null +++ b/app/templates/_posts/2012-09-28-third-post.md @@ -0,0 +1,7 @@ +--- +title: Third Post +date: 2012-09-28 +template: post.html +--- + +A slightly late, less interesting piece of prose. \ No newline at end of file diff --git a/app/templates/_posts/2012-12-07-fourth-post.md b/app/templates/_posts/2012-12-07-fourth-post.md new file mode 100644 index 0000000..a53380d --- /dev/null +++ b/app/templates/_posts/2012-12-07-fourth-post.md @@ -0,0 +1,7 @@ +--- +title: Fourth Post +date: 2012-12-07 +template: post.html +--- + +A really short, rushed-feeling string of words. \ No newline at end of file diff --git a/app/templates/gitignore b/app/templates/gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/app/templates/gitignore @@ -0,0 +1 @@ +node_modules diff --git a/package.json b/package.json new file mode 100644 index 0000000..44b975d --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "generator-metalsmith", + "version": "0.1.0", + "homepage": "https://github.com/hariadi/generator-metalsmith", + "description": "Yeoman generator for Metalsmith", + "author": { + "name": "Hariadi Hinta", + "url": "https://github.com/hariadi" + }, + "license": "ISC", + "main": "app/index.js", + "repository": { + "type": "git", + "url": "https://github.com/hariadi/generator-metalsmith.git" + }, + "bugs": { + "url": "https://github.com/hariadi/generator-metalsmith/issues" + }, + + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "mocha --reporter spec" + }, + "files": [ + "app" + ], + "dependencies": { + "yeoman-generator": "~0.16.0", + "chalk": "~0.4.0" + }, + "devDependencies": { + "mocha": "*" + }, + "peerDependencies": { + "yo": ">=1.0.0" + }, + "keywords": [ + "yeoman-generator", + "metalsmith", + "generator", + "static", + "site" + ] +} diff --git a/test/test-creation.js b/test/test-creation.js new file mode 100644 index 0000000..4faaaa9 --- /dev/null +++ b/test/test-creation.js @@ -0,0 +1,46 @@ +/*global describe, beforeEach, it */ +'use strict'; +var path = require('path'); +var helpers = require('yeoman-generator').test; + +describe('metalsmith generator', function () { + beforeEach(function (done) { + helpers.testDirectory(path.join(__dirname, 'temp'), function (err) { + if (err) { + return done(err); + } + + this.app = helpers.createGenerator('metalsmith:app', [ + '../../app' + ]); + done(); + }.bind(this)); + }); + + it('creates expected files', function (done) { + var expected = [ + '_layouts/post.html', + '_posts/2012-08-20-first-post.md', + '_posts/2012-08-23-second-post.md', + '_posts/2012-09-28-third-post.md', + '_posts/2012-12-07-fourth-post.md', + '.gitignore', + 'package.json', + 'metalsmith.json', + 'Makefile', + 'README.md' + ]; + + helpers.mockPrompt(this.app, { + 'msTitle': 'Metalsmith Blog', + 'msDesc': 'My Metalsmith-Powered Site', + 'msAuthor': 'Metal Smith', + 'msGithubUser': 'metalsmith', + }); + this.app.options['skip-install'] = true; + this.app.run({}, function () { + helpers.assertFile(expected); + done(); + }); + }); +}); diff --git a/test/test-load.js b/test/test-load.js new file mode 100644 index 0000000..3f6c6aa --- /dev/null +++ b/test/test-load.js @@ -0,0 +1,10 @@ +/*global describe, beforeEach, it*/ +'use strict'; +var assert = require('assert'); + +describe('metalsmith generator', function () { + it('can be imported without blowing up', function () { + var app = require('../app'); + assert(app !== undefined); + }); +});