Skip to content
Browse files

Update the project page template and build process. Add marked and Ug…

…lifyJS as submodules.
  • Loading branch information...
1 parent e781279 commit d3fc9833e56a98e995a63470299d2780cfbec872 @kitcambridge kitcambridge committed
Showing with 243 additions and 26 deletions.
  1. +6 −0 .gitmodules
  2. +72 −21 build.js
  3. BIN page/background.png
  4. +19 −0 page/page.html
  5. +143 −0 page/style.css
  6. +1 −5 test/test_json3.js
  7. +1 −0 vendor/marked
  8. +1 −0 vendor/uglifyjs
View
6 .gitmodules
@@ -1,3 +1,9 @@
[submodule "vendor/spec"]
path = vendor/spec
url = git://github.com/kitcambridge/spec.git
+[submodule "vendor/marked"]
+ path = vendor/marked
+ url = git://github.com/chjj/marked.git
+[submodule "vendor/uglifyjs"]
+ path = vendor/uglifyjs
+ url = git://github.com/mishoo/UglifyJS.git
View
93 build.js
@@ -1,29 +1,80 @@
-var marked = require("marked"), fs = require("fs"), compressor = require("uglify-js");
+/* JSON 3 Builder | http://bestiejs.github.com/json3 */
+var fs = require("fs"), marked = require("./vendor/marked"), compressor = require("./vendor/uglifyjs/uglify-js");
-// Enable GitHub Flavored Markdown.
+// Enable GitHub-Flavored Markdown.
marked.setOptions({ "gfm": true });
// Generate the GitHub project page.
-fs.readFile("README.md", "utf8", function (exception, source) {
+fs.readFile("README.md", "utf8", function readSource(exception, source) {
if (exception) {
console.log(exception);
} else {
- source = [
- "<!DOCTYPE html>",
- "<html lang=en>",
- "<head>",
- "<meta charset=utf-8>",
- "<title>JSON 3</title>",
- "<link rel=stylesheet href=page.css media=screen>",
- "</head>",
- "<body>",
- marked(source),
- "<script src=lib/json3.js></script>",
- "</body>",
- "</html>"
- ].join("\n");
- fs.writeFile("index.html", source, function (exception) {
- console.log(exception || "GitHub project page generated successfully.");
+ // Read the project page template.
+ fs.readFile("page/page.html", "utf8", function readPage(exception, page) {
+ var headers, lines, lastSection, lastLevel, navigation;
+ if (exception) {
+ console.log(exception);
+ } else {
+ // Generate the page navigation. Ported from `mdtoc.rb` by Sam
+ // Stephenson.
+ headers = [];
+ lines = source.split(/\r?\n/);
+ // First pass: Scan the Markdown source looking for titles of the format:
+ // `### Title ###`. Record the line number, header level (number of
+ // octothorpes), and text of each matching title.
+ lines.forEach(function (line, index) {
+ var match = /^(\#{1,6})\s+(.+?)\s+\1$/.exec(line);
+ if (match) {
+ headers.push([index, match[1].length, match[2]]);
+ }
+ });
+ // Second pass: Iterate over all matched titles and compute their
+ // corresponding section numbers. Then replace the titles with annotated
+ // anchors.
+ headers.forEach(function(value) {
+ var index = value[0], level = value[1], text = value[2], section, length;
+ if (lastSection) {
+ // Duplicate the last section metadata array.
+ section = lastSection.slice(0);
+ if (lastLevel < level) {
+ section.push(1);
+ } else {
+ length = lastLevel - level;
+ while (length--) {
+ section.pop();
+ }
+ section[section.length - 1] += 1;
+ }
+ } else {
+ section = [1];
+ }
+ lines[index] = Array(level + 1).join("#") + "<a name=\"section_" + section.join(".") + "\"></a>" + text;
+ value.push(section);
+ lastSection = section;
+ lastLevel = level;
+ });
+ // Third pass: Iterate over matched titles once more to produce the table of
+ // contents.
+ navigation = headers.map(function (value) {
+ var index = value[0], level = value[1], text = value[2], section = value[3], name = section.join(".");
+ return "<li><a href=\"#section_" + name + "\">" + text + "</a></li>";
+ });
+ navigation.push("");
+ // Write the page source to disk.
+ fs.writeFile("index.html", page.replace(/<%=\s*(.+?)\s*%>/g, function (match, data) {
+ switch (data) {
+ case "navigation":
+ // Insert the table of contents directly into the template.
+ return navigation.join("\n");
+ case "source":
+ // Convert the read me to HTML and insert it into the page body.
+ return marked(lines.join("\n"));
+ }
+ return "";
+ }), function (exception) {
+ console.log(exception || "GitHub project page generated successfully.");
+ });
+ }
});
}
});
@@ -48,8 +99,8 @@ fs.readFile("lib/json3.js", "utf8", function (exception, source) {
// function exposed by asynchronous module loaders.
compressor.uglify.ast_mangle(compressor.parser.parse(source), {
"except": ["define"]
- })
- )), {
+ }
+ ))), {
"ascii_only": true
});
// Older environments, Safari, and Chrome choke on excessively long lines.
View
BIN page/background.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
19 page/page.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>JSON 3</title>
+ <link rel="stylesheet" href="page/style.css" media="screen">
+ </head>
+ <body>
+ <ul id="navigation">
+ <%= navigation %>
+ </ul>
+ <div id="content">
+ <%= source %>
+ </div>
+ <div id="footer">
+ <p>&copy; 2012 <a href="http://kitcambridge.github.com">Kit Cambridge</a>.</p>
+ </div>
+ </body>
+</html>
View
143 page/style.css
@@ -0,0 +1,143 @@
+/* Earl Grey | http://kitcambridge.github.com/earlgrey | Copyright 2011-2012, Kit Cambridge | http://creativecommons.org/licenses/by/3.0 */
+html {
+ font: 12px/24px "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif;
+ background: url(background.png);
+}
+
+body {
+ width: 80%;
+ margin: 20px auto;
+ border: 3px solid #eee;
+ background: #fff;
+}
+
+#content {
+ padding: 25px;
+ text-align: justify;
+}
+
+p, ul, ol {
+ padding: 5px 0;
+ margin: 0;
+}
+
+ul, ol {
+ color: #333;
+ margin: auto auto auto 25px;
+}
+
+a {
+ padding: 1px;
+ color: inherit;
+ text-decoration: underline;
+}
+
+a:hover, a:focus {
+ text-decoration: none;
+}
+
+#content a:hover, #content a:focus {
+ background: #000;
+ color: #fff;
+}
+
+#footer a:hover, #footer a:focus {
+ background: #fff;
+ color: #000;
+}
+
+h1, h2, h3 {
+ padding: 5px 0;
+ margin: 0;
+}
+
+h1 {
+ font: 24px Palatino, Georgia, Times, "Times New Roman", serif;
+ color: #900;
+}
+
+h2, h3 {
+ text-transform: uppercase;
+ color: #666;
+ letter-spacing: 1px;
+ font-weight: bold;
+}
+
+h2 {
+ font-size: 14px;
+}
+
+h3 {
+ font-size: 12px;
+}
+
+table {
+ border-collapse: collapse;
+ border: solid #ccc;
+ border-width: 1px 0 0 1px;
+ margin: 15px 0;
+}
+
+td, th {
+ border: solid #ccc;
+ border-width: 0 1px 1px 0;
+ padding: 5px;
+ width: 20%;
+ text-align: center;
+}
+
+th {
+ font-weight: bold;
+ color: #333;
+}
+
+#navigation {
+ list-style: none;
+ float: left;
+ text-align: center;
+ width: 100%;
+ background: #333;
+ padding: 0;
+ margin: 0 0 10px 0;
+}
+
+#navigation li {
+ display: inline;
+}
+
+#navigation a {
+ display: inline-block;
+ color: #fff;
+ padding: 5px 5% 5px;
+ height: 20px;
+ text-decoration: none;
+ text-align: center;
+}
+
+#navigation a:hover, #navigation a:focus, #navigation a.active {
+ background: #eee;
+ color: #900;
+}
+
+#footer {
+ background: #333;
+ color: #fff;
+ text-align: center;
+}
+
+pre, code, tt {
+ font: normal 12px/24px Menlo, Monaco, Consolas, "Lucida Console", monospace;
+}
+
+pre {
+ background-color: #f8f8ff;
+ padding: 10px;
+ border: 1px solid #eee;
+ word-wrap: break-word;
+ white-space: pre-wrap;
+}
+
+img {
+ padding: 0 0 30px 30px;
+ float: right;
+}
View
6 test/test_json3.js
@@ -1,8 +1,4 @@
-/*
- * JSON 3 unit test suite.
- * http://bestiejs.github.com/json3
-*/
-
+/* JSON 3 Unit Test Suite | http://bestiejs.github.com/json3 */
(function (root) {
var isLoader = typeof define == "function" && !!define.amd,
isModule = typeof require == "function" && typeof exports == "object" && exports && !isLoader,
1 vendor/marked
@@ -0,0 +1 @@
+Subproject commit 041dd98ed46c7609ac39d32e6452571cd247b716
1 vendor/uglifyjs
@@ -0,0 +1 @@
+Subproject commit 37aed3a2964cabd4c9bf4f0750cf15242ec00731

0 comments on commit d3fc983

Please sign in to comment.
Something went wrong with that request. Please try again.