-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from hariadi/develop
v0.2.0
- Loading branch information
Showing
10 changed files
with
243 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
</head> | ||
<body> | ||
<h1>{{ title }}</h1> | ||
|
||
<time>{{ date | date('Y-m-d') }}</time> | ||
{{ contents | safe }} | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.