Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit b74f0ef

Browse files
author
Kahlil Lechelt
committed
Add sub-generator functionality for html pages.
1 parent d54cc26 commit b74f0ef

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ root = true
33

44
[*]
55
indent_style = space
6-
indent_size = 4
6+
indent_size = 2
77
end_of_line = lf
88
charset = utf-8
99
trim_trailing_whitespace = true

lib/initgenerator.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ InitGeneratorUtils.prototype = {
4646
}.bind(this));
4747
}
4848
}.bind(this));
49+
},
50+
51+
writePagesJson: function writePagesJson(pgs) {
52+
pgs[this.name] = {
53+
src: [
54+
'templates/header.html',
55+
'templates/' + this.name + '.html',
56+
'templates/footer.html'
57+
],
58+
dest: 'temp/' + this.name + '.html'
59+
};
60+
61+
fs.writeFileSync('pages.json', JSON.stringify(pgs, null, 2));
4962
}
5063
};
5164

page/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
var util = require('util');
4+
var fs = require('fs');
5+
var path = require('path');
6+
var initHelpers = require('../lib/initgenerator.js');
7+
var yeoman = require('yeoman-generator');
8+
9+
var PageGenerator = module.exports = function PageGenerator() {
10+
// By calling `NamedBase` here, we get the argument
11+
// to the subgenerator call as `this.name`.
12+
yeoman.generators.NamedBase.apply(this, arguments);
13+
};
14+
15+
util.inherits(PageGenerator, yeoman.generators.NamedBase);
16+
17+
PageGenerator.prototype.pagesJson = function pagesJson() {
18+
var pgs = {};
19+
var pgsPath = path.join(process.cwd(), 'pages.json');
20+
21+
if (fs.existsSync(pgsPath)) {
22+
pgs = JSON.parse(fs.readFileSync(pgsPath, 'utf-8'));
23+
initHelpers.writePagesJson.call(this, pgs);
24+
} else {
25+
initHelpers.writePagesJson.call(this, pgs);
26+
}
27+
};
28+
29+
PageGenerator.prototype.htmlSnippet = function htmlSnippet() {
30+
this.copy('index.html', 'templates/' + this.name + '.html');
31+
};

page/templates/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<p>Hello world! This is init.</p>
2+
<p>init is an HTML-framework based on HTML5 Boilerplate adding more
3+
flexibility and an automation process to it. It requires you to
4+
work with grunt, Sass, requireJS, bower. You can find more
5+
information about the usage in the documentation found in the
6+
<a href="https://github.com/use-init/init/tree/master/docs"><code>docs/</code></a>
7+
folder.</p>

0 commit comments

Comments
 (0)