Skip to content

Commit

Permalink
Auto-generate examples from template rather than edit them individually.
Browse files Browse the repository at this point in the history
  • Loading branch information
STRML committed Jan 2, 2015
1 parent f88437e commit 9cda249
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 72 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ js:
./node_modules/.bin/6to5 --experimental ./lib --out-dir ./build
rename 's/jsx$$/js/' ./build/*

html:
node ./examples/generate.js

check-build:
bash check-build.sh
17 changes: 9 additions & 8 deletions examples/1-basic.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!--
Do not edit this file! It is generated by `generate.js` in this folder, from `template.ejs` and vars.js.
-->
<html>
<head>
<script src="http://localhost:4002/dist/commons.js"></script>
Expand All @@ -6,16 +9,14 @@
</head>
<body>
<h3>React-Grid-Layout Demo 1 - Basic</h3>
<p>Try dragging the elements around.</p>
<p>React-Grid-Layout is the only grid layout system for React. It features auto-packing, resizable widgets,
a fluid layout, and separate layouts per responsive breakpoint.</p>
<p>Resize the window to try it out!</p>

<ul>
<p>Try dragging the elements around.</p>
<p>This is a basic, non-responsive layout with dragging and resizing. Usage is very simple.</p>
<ul>
<li><a href="https://github.com/STRML/react-grid-layout">View project on GitHub</a></li>
<li><a href="https://github.com/STRML/react-grid-layout/blob/master/test/examples/1-basic.jsx">View this example's source</a></li>
<li><a href="2-no-dragging.html">View the next example: "No Dragging"</a></li>
</ul>

<li><a href="2-no-dragging.html">View the next example: "No Dragging"</a></li>
</ul>
<div id="content"></div>
</body>
</html>
14 changes: 8 additions & 6 deletions examples/2-no-dragging.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!--
Do not edit this file! It is generated by `generate.js` in this folder, from `template.ejs` and vars.js.
-->
<html>
<head>
<script src="http://localhost:4002/dist/commons.js"></script>
Expand All @@ -6,14 +9,13 @@
</head>
<body>
<h3>React-Grid-Layout Demo 2 - No Dragging</h3>
<p>This particular example has dragging and resizing turned off.</p>
<p>Responsive layouts are still enabled. See the source for more details.</p>

<ul>
<p>This particular example has dragging and resizing turned off.</p>
<ul>
<li><a href="https://github.com/STRML/react-grid-layout">View project on GitHub</a></li>
<li><a href="https://github.com/STRML/react-grid-layout/blob/master/test/examples/2-no-dragging.jsx">View this example's source</a></li>
<li><a href="3-messy.html">View the next example: "Messy Layout"</a></li>
</ul>

<li><a href="3-messy.html">View the next example: "Messy"</a></li>
</ul>
<div id="content"></div>
</body>
</html>
33 changes: 14 additions & 19 deletions examples/3-messy.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
<!--
Do not edit this file! It is generated by `generate.js` in this folder, from `template.ejs` and vars.js.
-->
<html>
<head>
<script src="http://localhost:4002/dist/commons.js"></script>
<script src="http://localhost:4002/dist/3-messy.bundle.js"></script>
<title>RGL Example 3 - Messy</title>
<script src="http://localhost:4002/dist/commons.js"></script>
<script src="http://localhost:4002/dist/3-messy.bundle.js"></script>
<title>RGL Example 3 - Messy</title>
</head>
<body>
<h3>React-Grid-Layout Demo 3 - Messy Layout</h3>
<p>This demo shows what happens when elements are placed randomly all over the layout.</p>
<p>
RGL does not auto-pack in the same fashion as other projects, such as jQuery Masonry. Packing is only done
in the vertical dimension. If objects all have the same width, they will be packed efficiently.
</p>
<p>
If a layout is fed to RGL that has items with incorrect dimensions (width too big, overlapping other elements,
out of bounds, etc), they will be automatically corrected on startup. See the
<a href="https://github.com/STRML/react-grid-layout/blob/master/test/TestLayout.jsx#L37">source of this demo</a>,
where elements are placed randomly in the layout.
</p>

<ul>
<h3>React-Grid-Layout Demo 3 - Messy</h3>
<p>This demo shows what happens when elements are placed randomly all over the layout.</p>
<p>RGL does not auto-pack in the same fashion as other projects, such as jQuery Masonry. Packing is only done in the vertical dimension. If objects all have the same width, they will be packed efficiently.</p>
<p>If a layout is fed to RGL that has items with incorrect dimensions (width too big, overlapping other elements, out of bounds, etc), they will be automatically corrected on startup. See the source of this demo, where elements are placed randomly in the layout.</p>
<ul>
<li><a href="https://github.com/STRML/react-grid-layout">View project on GitHub</a></li>
<li><a href="https://github.com/STRML/react-grid-layout/blob/master/test/examples/3-messy.jsx">View this example's source</a></li>
<li><a href="4-grid-property.html">View the next example: "Grid Item Properties"</a></li>
</ul>

<li><a href="4-grid-property.html">View the next example: "Grid Item Properties"</a></li>
</ul>
<div id="content"></div>
</body>
</html>
14 changes: 8 additions & 6 deletions examples/4-grid-property.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!--
Do not edit this file! It is generated by `generate.js` in this folder, from `template.ejs` and vars.js.
-->
<html>
<head>
<script src="http://localhost:4002/dist/commons.js"></script>
Expand All @@ -6,14 +9,13 @@
</head>
<body>
<h3>React-Grid-Layout Demo 4 - Grid Item Properties</h3>
<p>This demo uses a layout assigned on the grid items themselves as the <code>_grid</code> property.</p>

<ul>
<p>This demo uses a layout assigned on the grid items themselves as the <code>_grid</code> property.</p>
<ul>
<li><a href="https://github.com/STRML/react-grid-layout">View project on GitHub</a></li>
<li><a href="https://github.com/STRML/react-grid-layout/blob/master/test/examples/4-grid-property.jsx">View this example's source</a></li>
<li><a href="5-static-elements.html">View the next example: "Static Elements"</a></li>
</ul>


<li><a href="5-static-elements.html">View the next example: "Static Elements"</a></li>
</ul>
<div id="content"></div>
</body>
</html>
15 changes: 8 additions & 7 deletions examples/5-static-elements.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!--
Do not edit this file! It is generated by `generate.js` in this folder, from `template.ejs` and vars.js.
-->
<html>
<head>
<script src="http://localhost:4002/dist/commons.js"></script>
Expand All @@ -6,15 +9,13 @@
</head>
<body>
<h3>React-Grid-Layout Demo 5 - Static Elements</h3>
<p>This demo sets an item to <code>static</code>. Static elements cannot be moved or resized. Other elements
move themselves around a static element.</p>

<ul>
<p>This demo sets an item to <code>static</code>. Static elements cannot be moved or resized. Other elements move themselves around a static element.</p>
<ul>
<li><a href="https://github.com/STRML/react-grid-layout">View project on GitHub</a></li>
<li><a href="https://github.com/STRML/react-grid-layout/blob/master/test/examples/5-static-elements.jsx">View this example's source</a></li>
<li><a href="6-dynamic-add-remove.html">View the next example: "Dynamic Add/Remove"</a></li>
</ul>


<li><a href="6-dynamic-add-remove.html">View the next example: "Dynamic Add/Remove"</a></li>
</ul>
<div id="content"></div>
</body>
</html>
16 changes: 9 additions & 7 deletions examples/6-dynamic-add-remove.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!--
Do not edit this file! It is generated by `generate.js` in this folder, from `template.ejs` and vars.js.
-->
<html>
<head>
<script src="http://localhost:4002/dist/commons.js"></script>
Expand All @@ -6,15 +9,14 @@
</head>
<body>
<h3>React-Grid-Layout Demo 6 - Dynamic Add/Remove</h3>
<p>This demo shows what happens when items are dynamically added and removed.</p>
<p>You can remove an item by clicking its 'x', and add a new one with the button.</p>

<ul>
<p>This demo shows what happens when items are dynamically added and removed.</p>
<p>You can remove an item by clicking its "x", and add a new one with the button.</p>
<ul>
<li><a href="https://github.com/STRML/react-grid-layout">View project on GitHub</a></li>
<li><a href="https://github.com/STRML/react-grid-layout/blob/master/test/examples/6-dynamic-add-remove.jsx">View this example's source</a></li>
<li><a href="7-localstorage.html">View the next example: "LocalStorage"</a></li>
</ul>


<li><a href="7-localstorage.html">View the next example: "LocalStorage"</a></li>
</ul>
<div id="content"></div>
</body>
</html>
16 changes: 9 additions & 7 deletions examples/7-localstorage.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!--
Do not edit this file! It is generated by `generate.js` in this folder, from `template.ejs` and vars.js.
-->
<html>
<head>
<script src="http://localhost:4002/dist/commons.js"></script>
Expand All @@ -6,15 +9,14 @@
</head>
<body>
<h3>React-Grid-Layout Demo 7 - LocalStorage</h3>
<p>This simple demo synchronizes to localStorage.</p>
<p>Try moving and resizing elements, then reloading.</p>

<ul>
<p>This simple demo synchronizes to localStorage.</p>
<p>Try moving and resizing elements, then reloading.</p>
<ul>
<li><a href="https://github.com/STRML/react-grid-layout">View project on GitHub</a></li>
<li><a href="https://github.com/STRML/react-grid-layout/blob/master/test/examples/7-localstorage.jsx">View this example's source</a></li>
<li><a href="8-localstorage-responsive.html">View the next example: "Responsive w/LocalStorage"</a></li>
</ul>


<li><a href="8-localstorage-responsive.html">View the next example: "Responsive with LocalStorage"</a></li>
</ul>
<div id="content"></div>
</body>
</html>
23 changes: 11 additions & 12 deletions examples/8-localstorage-responsive.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<!--
Do not edit this file! It is generated by `generate.js` in this folder, from `template.ejs` and vars.js.
-->
<html>
<head>
<script src="http://localhost:4002/dist/commons.js"></script>
<script src="http://localhost:4002/dist/7-localstorage.bundle.js"></script>
<title>RGL Example 8 - Responsive w/LocalStorage</title>
<script src="http://localhost:4002/dist/8-localstorage-responsive.bundle.js"></script>
<title>RGL Example 8 - Responsive with LocalStorage</title>
</head>
<body>
<h3>React-Grid-Layout Demo 8 - Responsive w/LocalStorage</h3>
<p>This simple demo synchronizes to localStorage for each responsive breakpoint.</p>
<p>Try moving and resizing elements, changing window width, moving some more, and refreshing.</p>
<p>Each breakpoint has a separate layout. The <code>onLayoutChange</code> callback calls back with
a hash of breakpoints to layouts, which is then synchronized to localStorage.</p>

<ul>
<h3>React-Grid-Layout Demo 8 - Responsive with LocalStorage</h3>
<p>This simple demo synchronizes to localStorage for each responsive breakpoint.</p>
<p>Try moving and resizing elements, changing window width, moving some more, and refreshing.</p>
<p>Each breakpoint has a separate layout. The <code>onLayoutChange</code> callback calls back with a hash of breakpoints to layouts, which is then synchronized to localStorage.</p>
<ul>
<li><a href="https://github.com/STRML/react-grid-layout">View project on GitHub</a></li>
<li><a href="https://github.com/STRML/react-grid-layout/blob/master/test/examples/8-localstorage-responsive.jsx">View this example's source</a></li>
<!-- <li><a href="2-no-dragging.html">View the next example</a></li> -->
</ul>

</ul>
<div id="content"></div>
</body>
</html>
18 changes: 18 additions & 0 deletions examples/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
var fs = require('fs');
var ejs = require('ejs');
var data = require('./vars');
var tpl = fs.readFileSync(__dirname + '/template.ejs').toString();

var base = 'http://localhost:4002';
var banner = 'Do not edit this file! It is generated by `generate.js` in this folder, from `template.ejs` and ' +
'vars.js.';

data.forEach(function(datum, i) {
datum.base = base;
datum.index = i;
datum.banner = banner;
datum.next = data[i + 1];
var html = ejs.render(tpl, datum);
fs.writeFileSync(__dirname + '/' + i + '-' + datum.source + '.html', html);
});
24 changes: 24 additions & 0 deletions examples/template.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
<%= banner %>
-->
<html>
<head>
<script src="<%= base %>/dist/commons.js"></script>
<script src="<%= base %>/dist/<%= index %>-<%= source %>.bundle.js"></script>
<title>RGL Example <%= index %> - <%= title %></title>
</head>
<body>
<h3>React-Grid-Layout Demo <%= index %> - <%= title %></h3>
<% for(var i = 0; i < paragraphs.length; i++) { -%>
<p><%- paragraphs[i] %></p>
<% } -%>
<ul>
<li><a href="https://github.com/STRML/react-grid-layout">View project on GitHub</a></li>
<li><a href="https://github.com/STRML/react-grid-layout/blob/master/test/examples/<%= index %>-<%= source %>.jsx">View this example's source</a></li>
<% if (next) { %>
<li><a href="<%= index + 1 %>-<%= next.source %>.html">View the next example: "<%= next.title %>"</a></li>
<% } -%>
</ul>
<div id="content"></div>
</body>
</html>
82 changes: 82 additions & 0 deletions examples/vars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
'use strict';

module.exports = [
{
title: 'Showcase',
source: 'showcase',
paragraphs: [
'Try dragging the elements around.',
'React-Grid-Layout is the only grid layout system for React. It features auto-packing, resizable widgets, ' +
'a fluid layout, and separate layouts per responsive breakpoint.',
'Resize the window to try it out!'
]
},
{
title: 'Basic',
source: 'basic',
paragraphs: [
'Try dragging the elements around.',
'This is a basic, non-responsive layout with dragging and resizing. Usage is very simple.'
]
},
{
title: 'No Dragging',
source: 'no-dragging',
paragraphs: [
'This particular example has dragging and resizing turned off.'
]
},
{
title: 'Messy',
source: 'messy',
paragraphs: [
'This demo shows what happens when elements are placed randomly all over the layout.',
'RGL does not auto-pack in the same fashion as other projects, such as jQuery Masonry. Packing is only done ' +
'in the vertical dimension. If objects all have the same width, they will be packed efficiently.',
'If a layout is fed to RGL that has items with incorrect dimensions (width too big, overlapping other elements, ' +
'out of bounds, etc), they will be automatically corrected on startup. See the ' +
'source of this demo, where elements are placed randomly in the layout.'
]
},
{
title: 'Grid Item Properties',
source: 'grid-property',
paragraphs: [
'This demo uses a layout assigned on the grid items themselves as the <code>_grid</code> property.',
]
},
{
title: 'Static Elements',
source: 'static-elements',
paragraphs: [
'This demo sets an item to <code>static</code>. Static elements cannot be moved or resized. Other elements ' +
'move themselves around a static element.'
]
},
{
title: 'Dynamic Add/Remove',
source: 'dynamic-add-remove',
paragraphs: [
'This demo shows what happens when items are dynamically added and removed.',
'You can remove an item by clicking its "x", and add a new one with the button.'
]
},
{
title: 'LocalStorage',
source: 'localstorage',
paragraphs: [
'This simple demo synchronizes to localStorage.',
'Try moving and resizing elements, then reloading.'
]
},
{
title: 'Responsive with LocalStorage',
source: 'localstorage-responsive',
paragraphs: [
'This simple demo synchronizes to localStorage for each responsive breakpoint.',
'Try moving and resizing elements, changing window width, moving some more, and refreshing.',
'Each breakpoint has a separate layout. The <code>onLayoutChange</code> callback calls back with ' +
'a hash of breakpoints to layouts, which is then synchronized to localStorage.'
]
},
];

0 comments on commit 9cda249

Please sign in to comment.