Skip to content
This repository has been archived by the owner on Aug 19, 2018. It is now read-only.

Commit

Permalink
Add templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
gillesfabio committed Jun 21, 2014
1 parent a2d60c4 commit db17b1b
Show file tree
Hide file tree
Showing 20 changed files with 285 additions and 19 deletions.
19 changes: 4 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules
test/tmp
tmp
public
build
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NODE_LOCAL_BIN=./node_modules/.bin

test:
@${NODE_LOCAL_BIN}/mocha --reporter spec test/specs/**/*.js

.PHONY: test
5 changes: 5 additions & 0 deletions app/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Description:
Creates a new project.

Example:
yo metalpages
22 changes: 21 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,24 @@

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

module.exports = yeoman.generators.Base.extend({});
module.exports = yeoman.generators.Base.extend({
directories: function() {
this.directory('src', 'src');
this.directory('static', 'static');
},
templates: function() {
this.template('_bower.json', 'bower.json');
this.template('_package.json', 'package.json');
this.template('_README.md', 'README.md');
this.mkdir('templates');
this.template('templates/_layout.html', 'templates/layout.html');
this.template('templates/_index.html', 'templates/index.html');
},
files: function() {
this.copy('build.js', 'build.js');
this.copy('editorconfig', '.editorconfig');
this.copy('gitignore', '.gitignore');
this.copy('gulpfile.js', 'gulpfile.js');
this.copy('Makefile', 'Makefile');
}
});
17 changes: 17 additions & 0 deletions app/templates/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
install:
@npm install
@bower install

clean:
@rm -rf build public

build: clean
@gulp build

serve: build
@gulp

publish:
@gulp deploy

.PHONY: install clean build serve publish
9 changes: 9 additions & 0 deletions app/templates/_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## <%= appname %>

### Installation

```
$ make install
$ make serve
$ open http://localhost:3000
```
5 changes: 5 additions & 0 deletions app/templates/_bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "<%= _.slugify(appname) %>",
"version": "0.0.0",
"private": true
}
21 changes: 21 additions & 0 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "<%= _.slugify(appname) %>",
"version": "0.0.0",
"private": true,
"engines": {
"node": ">=0.10.0"
},
"devDependencies": {
"express": "^4.4.3",
"gulp": "^3.8.1",
"gulp-concat": "^2.2.0",
"gulp-gh-pages": "^0.3.2",
"gulp-jsonlint": "0.0.3",
"gulp-minify-css": "^0.3.5",
"metalsmith": "^0.8.0",
"metalsmith-markdown": "^0.2.1",
"metalsmith-metadata": "0.0.1",
"metalsmith-templates": "^0.5.1",
"swig": "^1.3.2"
}
}
22 changes: 22 additions & 0 deletions app/templates/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

var Metalsmith = require('metalsmith');
var metadata = require('metalsmith-metadata');
var templates = require('metalsmith-templates');
var markdown = require('metalsmith-markdown');

module.exports = build;

var m = new Metalsmith(__dirname);

m.destination('./public');
m.use(metadata({metadata: 'metadata.json'}));
m.use(markdown({smartypants: true, gfm: true, tables: true}));
m.use(templates({engine: 'swig', directory: 'templates'}));

function build(done) {
m.build(function(err) {
if (err) return done(err);
done();
});
}
5 changes: 5 additions & 0 deletions app/templates/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
node_modules
bower_components
build
public
71 changes: 71 additions & 0 deletions app/templates/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict';

var path = require('path');
var express = require('express');
var gulp = require('gulp');
var concat = require('gulp-concat');
var minify = require('gulp-minify-css');
var jsonlint = require("gulp-jsonlint");
var deploy = require('gulp-gh-pages');
var swig = require('swig');
var build = require('./build');

gulp.task('css', function() {
return gulp.src([
'static/css/**/*.css'
])
.pipe(concat('bundle.css'))
.pipe(minify())
.pipe(gulp.dest('build'));
});

gulp.task('images', function() {
return gulp.src(['static/images/**/*'])
.pipe(gulp.dest('build'));
});

gulp.task('lint:json', function() {
return gulp.src([
'src/**/*.json'
])
.pipe(jsonlint())
.pipe(jsonlint.reporter());
});

gulp.task('build:metalsmith', ['lint:json'], function(done) {
build(function(err){
if (err) return err;
console.log('Metalsmith building... Done.');
done();
});
});

gulp.task('build', ['build:metalsmith', 'css', 'images'], function() {
return gulp.src(['build/**/*'])
.pipe(gulp.dest('public'));
});

gulp.task('deploy', ['build'], function() {
return gulp.src('./public/**/*')
.pipe(deploy());
});

gulp.task('serve', ['watch', 'build'], function() {
var port = process.env.NODE_PORT || 3000;
var app = express();
app.set('view cache', false);
swig.setDefaults({cache: false});
app.use(express.static(path.join(__dirname, 'public')));
app.listen(port);
console.log('Server running on localhost:%d...', port);
});

gulp.task('watch', function() {
gulp.watch([
'static/**/*',
'src/**/*',
'templates/**/*'
], ['build']);
});

gulp.task('default', ['serve']);
3 changes: 3 additions & 0 deletions app/templates/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
template: index.html
---
3 changes: 3 additions & 0 deletions app/templates/src/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "Hello, you!"
}
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions app/templates/templates/_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "layout.html" %}

{% block content %}
<h1><%= appname %></h1>
<p>{{ metadata.hello }}</p>
{% endblock %}
16 changes: 16 additions & 0 deletions app/templates/templates/_layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><%= appname %></title>
<link rel="stylesheet" href="bundle.css">
</head>
<body>
<div id="content">
<div class="container">
{% block content %}
{% endblock %}
</div>
</div>
</body>
</html>
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
"yeoman-generator": "^0.17.0"
},
"devDependencies": {
"mocha": "^1.20.1",
"sinon": "^1.10.2",
"supertest": "^0.13.0"
"mocha": "^1.20.1"
}
}
8 changes: 8 additions & 0 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

var path = require('path');

var config = module.exports = {};

config.testDirectory = path.join(__dirname, 'tmp');
config.appPath = path.join(__dirname, '..', 'app');
62 changes: 62 additions & 0 deletions test/specs/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*jshint expr: true*/
/*global describe, beforeEach, it*/
'use strict';

var generator = require('yeoman-generator');
var helpers = generator.test;
var assert = generator.assert;
var config = require('../config');

describe('base', function() {

beforeEach(function(done) {
helpers.testDirectory(config.testDirectory, function(err) {
if (err) return done(err);
this.app = helpers.createGenerator('metalpages', [config.appPath]);
this.app.options['skip-install'] = true;
done();
}.bind(this));
});

it('should properly setup project', function(done) {
helpers.mockPrompt(this.app, this.prompts);
var expected = [
'src/metadata.json',
'src/index.md',
'static/css/index.css',
'static/images',
'templates/layout.html',
'templates/index.html',
'.editorconfig',
'.gitignore',
'bower.json',
'package.json',
'build.js',
'gulpfile.js',
'Makefile',
'README.md'
];
this.app.run({}, function() {
assert.file(expected);
done();
});
});

it('should properly setup app name in all templates', function(done) {
helpers.mockPrompt(this.app, this.prompts);
var files = [
'bower.json',
'package.json',
'README.md',
'templates/layout.html',
'templates/index.html'
];
this.app.run({}, function() {
files.forEach(function(file) {
assert.fileContent(file, /tmp/);
});
done();
});
});

});

0 comments on commit db17b1b

Please sign in to comment.