|
|
@@ -68,10 +68,26 @@ ExampleStore.prototype.loadRepository = function(repoPath) {
|
|
|
ExampleStore.prototype.loadExample = function(repo, slug) {
|
|
|
const exampleConfig = require(repo.fullPath + '/' + slug + '/config.json');
|
|
|
repo.examples.push(Object.assign({ slug }, exampleConfig));
|
|
|
+ return exampleConfig;
|
|
|
};
|
|
|
|
|
|
+ExampleStore.prototype.getList = function(path) {
|
|
|
+ return _.find(this.repos, { path });
|
|
|
+}
|
|
|
+
|
|
|
+ExampleStore.prototype.getMenu = function(path) {
|
|
|
+ const self = this;
|
|
|
+ return '<ul>' + self.repos.reduce((menu, repo) => {
|
|
|
+ return '<li>'+ repo.title + '<ul>' + repo.examples.reduce((submenu, example) =>
|
|
|
+ (submenu + '<li><a href="#' + repo.path + '/' + example.slug + '">' + example.title + '</a></li>'),
|
|
|
+ '') + '</ul></li>';
|
|
|
+ }, '') + '</ul>';
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
var es = new ExampleStore(__dirname + '/exemples');
|
|
|
-es.init();
|
|
|
+es.init()
|
|
|
+.then(() => console.log(es.getMenu()));
|
|
|
|
|
|
|
|
|
function addExample(slug, title) {
|
|
|
@@ -81,7 +97,7 @@ function addExample(slug, title) {
|
|
|
|
|
|
function readConfigJson(exampleSlug) {
|
|
|
console.log(exampleSlug);
|
|
|
- return require('./exemples/' + exampleSlug + '/config.json');
|
|
|
+ return require('./exemples/jquery/' + exampleSlug + '/config.json');
|
|
|
}
|
|
|
|
|
|
function readFileAsync(file) {
|
|
|
@@ -141,6 +157,23 @@ app.get('/examples/:slug', function(req, res) {
|
|
|
.then(html => res.send(html));
|
|
|
});
|
|
|
|
|
|
+app.get('/menu', (rea, res) => {
|
|
|
+ res.send(es.getMenu());
|
|
|
+});
|
|
|
+
|
|
|
+app.get('/list/:repoPath', function(req, res) {
|
|
|
+ const { repoPath } = req.params;
|
|
|
+ const repo = es.getList(repoPath);
|
|
|
+ if(! repo) {
|
|
|
+ return res.status(404).send('Repo ' + repoPath + ' not found');
|
|
|
+ }
|
|
|
+ console.log('found repo', repo);
|
|
|
+ const data = repo.examples.map(e => (
|
|
|
+ { slug: e.slug, title: e.title }
|
|
|
+ ));
|
|
|
+ res.json(data);
|
|
|
+});
|
|
|
+
|
|
|
app.put('/examples/:slug', function(req, res) {
|
|
|
var slug = req.params.slug;
|
|
|
var existing = _.find(examples, { slug: slug });
|