Skip to content

Commit

Permalink
Examples: move diagram to top of example
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Jun 9, 2015
1 parent 9d0e55d commit fe3edd8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 39 deletions.
85 changes: 47 additions & 38 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module.exports = function(grunt) {

entry.examples.forEach(function(example) {
var markdown, filepath, eg, md, inMarkdown,
images, breadboards, embeds, name, imgMarkdown, values;
images, breadboards, embeds, name, imgMarkdown, values, primary;

markdown = [];
filepath = "eg/" + example.file;
Expand Down Expand Up @@ -232,6 +232,8 @@ module.exports = function(grunt) {
// We'll combine markdown for images and breadboards
imgMarkdown = "";

primary = breadboards.shift();

images.forEach(function(img) {
if (!img.title || !img.file) {
grunt.fail.fatal("Invalid image: title and file required");
Expand All @@ -248,52 +250,24 @@ module.exports = function(grunt) {
});

breadboards.forEach(function(breadboard) {

if (!breadboard.name) {
grunt.fail.fatal("Invalid breadboard: name required");
}

if (!breadboard.title) {
grunt.fail.fatal("Invalid breadboard (" + breadboard.name + "): title required");
}

breadboard.png = "docs/breadboard/" + breadboard.name + ".png";
breadboard.fzz = "docs/breadboard/" + breadboard.name + ".fzz";

breadboard.hasPng = fs.existsSync(breadboard.png);
breadboard.hasFzz = fs.existsSync(breadboard.fzz);

if (!breadboard.hasPng) {
if (breadboard.auto) {
// i.e. we tried to guess at a name but still doesn't exist
// We can just ignore and no breadboard shown
return;
} else {
// A breadboard was specified but doesn't exist - error
grunt.fail.fatal("Specified breadboard doesn't exist: " + breadboard.png);
}
}

// FZZ is optional, but we'll warn at verbose
if (!breadboard.hasFzz) {
verbose.writeln("Missing FZZ: " + breadboard.fzz);
}

imgMarkdown += templates.breadboard({ breadboard: breadboard });
imgMarkdown += breadboardMarkdown(breadboard);
});

values = {
title: example.title,
description: example.description,
command: "node " + filepath,
description: example.description,
embeds: embeds,
example: eg,
externals: example.externals || [],
file: md,
markdown: markdown,
images: imgMarkdown,
embeds: embeds,
externals: example.externals || []
markdown: markdown,
primary: primary ? breadboardMarkdown(primary) : "",
title: example.title,
};

breadboardMarkdown

// Write the file to /docs/*
file.write(md, templates.eg(values));

Expand All @@ -313,6 +287,41 @@ module.exports = function(grunt) {
log.writeln("Examples created.");
});


function breadboardMarkdown(breadboard) {
if (!breadboard.name) {
grunt.fail.fatal("Invalid breadboard: name required");
}

if (!breadboard.title) {
grunt.fail.fatal("Invalid breadboard (" + breadboard.name + "): title required");
}

breadboard.png = "docs/breadboard/" + breadboard.name + ".png";
breadboard.fzz = "docs/breadboard/" + breadboard.name + ".fzz";

breadboard.hasPng = fs.existsSync(breadboard.png);
breadboard.hasFzz = fs.existsSync(breadboard.fzz);

if (!breadboard.hasPng) {
if (breadboard.auto) {
// i.e. we tried to guess at a name but still doesn't exist
// We can just ignore and no breadboard shown
return;
} else {
// A breadboard was specified but doesn't exist - error
grunt.fail.fatal("Specified breadboard doesn't exist: " + breadboard.png);
}
}

// FZZ is optional, but we'll warn at verbose
if (!breadboard.hasFzz) {
verbose.writeln("Missing FZZ: " + breadboard.fzz);
}

return templates.breadboard({ breadboard: breadboard });
}

// run the examples task and fail if there are uncommitted changes to the docs directory
task.registerTask("test-examples", "Guard against out of date examples", ["examples", "fail-if-uncommitted-examples"]);

Expand Down
4 changes: 4 additions & 0 deletions tpl/.eg.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<%= description %>
<% } %>

<% if (primary) { %>
<%= primary %>
<% } %>

Run with:
```bash
<%= command %>
Expand Down
15 changes: 14 additions & 1 deletion tpl/programs.json
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,20 @@
},
{
"file": "kinect-arm-controller.js",
"title": "Kinect Arm Controller"
"title": "Kinect Robotic Arm Controller",
"images": [
{"file": "robotic-arm.jpg", "title": "Robotic Arm", "description": "Assembled Robotic Arm from LynxMotion"},
{"file": "arm-diagram.jpg", "title": "Arm Diagram", "description": "Illustrates arm joint connections."}
],
"embeds": [
{ "name": "kinect-arm-controller",
"src": "https://www.youtube.com/embed/VCjbUJzYYvI",
"type": "youtube" }
],
"externals": [
{ "title": "JavaScript: Kinect Controlled Robot Arm", "href": "http://bocoup.com/weblog/javascript-arduino-kinect-robot-arm/"},
{ "title": "LynxMotion: AL5D Robotic Arm", "href": "http://www.lynxmotion.com/c-130-al5d.aspx"}
]
},
{
"file": "laser-trip-wire.js",
Expand Down

0 comments on commit fe3edd8

Please sign in to comment.