|
|
@@ -39,27 +39,31 @@ function readFileAsync(file) {
|
|
|
.then(buf => (buf.toString()));
|
|
|
}
|
|
|
|
|
|
-// function readFilesAsync(path, files) {
|
|
|
-// // console.log('reading files', files, 'from path', path);
|
|
|
-// return Promise.map(files,
|
|
|
-// f => readFileAsync(path + '/' + f)
|
|
|
-// );
|
|
|
-// }
|
|
|
-
|
|
|
-// function readExampleFiles(slug, config) {
|
|
|
-// const exampleDir = __dirname + '/exemples/' + slug;
|
|
|
-// const libsCssDir = __dirname + '/css/vendor';
|
|
|
-// const libsJsDir = __dirname + '/js/vendor';
|
|
|
-// const { html, js, css, libsCss, libsJs } = config;
|
|
|
-// return Promise.all([
|
|
|
-// readFilesAsync(exampleDir, html),
|
|
|
-// readFilesAsync(exampleDir, js),
|
|
|
-// readFilesAsync(exampleDir, css),
|
|
|
-// readFilesAsync(libsJsDir, libsJs),
|
|
|
-// readFilesAsync(libsCssDir, libsCss),
|
|
|
-// ]);
|
|
|
-// }
|
|
|
+function readFilesAsync(path, files) {
|
|
|
+ // console.log('reading files', files, 'from path', path);
|
|
|
+ return Promise.map(files,
|
|
|
+ f => readFileAsync(path + '/' + f)
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+function readExampleFiles(repoSlug, exampleSlug, config) {
|
|
|
+ const exampleDir = __dirname + '/exemples/' + repoSlug + '/' + exampleSlug;
|
|
|
+ const libsCssDir = __dirname + '/css/vendor';
|
|
|
+ const libsJsDir = __dirname + '/js/vendor';
|
|
|
+ const { html, js, css } = config; // libsCss, libsJs
|
|
|
+ return Promise.all([
|
|
|
+ readFilesAsync(exampleDir, html),
|
|
|
+ readFilesAsync(exampleDir, js),
|
|
|
+ readFilesAsync(exampleDir, css),
|
|
|
+ // readFilesAsync(libsJsDir, libsJs),
|
|
|
+ // readFilesAsync(libsCssDir, libsCss),
|
|
|
+ ]);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
+/**
|
|
|
+ * Index page: render with only repo list in menu
|
|
|
+ */
|
|
|
app.get('/', function(req, res) {
|
|
|
const menuRepo = exStore.getRepoMenu();
|
|
|
// const title = 'Home';
|
|
|
@@ -70,6 +74,9 @@ app.get('/', function(req, res) {
|
|
|
}));
|
|
|
});
|
|
|
|
|
|
+/**
|
|
|
+ * Repo page: render with repo list and selected repo's example list in menu
|
|
|
+ */
|
|
|
app.get('/:repoSlug',
|
|
|
function(req, res) {
|
|
|
const repo = exStore.getRepo(req.params.repoSlug);
|
|
|
@@ -79,7 +86,7 @@ app.get('/:repoSlug',
|
|
|
const menuRepo = exStore.getRepoMenu();
|
|
|
const menuExample = exStore.getExampleMenu(repo.path);
|
|
|
// const title = 'Home';
|
|
|
- console.log(menuRepo);
|
|
|
+ console.log(menuExample);
|
|
|
res.send(Mustache.render(indexTpml, {
|
|
|
// title,
|
|
|
menuRepo,
|
|
|
@@ -87,6 +94,36 @@ app.get('/:repoSlug',
|
|
|
}));
|
|
|
});
|
|
|
|
|
|
+/**
|
|
|
+ * Example page: render with repo list and selected repo's example list in menu,
|
|
|
+ * and the editor with the selected example
|
|
|
+ */
|
|
|
+app.get('/:repoSlug/:exampleSlug',
|
|
|
+ function(req, res) {
|
|
|
+ const repo = exStore.getRepo(req.params.repoSlug);
|
|
|
+ if(! repo) {
|
|
|
+ return res.status(404).send('Repo ' + req.params.repoSlug + ' not found');
|
|
|
+ }
|
|
|
+ const menuRepo = exStore.getRepoMenu();
|
|
|
+ const menuExample = exStore.getExampleMenu(repo.path);
|
|
|
+ const example = _.find(repo.examples, { slug: req.params.exampleSlug });
|
|
|
+ if(! example) {
|
|
|
+ return res.status(404).send('Example ' + req.params.repoSlug + '/' + req.params.exampleSlug + ' not found');
|
|
|
+ }
|
|
|
+ // const title = 'Home';
|
|
|
+ console.log(menuExample);
|
|
|
+ const { repoSlug, exampleSlug } = req.params;
|
|
|
+ readExampleFiles(repoSlug, exampleSlug, example)
|
|
|
+ .then(([ html, js, css ]) => {
|
|
|
+ console.log('example files', html, js, css);
|
|
|
+ res.send(Mustache.render(indexTpml, {
|
|
|
+ // title,
|
|
|
+ menuRepo,
|
|
|
+ menuExample
|
|
|
+ }));
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
app.post('/examples', function(req, res) {
|
|
|
var title = req.body.title;
|
|
|
if(! req.body.title) {
|