From 9338217743681a556f8473b4a4de2fd885bb02d2 Mon Sep 17 00:00:00 2001
From: Jordan Scales
Date: Tue, 21 Apr 2020 13:41:54 -0400
Subject: [PATCH] helper code for rendering examples
---
build.js | 19 ++++++++++++++++++-
docs/index.html.ejs | 40 ++++++++--------------------------------
2 files changed, 26 insertions(+), 33 deletions(-)
diff --git a/build.js b/build.js
index af4746f..a777c81 100644
--- a/build.js
+++ b/build.js
@@ -10,12 +10,29 @@ function getCurrentId() {
return id;
}
+function example(code) {
+ const magicBrackets = /\[\[(.*)\]\]/g;
+ const inline = code.replace(magicBrackets, "$1");
+ const escaped = code
+ .replace(magicBrackets, "")
+ .replace(//g, ">");
+
+ return `
+ ${inline}
+
+ Show code
+ ${escaped}
+
+
`;
+}
+
function buildDocs() {
const template = fs.readFileSync("./docs/index.html.ejs", "utf-8");
fs.writeFileSync(
"./docs/index.html",
- ejs.render(template, { getNewId, getCurrentId })
+ ejs.render(template, { getNewId, getCurrentId, example })
);
}
diff --git a/docs/index.html.ejs b/docs/index.html.ejs
index 0fc0bb3..8cace6a 100644
--- a/docs/index.html.ejs
+++ b/docs/index.html.ejs
@@ -92,55 +92,31 @@
They are given 12px of horizontal padding by default.
-
-
-
-
- Show code
- <button>Click me</button>
-
-
+ <%- example(``) %>
When buttons are clicked, the raised borders become sunken.
The following button is simulated to be in the pressed (active) state.
-
-
-
-
-
- Show code
- <button>I am being pressed</button>
-
-
+ <% /* [[ ... ]] is used to render contents that
+ will not appear in the "Show code" section */
+ %>
+ <%- example(``) %>
+
Disabled buttons maintain the same raised border, but have a "washed out"
appearance in their label.
-
-
-
-
- Show code
- <button disabled>I cannot be clicked</button>
-
-
+ <%- example(``) %>
Button focus is communicated with a dotted border, set 4px within the contents of the button.
The following example is simulated to be focused.
-
-
-
- Show code
- <button>I am focused</button>
-
-
+ <%- example(``) %>