More simplification of the templating & rendering.
authorMicheil Smith <micheil@brandedcode.com>
Thu, 28 Oct 2010 20:00:28 +0000 (07:00 +1100)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 28 Oct 2010 21:59:15 +0000 (14:59 -0700)
doc/template.html [moved from doc/template_page.html with 79% similarity]
doc/template_index.html [deleted file]
tools/doctool/doctool.js

similarity index 79%
rename from doc/template_page.html
rename to doc/template.html
index 240ca9d..dfbf7f0 100644 (file)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
 <head>
-  <title>{{section}} - Node.js Manual &amp; Documentation</title>
+  <title>{{section}}Node.js Manual &amp; Documentation</title>
   <link rel="stylesheet" href="assets/style.css" type="text/css" media="all" />
   <link rel="stylesheet" href="assets/sh.css" type="text/css" media="all"/>
   <script type="text/javascript" src="assets/jquery.js"></script>
@@ -11,7 +11,7 @@
     <header>
       <h1>Node.js Manual &amp; Documentation</h1>
       <div id="gtoc">
-        <p><a href="index.html">Table of Contents</a></p>
+        <p><a href="index.html">Table of Contents</a> | <a href="all.html">View on single page</a></p>
       </div>
       <hr />
     </header>
diff --git a/doc/template_index.html b/doc/template_index.html
deleted file mode 100644 (file)
index 56b42ab..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <title>Node.js Manual &amp; Documentation</title>
-  <link rel="stylesheet" href="assets/style.css" type="text/css" media="all" />
-  <link rel="stylesheet" href="assets/sh.css" type="text/css" media="all"/>
-  <script type="text/javascript" src="assets/jquery.js"></script>
-</head>
-<body>
-  <div id="container">
-    <header>
-      <h1>Node.js Manual &amp; Documentation</h1>
-      <hr />
-    </header>
-    {{content}}
-  </div>
-  <script type="text/javascript" src="assets/sh_main.js"></script>
-  <script type="text/javascript" src="assets/sh_javascript.min.js"></script>
-  <script type="text/javascript" src="assets/core.js"></script>
-</body>
-</html>
\ No newline at end of file
index 223ddab..c28402f 100644 (file)
@@ -71,22 +71,14 @@ function checkdir(next){
 /*
 Loads the template for which the documentation should be outputed into.
 */
-var template_index, template_page;
+var template;
 
 function loadTemplates(next){
-  var templates_path = path.join(doc_root, "..", "template");
-  
-  fs.readFile(templates_path+"_page.html", "utf8", function(err, data){
-    if(err) throw err;
+  fs.readFile(path.join(doc_root, "../template.html"), "utf8", function(e, d){
+    if(e) throw e;
     
-    template_page = data;
-    
-    fs.readFile(templates_path+"_index.html", "utf8", function(err, data){
-      if(err) throw err;
-
-      template_index = data;
-      next();
-    });
+    template = d;
+    next();
   });
 };
 
@@ -103,8 +95,7 @@ function convertFiles(next){
     files.filter(function(file){
       var basename = path.basename(file, ".markdown");
       return path.extname(file) == ".markdown" &&
-        basename != "index" &&
-        basename != "_toc";
+        basename.substr(0,1) != "_";
     }).forEach(function(file){
       var filename = path.basename(file, '.markdown')
         , build_path = path.join(build_root, filename+".html")
@@ -115,9 +106,13 @@ function convertFiles(next){
         
         // do conversion stuff.
         var html = convertData(data);
-        var output = template_page
-          .replace("{{section}}", filename)
-          .replace("{{content}}", html);
+        var output = template.replace("{{content}}", html);
+        
+        if(filename == "index"){
+          output = output.replace("{{section}}", "");
+        } else {
+          output = output.replace("{{section}}", filename+" - ")
+        }
         
         fs.writeFile(build_path, output, function(err){
           if(err) throw err;
@@ -129,22 +124,6 @@ function convertFiles(next){
   next();
 };
 
-function createIndex(next){
-  fs.readFile(path.join(doc_root, "index.markdown"), "utf8", function(err, data){
-    if(err) throw err;
-    
-    // do conversion stuff.
-    var html = convertData(data);
-    var output = template_index.replace("{{content}}", html);
-    
-    fs.writeFile(path.join(build_root, "index.html"), output, function(err){
-      if(err) throw err;
-    });
-  });
-  // one again, no need to wait.
-  next();
-};
-
 function copyAssets(next){
   cp.exec("cp -R "+assets_path+" "+bassets_path, function(err, stdout, stderr){
     next();
@@ -155,6 +134,5 @@ step(
   checkdir,
   copyAssets,
   loadTemplates,
-  convertFiles,
-  createIndex
+  convertFiles
 )();
\ No newline at end of file