Bläddra i källkod

Add new example to the menu

Benoît Hubert 8 år sedan
förälder
incheckning
7e81720421
5 ändrade filer med 11 tillägg och 10 borttagningar
  1. 1 1
      html/index.mustache.html
  2. 5 3
      js/editor.js
  3. 0 1
      js/req-promise.js
  4. 1 1
      lib/ExampleStore.js
  5. 4 4
      sandboxApp.js

+ 1 - 1
html/index.mustache.html

@@ -36,7 +36,7 @@
             <div id="menu-example" class="pure-g nav-menu">{{#menuExample}}
               <div class="pure-u-1 pure-u-md-1-2">
               <span class="cat-title">{{category.title}}</span>
-              <ul>{{#examples}}
+              <ul id="cat-{{category.slug}}">{{#examples}}
               <li><a href="/{{{slug}}}">{{title}}</a></li>{{/examples}}</ul>
             </div>{{/menuExample}}</div>
         </div>

+ 5 - 3
js/editor.js

@@ -275,10 +275,12 @@ $(document).ready(function() {
     var repoSlug = $detailsRepo.data('slug');
     var title = $(this).find('input[name="title"]').val();
     rp.post('/' + repoSlug + '/examples', { title: title })
-    .then(function(newExample) {
+    .then(function(example) {
       clearAndCloseEditor();
-      // $fileSelect.append(makeFileSelectOption(newExample));
-      // $fileSelect.val(newExample.slug);
+      // $fileSelect.append(makeFileSelectOption(example));
+      // $fileSelect.val(example.slug);
+      var $exMenuItem = $('<li><a href="/' + repoSlug + example.slug + '">' + example.title + '</a></li>')
+      .appendTo( $('#cat-' + example.category) );
       notify('success', "Exemple créé !");
     })
     .catch(errText => notify('error', 'Erreur: ' + errText));

+ 0 - 1
js/req-promise.js

@@ -38,7 +38,6 @@
           reject(new Error(jqXHR.responseText));
         }
       });
-    console.log(options)
       $.ajax(options);
     });
   }

+ 1 - 1
lib/ExampleStore.js

@@ -53,7 +53,7 @@ ExampleStore.prototype.getExampleMenu = function(path) {
     console.error('Repo ' + repo.title + 'has no categories key');
     return [];
   }
-  // console.log('repo examples', repo.examples)
+  console.log('getExampleMenu repo examples', repo.examples)
   const menu = repo.categories.map(category => {
     const examplesInCat = repo.examples.filter(ex => (ex.category === category.slug));
     // console.log('examples in cat', category, examplesInCat);

+ 4 - 4
sandboxApp.js

@@ -119,16 +119,16 @@ app.post('/:repoSlug/examples', function(req, res) {
   // Prepare files to write
   var targetDir = __dirname + '/exemples/' + repoSlug + '/' + exampleSlug;
   var files = mapObjToArray({
-    'contenu.html': '',
-    'script.js': '',
+    'contenu.html': '<!-- ' + title + '-->\n',
+    'script.js': '// ' + title,
     'config.json': beautify(config, null, 2, 100)
   }, 'file', 'content');
   fs.mkdirAsync(targetDir)
   .then(() => Promise.map(
     files, ({ file, content }) => fs.writeFileAsync(targetDir + '/' + file, content)
   ))
-  .then(files => repo.examples.push({ slug: slug, title: title }))
-  .then(() => res.json({ slug: exampleSlug, title: title }));
+  .then(files => repo.examples.push(config))
+  .then(() => res.json(config));
 });
 
 app.get('/examples/:slug', function(req, res) {