Skip to content

Commit

Permalink
Merge pull request #2 from hariadi/develop
Browse files Browse the repository at this point in the history
v0.2.0
  • Loading branch information
hariadi committed Mar 15, 2014
2 parents c580864 + f05301e commit c75a59c
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 121 deletions.
251 changes: 153 additions & 98 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,98 +1,153 @@
'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;
'use strict';

var yeoman = require('yeoman-generator');

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)
});
});

this.metalsmith = require('../metalsmith.json');

},

askFor: function () {
var done = this.async();

if (!this.options['skip-welcome-message'] || !this.options.w) {
this.log(this.yeoman);
}

var plugins = this.metalsmith.plugins;
var choices = [];
for (var plugin in plugins) {
if (plugins.hasOwnProperty(plugin)) {
choices.push({ name: plugin, checked: true });
}
}

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'
}, {
type: 'checkbox',
name: 'msPlugins',
message: 'Which plugins do you want to use?',
choices: choices
}, {
type: 'list',
message: 'Which template engine do you want to use?',
name: 'templateEngine',
//TODO: support https://github.com/visionmedia/consolidate.js#supported-template-engines
choices: [{
name: 'swig',
checked: true
}, 'handlebars'],
when : function (answers) {
return answers.msPlugins.indexOf('metalsmith-templates') > -1;
}
}, {
type: 'input',
message: 'What should a permalink look like?',
name: 'permalinksPattern',
default : ':title',
when : function (answers) {
return answers.msPlugins.indexOf('metalsmith-permalinks') > -1;
}
}];

this.prompt(prompts, function (answers) {

var deps = this._.object(answers.msPlugins.map(function (plugin) {
return plugin.replace('metalsmith-', '');
}), answers.msPlugins.map(function () {
return true;
}));

for (var key in answers) {
if (answers.hasOwnProperty(key)) {
if (key === 'msPlugins') {

for (var pkg in deps) {
if (deps.hasOwnProperty(pkg)) {
this[pkg] = deps[pkg];
}
}

} else {
this[key] = answers[key];
}
}
}

done();
}.bind(this));
},

site: function () {
this.mkdir('_site');
},

layouts: function () {

var prefix = (this.templateEngine === 'swig') ? '' : this.templateEngine + '-';

this.mkdir('_layouts');
this.template('_layouts/' + prefix + 'default.html', '_layouts/default.html');
this.template('_layouts/' + prefix + 'post.html', '_layouts/post.html');
},

posts: function () {
this.mkdir('_posts');
this.directory('_posts', '_posts');
},

gitfiles: function () {
this.copy('gitignore', '.gitignore');
},

package: function () {
this.template('_package.json', 'package.json');
},

metalsmith: function () {
this.template('_metalsmith.json', 'metalsmith.json');
},

makefile: function () {
this.copy('Makefile', 'Makefile');
},

readme: function () {
this.copy('README.md', 'README.md');
},

});

module.exports = MetalsmithGenerator;
16 changes: 16 additions & 0 deletions app/templates/_layouts/handlebars-default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html>
<head>
<title><%= _.capitalize(msTitle) %> - {{ title }}</title>
</head>
<body>
<h2>Blog Posts</h2>

{{#if articles }}
{{#each articles }}
<h2><a href="{{ article.path }}/index.html">{{ article.title }}</a></h2>
<time>{{ article.date }}</time>
{{/each}}
{{/if}}

</body>
</html>
12 changes: 12 additions & 0 deletions app/templates/_layouts/handlebars-post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title><%= _.capitalize(msTitle) %> - {{ title }}</title>
</head>
<body>
<h1>{{ title }}</h1>

<time>{{ date }}</time>
{{{ contents }}}

</body>
</html>
12 changes: 12 additions & 0 deletions app/templates/_layouts/handlebars.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title><%= _.capitalize(msTitle) %> - {{ title }}</title>
</head>
<body>
<h1>{{ title }}</h1>

<time>{{ date }}</time>
{{{ contents }}}

</body>
</html>
2 changes: 2 additions & 0 deletions app/templates/_layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
</head>
<body>
<h1>{{ title }}</h1>

<time>{{ date | date('Y-m-d') }}</time>
{{ contents | safe }}

</body>
</html>
18 changes: 9 additions & 9 deletions app/templates/_metalsmith.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"title": "<%= _.capitalize(msTitle) %>",
"description": "<%= msDesc %>"
},
"plugins": {
"plugins": {<% if(ignore){ %>
"metalsmith-ignore": [
"_drafts/*",
"_posts/index.md"
],
"metalsmith-drafts": {},
"metalsmith-markdown": {},
],<% } %><% if(drafts){ %>
"metalsmith-drafts": {},<% } %><% if(markdown){ %>
"metalsmith-markdown": {},<% } %><% if(permalinks){ %>
"metalsmith-permalinks": {
"pattern": ":title"
},
"pattern": "<%= permalinksPattern %>"
},<% } %><% if(collections){ %>
"metalsmith-collections": {
"articles": {
"pattern": "*.md",
"sortBy": "date",
"reverse": true
}
},
},<% } %><% if(templates){ %>
"metalsmith-templates": {
"engine": "swig",
"engine": "<%= templateEngine %>",
"directory": "_layouts"
}
}<% } %>
}
}
14 changes: 7 additions & 7 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"type": "git",
"url": "https://github.com/<%= msGithubUser %>/<%= _.slugify(msTitle) %>"
},
"dependencies": {
"metalsmith-ignore": "^0.1.2",
"metalsmith-drafts": "0.0.1",
"dependencies": {<% if(ignore){ %>
"metalsmith-ignore": "^0.1.2",<% } %><% if(drafts){ %>
"metalsmith-drafts": "0.0.1",<% } %><% if(templates){ %>
"metalsmith-templates": "^0.3.0",
"metalsmith-markdown": "^0.2.1",
"metalsmith-permalinks": "^0.2.0",
"metalsmith-collections": "^0.1.0",
"swig": "^1.3.2",
"<%= templateEngine %>": "*",<% } %><% if(markdown){ %>
"metalsmith-markdown": "^0.2.1",<% } %><% if(permalinks){ %>
"metalsmith-permalinks": "^0.2.0",<% } %><% if(collections){ %>
"metalsmith-collections": "^0.1.0",<% } %>
"metalsmith": "^0.3.0"
}
}
16 changes: 16 additions & 0 deletions metalsmith.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"title": "Metalsmith Blog",
"description": "My Metalsmith-Powered Site",
"plugins": {
"metalsmith-ignore": "^0.1.2",
"metalsmith-drafts": "^0.0.1",
"metalsmith-templates": "^0.3.0",
"metalsmith-markdown": "^0.2.1",
"metalsmith-permalinks": "^0.2.0",
"metalsmith-collections": "^0.1.0"
},
"engine": {
"swig": "^1.3.2",
"handlebars": "^2.0.0-alpha.2"
}
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-metalsmith",
"version": "0.1.1",
"version": "0.2.0",
"homepage": "https://github.com/hariadi/generator-metalsmith",
"description": "Yeoman generator for Metalsmith",
"author": {
Expand All @@ -27,8 +27,7 @@
"app"
],
"dependencies": {
"yeoman-generator": "~0.16.0",
"chalk": "~0.4.0"
"yeoman-generator": "~0.16.0"
},
"devDependencies": {
"mocha": "*"
Expand Down
Loading

0 comments on commit c75a59c

Please sign in to comment.