Selaa lähdekoodia

Per-repo example menu

Benoît Hubert 8 vuotta sitten
vanhempi
commit
459a720877

+ 3 - 0
exemples/javascript/repo-config.json

@@ -0,0 +1,3 @@
+{
+  "title": "JavaScript"
+}

+ 9 - 0
exemples/javascript/tableaux-boucles/config.json

@@ -0,0 +1,9 @@
+{
+  "title": "Tableaux - Boucles",
+  "category": "array",
+  "html": [ "example.html" ],
+  "js": [ "script.js" ],
+  "css": [],
+  "libsJs": [],
+  "libsCss": [ "styles.css" ]
+}

+ 0 - 0
exemples/javascript/tableaux-boucles/example.html


+ 2 - 0
exemples/javascript/tableaux-boucles/script.js

@@ -0,0 +1,2 @@
+var suiteFibonacci = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89];
+console.log(suiteFibonacci);

+ 2 - 2
html/index.mustache.html

@@ -24,8 +24,8 @@
                   <li><a href="{{slug}}">{{title}}</a></li>{{/menuRepo}}
                 </ul>
 
-                <ul id="menu-repo" class="nav-menu">{{#menuRepo}}
-                  <li><a href="{{slug}}">{{title}}</a></li>{{/menuRepo}}
+                <ul id="menu-repo" class="nav-menu">{{#menuExample}}
+                  <li><a href="{{slug}}">{{title}}</a></li>{{/menuExample}}
                 </ul>
             </div>
 

+ 3 - 3
lib/ExampleStore.js

@@ -51,7 +51,7 @@ ExampleStore.prototype.getRepoMenu = function(path) {
 ExampleStore.prototype.getExampleMenu = function(path) {
   const repo = _.find(this.repos, { path });
   return repo.examples.map(
-    ({ title, slug }) => ({ title, href: repo.path + '/' + slug }) 
+    ({ title, slug }) => ({ title, slug: repo.path + '/' + slug }) 
   );
 };
 
@@ -64,8 +64,8 @@ ExampleStore.prototype.getMenu = function(path) {
   }, '') + '</ul>';
 }
 
-ExampleStore.prototype.repoExists = function(path) {
-  return _.find(this.repos, { path }) !== undefined;
+ExampleStore.prototype.getRepo = function(path) {
+  return _.find(this.repos, { path });
 }
 
 module.exports = ExampleStore;

+ 6 - 8
sandboxApp.js

@@ -71,21 +71,19 @@ app.get('/', function(req, res) {
 });
 
 app.get('/:repoSlug',
-  function(req, res, next) {
-    if(! exStore.repoExists(req.params.repoSlug)) {
+  function(req, res) {
+    const repo = exStore.getRepo(req.params.repoSlug);
+    if(! repo) {
       return res.status(404).send('Repo ' + req.params.repoSlug + ' not found');
     }
-    next();
-  },
-  function(req, res) {
-    const menuRepo = exStore.getRepoMenu();
     const menuRepo = exStore.getRepoMenu();
+    const menuExample = exStore.getExampleMenu(repo.path);
     // const title    = 'Home';
     console.log(menuRepo);
     res.send(Mustache.render(indexTpml, {
-      title,
+      // title,
       menuRepo,
-    menuRepo
+      menuExample
     }));
 });