|
|
@@ -11,7 +11,7 @@ var {
|
|
|
readFilesAsync
|
|
|
} = require('../lib/fsio');
|
|
|
var translator = require('../lib/translator');
|
|
|
-
|
|
|
+var passLog = require('../lib/passLog');
|
|
|
|
|
|
// One-liner for current directory, ignores .dotfiles
|
|
|
chokidar.watch('./html', {ignored: /(^|[\/\\])\../}).on('all', (event, path) => {
|
|
|
@@ -40,34 +40,33 @@ module.exports = function(exStore, exDir) {
|
|
|
// Extract repoSlug and exampleSlug from req.params
|
|
|
const { locale, params: { repoSlug, exampleSlug } } = req;
|
|
|
let repo;
|
|
|
- let example;
|
|
|
let menuExample;
|
|
|
let statusCode;
|
|
|
|
|
|
- // Initialize view data
|
|
|
+ // Initialize vie data
|
|
|
let data = {
|
|
|
menuRepo: exStore.getRepoMenu(),
|
|
|
_: translator.getAll(locale)
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
// Fetch example repository if needed
|
|
|
if(withRepo) {
|
|
|
- repo = exStore.getRepo(repoSlug);
|
|
|
- if(! repo) {
|
|
|
+ data.repo = exStore.getRepo(repoSlug);
|
|
|
+ if(! data.repo) {
|
|
|
// return res.status(404).send('Repo ' + req.params.repoSlug + ' not found');
|
|
|
data.errorMessage = translator.getOne(locale, "repoNotFound", [repoSlug]); //'Repo ' + params.repoSlug + ' not found';
|
|
|
statusCode = 404;
|
|
|
}
|
|
|
else {
|
|
|
- data.menuExample = exStore.getExampleMenu(repo.path);
|
|
|
+ data.menuExample = exStore.getExampleMenu(data.repo.path);
|
|
|
data.showControls = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Fetch example if needed
|
|
|
- if(withExample && repo) {
|
|
|
- example = _.find(repo.examples, { slug: exampleSlug });
|
|
|
- if(! example) {
|
|
|
+ if(withExample && data.repo) {
|
|
|
+ data.example = _.find(data.repo.examples, { slug: exampleSlug });
|
|
|
+ if(! data.example) {
|
|
|
// return res.status(404).send('Example ' + req.params.repoSlug + '/' + req.params.exampleSlug + ' not found');
|
|
|
data.errorMessage = translator.getOne(locale, "exampleNotFound", [repoSlug, exampleSlug]);
|
|
|
statusCode = 404;
|
|
|
@@ -79,12 +78,13 @@ module.exports = function(exStore, exDir) {
|
|
|
|
|
|
// Mustache.render(indexTpml, data);
|
|
|
return (
|
|
|
- exampleSlug && example ?
|
|
|
- readExampleFiles(repoSlug, exampleSlug, example) : Promise.resolve([])
|
|
|
+ exampleSlug && data.example ?
|
|
|
+ readExampleFiles(repoSlug, exampleSlug, data.example) : Promise.resolve([])
|
|
|
).then(files =>
|
|
|
({ files, filesJSON: JSON.stringify(files) })
|
|
|
)
|
|
|
.then(({ files, filesJSON }) => Object.assign(data, { files, filesJSON }))
|
|
|
+ .then(passLog('data before rendering, path: ' + req.path))
|
|
|
.then(data => ({
|
|
|
html: Mustache.render(indexTpml, data),
|
|
|
code: statusCode ? statusCode : 200
|