Sfoglia il codice sorgente

Give examples their own layout so they can share more logic

Kevin van Zonneveld 9 anni fa
parent
commit
144af8d9ff

+ 1 - 1
website/src/examples/cdn/html/app.html

@@ -4,6 +4,6 @@
 var uppy = new Uppy.Core();
 var uppy = new Uppy.Core();
 uppy.use(Uppy.plugins.Tus10);
 uppy.use(Uppy.plugins.Tus10);
 
 
-console.log(Uppy);
+console.log(uppy.type);
 console.log('Uppy loaded from CDN with a tus 1.0 plugin');
 console.log('Uppy loaded from CDN with a tus 1.0 plugin');
 </script>
 </script>

+ 12 - 3
website/src/examples/cdn/index.ejs

@@ -1,5 +1,6 @@
 ---
 ---
 title: CDN
 title: CDN
+layout: example
 type: examples
 type: examples
 order: 0
 order: 0
 ---
 ---
@@ -9,22 +10,30 @@ CDN
 {% endblockquote %}
 {% endblockquote %}
 
 
 <p>
 <p>
-This example showcases sourcing an UMD dist build straight from a CDN.
+  This example showcases sourcing an UMD dist build straight from a CDN.
 </p>
 </p>
 
 
+<!-- <link rel="stylesheet" href="css/app.css"> -->
 <% include html/app.html %>
 <% include html/app.html %>
 <script src="js/app.js"></script>
 <script src="js/app.js"></script>
 
 
 <hr />
 <hr />
 
 
+<p id="console-wrapper">
+  Console output: <br />
+</p>
+
 <p>
 <p>
   On this page we're using the following HTML snippet:
   On this page we're using the following HTML snippet:
 </p>
 </p>
-
 {% include_code lang:html cdn/html/app.html %}
 {% include_code lang:html cdn/html/app.html %}
 
 
 <p>
 <p>
   Along with this JavaScript:
   Along with this JavaScript:
 </p>
 </p>
-
 {% include_code lang:js cdn/js/app.es6 %}
 {% include_code lang:js cdn/js/app.es6 %}
+
+<!-- <p>
+  And the following CSS:
+</p>
+{% include_code lang:css cdn/css/app.css %} -->

+ 0 - 0
website/src/examples/cdn/static/js/app.js


+ 6 - 4
website/src/examples/dragdrop/index.ejs

@@ -1,5 +1,6 @@
 ---
 ---
 title: Drag and Drop
 title: Drag and Drop
+layout: example
 type: examples
 type: examples
 order: 2
 order: 2
 ---
 ---
@@ -9,7 +10,7 @@ Drag &amp; Drop
 {% endblockquote %}
 {% endblockquote %}
 
 
 <p>
 <p>
-Here you'll see a demo of how you might set up Drag and Drop with Uppy:
+  Here you'll see a demo of how you might set up Drag and Drop with Uppy:
 </p>
 </p>
 
 
 <link rel="stylesheet" href="css/app.css">
 <link rel="stylesheet" href="css/app.css">
@@ -18,20 +19,21 @@ Here you'll see a demo of how you might set up Drag and Drop with Uppy:
 
 
 <hr />
 <hr />
 
 
+<p id="console-wrapper">
+  Console output: <br />
+</p>
+
 <p>
 <p>
   On this page we're using the following HTML snippet:
   On this page we're using the following HTML snippet:
 </p>
 </p>
-
 {% include_code lang:html dragdrop/html/app.html %}
 {% include_code lang:html dragdrop/html/app.html %}
 
 
 <p>
 <p>
   Along with this JavaScript:
   Along with this JavaScript:
 </p>
 </p>
-
 {% include_code lang:js dragdrop/js/app.es6 %}
 {% include_code lang:js dragdrop/js/app.es6 %}
 
 
 <p>
 <p>
   And the following CSS:
   And the following CSS:
 </p>
 </p>
-
 {% include_code lang:css dragdrop/css/app.css %}
 {% include_code lang:css dragdrop/css/app.css %}

+ 2 - 2
website/src/examples/dragdrop/js/app.es6

@@ -1,5 +1,3 @@
-console.log('a');
-
 import Uppy from 'uppy/core';
 import Uppy from 'uppy/core';
 import { DragDrop, Tus10 } from 'uppy/plugins';
 import { DragDrop, Tus10 } from 'uppy/plugins';
 
 
@@ -8,3 +6,5 @@ const files = uppy
   .use(DragDrop, {selector: '#upload-target'})
   .use(DragDrop, {selector: '#upload-target'})
   .use(Tus10, {endpoint: 'http://master.tus.io:8080'})
   .use(Tus10, {endpoint: 'http://master.tus.io:8080'})
   .run();
   .run();
+
+console.log(uppy.type);

+ 0 - 0
website/src/examples/dragdrop/static/js/app.js


+ 6 - 4
website/src/examples/dropbox/index.ejs

@@ -1,5 +1,6 @@
 ---
 ---
 title: Dropbox
 title: Dropbox
+layout: example
 type: examples
 type: examples
 order: 1
 order: 1
 ---
 ---
@@ -9,7 +10,7 @@ Dropbox
 {% endblockquote %}
 {% endblockquote %}
 
 
 <p>
 <p>
-Here you'll see a demo of how you might set up Dropbox with Uppy:
+  Here you'll see a demo of how you might set up Dropbox with Uppy:
 </p>
 </p>
 
 
 <link rel="stylesheet" href="css/app.css">
 <link rel="stylesheet" href="css/app.css">
@@ -18,20 +19,21 @@ Here you'll see a demo of how you might set up Dropbox with Uppy:
 
 
 <hr />
 <hr />
 
 
+<p id="console-wrapper">
+  Console output: <br />
+</p>
+
 <p>
 <p>
   On this page we're using the following HTML snippet:
   On this page we're using the following HTML snippet:
 </p>
 </p>
-
 {% include_code lang:html dropbox/html/app.html %}
 {% include_code lang:html dropbox/html/app.html %}
 
 
 <p>
 <p>
   Along with this JavaScript:
   Along with this JavaScript:
 </p>
 </p>
-
 {% include_code lang:js dropbox/js/app.es6 %}
 {% include_code lang:js dropbox/js/app.es6 %}
 
 
 <p>
 <p>
   And the following CSS:
   And the following CSS:
 </p>
 </p>
-
 {% include_code lang:css dropbox/css/app.css %}
 {% include_code lang:css dropbox/css/app.css %}

+ 9 - 2
website/src/examples/dropbox/js/app.es6

@@ -1,3 +1,10 @@
-import { DropboxPlugin } from 'uppy/plugins';
+import Uppy from 'uppy/core';
+import { Dropbox, Tus10 } from 'uppy/plugins';
 
 
-console.log(DropboxPlugin);
+const uppy = new Uppy({wait: false});
+const files = uppy
+  .use(Dropbox, {selector: '#upload-target'})
+  .use(Tus10, {endpoint: 'http://master.tus.io:8080'})
+  .run();
+
+console.log(uppy.type);

+ 0 - 0
website/src/examples/dropbox/static/js/app.js


+ 33 - 0
website/themes/uppy/layout/example.ejs

@@ -0,0 +1,33 @@
+<%- partial('partials/sidebar', { type: page.type, index: page.index }) %>
+<div class="content <%- page.type ? page.type + ' with-sidebar' : '' %>">
+  <h1><%- page.title %> Example</h1>
+
+  <!--
+  Add textarea already so it's available immediately for logging.
+  It is later made visible, and moved into the #console-wrapper to position it in layout how
+  you see fit.
+  -->
+  <textarea id="console-log"></textarea>
+  <script>
+  console.log = (function (old_function, div_log) {
+    return function (text) {
+      old_function(text);
+      div_log.value = text + "\n" + div_log.value;
+    };
+  } (console.log.bind(console), document.getElementById("console-log")));
+  </script>
+
+  <%- page.content %>
+
+  <script>
+    // #console-log textarea is declared earlier so it's available immediately for logging.
+    // Here it is made visible, and moved into the #console-wrapper, so you can position it in the layout how
+    // you see fit.
+    document.getElementById('console-wrapper').appendChild(document.getElementById('console-log'));
+    document.getElementById('console-log').style.display = 'block';
+  </script>
+
+  <div class="footer">Caught a mistake or want to contribute to the documentation?
+     <a href="https://github.com/transloadit/uppy/blob/master/website/src/<%- page.source %>" target="_blank">Edit/fork this page directly on Github</a>!
+  </div>
+</div>

+ 1 - 1
website/themes/uppy/layout/page.ejs

@@ -2,7 +2,7 @@
     <%- partial('partials/sidebar', { type: page.type, index: page.index }) %>
     <%- partial('partials/sidebar', { type: page.type, index: page.index }) %>
 <% } %>
 <% } %>
 <div class="content <%- page.type ? page.type + ' with-sidebar' : '' %>">
 <div class="content <%- page.type ? page.type + ' with-sidebar' : '' %>">
-    <h1><%- page.title %><%- page.type === 'examples' ? ' Example' : '' %></h1>
+    <h1><%- page.title %></h1>
     <%- page.content %>
     <%- page.content %>
     <% if (page.type === 'guide') { %>
     <% if (page.type === 'guide') { %>
       <div class="guide-links">
       <div class="guide-links">