Skip to content
Browse files

much improved handling of modules

  • Loading branch information...
1 parent e31e86e commit a4a4eed931a18d25c1a4ec15f0848a0685eb0b34 Greg Smith committed Nov 23, 2011
Showing with 875 additions and 153 deletions.
  1. +1 −1 example.js
  2. +16 −32 out/{result.html → example.html}
  3. +103 −58 out/site.html
  4. +33 −15 site.js
  5. +5 −16 templates/default._template
  6. +49 −0 tests/modules.js
  7. +599 −0 tests/updoc.html
  8. +69 −31 updoc.js
View
2 example.js
@@ -71,4 +71,4 @@ window.example = (function() {
};
-})();
+})();
View
48 out/result.html → out/example.html
@@ -8,7 +8,7 @@
<style>
body {
padding: 0;
- margin: 0;
+ margin: 1em 0 0;
font-family: sans-serif;
line-height: 1.4em;
}
@@ -125,15 +125,14 @@
}
.depth0 {
- margin: 0em;
+ margin: 1em 0em;
}
.depth0 h1 {
text-shadow: 1px 1px 0 #cc7800;
}
.depth0.header {
- margin: 1em 0;
border-style: none solid solid none;
border-width: 2px;
border-color: #9e5d00;
@@ -142,7 +141,7 @@
}
.depth1 {
- margin: 1em 0 1em 2em;
+ margin: 1em 0 1em 1em;
}
.depth1 h1 {
@@ -154,22 +153,13 @@
border-color: #00416e;
border-width: 2px;
background-color: #c9e9ff;
- margin: 1em 0 1em 1em;
}
.depth2 {
- margin: 1em 0 1em 3em;
-}
-
-.depth2.header {
margin: 1em 0 1em 2em;
}
.depth3 {
- margin: 1em 0 1em 4em;
-}
-
-.depth3.header {
margin: 1em 0 1em 3em;
}
</style>
@@ -273,7 +263,7 @@
</nav>
<div id="sections">
- <section class="depth0 header">
+ <section class="depth0 header" data-module="">
<h1 id="header-Example-App">Example App</h1>
@@ -296,7 +286,7 @@ <h1 id="header-Example-App">Example App</h1>
</section>
- <section class="depth1 header">
+ <section class="depth1 header" data-module="guesser">
<h1 id="header-Guesser-module">Guesser module</h1>
@@ -320,7 +310,7 @@ <h1 id="header-Guesser-module">Guesser module</h1>
</section>
- <section class="depth1 ">
+ <section class="depth2 " data-module="guesser.SECRET">
@@ -353,13 +343,13 @@ <h2 id="name-SECRET">
</section>
- <section class="depth1 ">
+ <section class="depth2 " data-module="guesser.guess">
<h2 id="name-guess">
- function
+
@@ -374,8 +364,6 @@ <h2 id="name-guess">
-
-
<li>
<span class="property">
param
@@ -403,7 +391,7 @@ <h2 id="name-guess">
</section>
- <section class="depth1 header">
+ <section class="depth1 header" data-module="util">
<h1 id="header-Util-Module">Util Module</h1>
@@ -427,7 +415,7 @@ <h1 id="header-Util-Module">Util Module</h1>
</section>
- <section class="depth2 header">
+ <section class="depth2 header" data-module="util.cheating">
<h1 id="header-Cheating">Cheating</h1>
@@ -451,13 +439,13 @@ <h1 id="header-Cheating">Cheating</h1>
</section>
- <section class="depth2 ">
+ <section class="depth3 " data-module="util.cheating.cheat">
<h2 id="name-cheat">
- function
+
@@ -474,8 +462,6 @@ <h2 id="name-cheat">
-
-
<li>
<span class="property">
return
@@ -492,7 +478,7 @@ <h2 id="name-cheat">
</section>
- <section class="depth2 header">
+ <section class="depth2 header" data-module="util.math">
<h1 id="header-Math">Math</h1>
@@ -516,13 +502,13 @@ <h1 id="header-Math">Math</h1>
</section>
- <section class="depth2 ">
+ <section class="depth3 " data-module="util.math.numBetween">
<h2 id="name-numBetween">
- function
+
@@ -539,8 +525,6 @@ <h2 id="name-numBetween">
-
-
<li>
<span class="property">
param1
@@ -590,4 +574,4 @@ <h2 id="name-numBetween">
})();
</script>
</body>
-</html>
+</html>
View
161 out/site.html
@@ -8,7 +8,7 @@
<style>
body {
padding: 0;
- margin: 0;
+ margin: 1em 0 0;
font-family: sans-serif;
line-height: 1.4em;
}
@@ -125,15 +125,14 @@
}
.depth0 {
- margin: 0em;
+ margin: 1em 0em;
}
.depth0 h1 {
text-shadow: 1px 1px 0 #cc7800;
}
.depth0.header {
- margin: 1em 0;
border-style: none solid solid none;
border-width: 2px;
border-color: #9e5d00;
@@ -142,7 +141,7 @@
}
.depth1 {
- margin: 1em 0 1em 2em;
+ margin: 1em 0 1em 1em;
}
.depth1 h1 {
@@ -154,22 +153,13 @@
border-color: #00416e;
border-width: 2px;
background-color: #c9e9ff;
- margin: 1em 0 1em 1em;
}
.depth2 {
- margin: 1em 0 1em 3em;
-}
-
-.depth2.header {
margin: 1em 0 1em 2em;
}
.depth3 {
- margin: 1em 0 1em 4em;
-}
-
-.depth3.header {
margin: 1em 0 1em 3em;
}
</style>
@@ -233,7 +223,7 @@
<li>
-
- <a href="#header-Rules">Rules</a>
+ <a href="#header-Using-updoc">Using updoc</a>
</li>
@@ -243,7 +233,7 @@
<li>
-
- <a href="#header-Using-updoc">Using updoc</a>
+ <a href="#header-Rules">Rules</a>
</li>
@@ -270,12 +260,22 @@
+ <li>
+ -
+
+ <a href="#header-Highlighting">Highlighting</a>
+
+
+ </li>
+
+
+
</ul>
</nav>
<div id="sections">
- <section class="depth0 header">
+ <section class="depth0 header" data-module="">
<h1 id="header-updoc">updoc</h1>
@@ -297,7 +297,7 @@ <h1 id="header-updoc">updoc</h1>
</section>
- <section class="depth1 header">
+ <section class="depth1 header" data-module="1info">
<h1 id="header-About">About</h1>
@@ -329,7 +329,7 @@ <h1 id="header-About">About</h1>
</section>
- <section class="depth1 header">
+ <section class="depth1 header" data-module="2features">
<h1 id="header-Features">Features</h1>
@@ -364,6 +364,15 @@ <h1 id="header-Features">Features</h1>
<li>
<span class="property">
+ code
+ </span>
+ is organized by modules
+ </li>
+
+
+
+ <li>
+ <span class="property">
templates
</span>
are easy to create and modify
@@ -396,7 +405,7 @@ <h1 id="header-Features">Features</h1>
</section>
- <section class="depth1 header">
+ <section class="depth1 header" data-module="3example">
<h1 id="header-Example">Example</h1>
@@ -437,7 +446,7 @@ <h1 id="header-Example">Example</h1>
</section>
- <section class="depth1 header">
+ <section class="depth1 header" data-module="4download">
<h1 id="header-Download">Download</h1>
@@ -461,7 +470,35 @@ <h1 id="header-Download">Download</h1>
</section>
- <section class="depth1 header">
+ <section class="depth1 header" data-module="5using">
+
+ <h1 id="header-Using-updoc">Using updoc</h1>
+
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">Install updoc like this:
+<code>sudo npm install updoc -g</code>
+Use updoc like this:
+<code>updoc input.js output.html</code>
+An optional 3rd argument specifies the template.</div>
+
+ </section>
+
+ <section class="depth1 header" data-module="6rules">
<h1 id="header-Rules">Rules</h1>
@@ -538,33 +575,7 @@ <h1 id="header-Rules">Rules</h1>
</section>
- <section class="depth1 header">
-
- <h1 id="header-Using-updoc">Using updoc</h1>
-
-
-
- <ul>
-
-
-
-
-
-
-
-
-
-
-
- </ul>
-
- <div class="description">You can use updoc like this:
-<code>node updoc input.js output.html</code>
-An optional 3rd argument specifies the template.</div>
-
- </section>
-
- <section class="depth1 header">
+ <section class="depth1 header" data-module="7modules">
<h1 id="header-Modules">Modules</h1>
@@ -587,18 +598,22 @@ <h1 id="header-Modules">Modules</h1>
<div class="description">updoc organizes your documentation by modules. Each comment
block can have a &#64;module property. It looks like this:
<code>&#64;module app.util.foobar</code>
+The function or var name is added to the end of the module if appropriate.
+Code of this form has its module set automatically:
+<code>foo.bar.bat = function() {} // my module is foo.bar.bat</code>
Sections are nested by
the module's depth and sorted by name. The sort order follows:
<ol>
<li>alphabetical by module</li>
<li>alphabetical by name (for functions and vars)</li>
<li>order of appearance in source</li>
</ol>
-If the module property is omitted it is a top-level section.</div>
+If the module property is omitted and isn't detected it is a top-level
+section.</div>
</section>
- <section class="depth1 header">
+ <section class="depth1 header" data-module="8templates">
<h1 id="header-Templates">Templates</h1>
@@ -623,14 +638,14 @@ <h1 id="header-Templates">Templates</h1>
properties provided in the updoc comments, with a few bonus properties.
</p>
<code>{
-&nbsp;version: '0.1', // updoc version
+&nbsp;version: '0.0.1', // updoc version
&nbsp;sections: [ // each updoc comment is a section
&nbsp;&nbsp;{
&nbsp;&nbsp; name: 'foo' // var name or function name. may be absent
&nbsp;&nbsp; type: 'function', // function or var or other
&nbsp;&nbsp; prop: 'val', // &#64;prop val
-&nbsp;&nbsp; module: 'example.util', // &#64;module example.util
-&nbsp;&nbsp; depth: 2 // module depth. &#64;module foo.bar.bat is depth 3
+&nbsp;&nbsp; module: 'example.util.foo', // &#64;module example.util
+&nbsp;&nbsp; depth: 3 // module depth. &#64;module foo.bar.bat is depth 3
&nbsp; }
&nbsp;]
}</code>
@@ -647,12 +662,40 @@ <h1 id="header-Templates">Templates</h1>
</p>
<p>
You can view the raw json output by specifying "json" as the output file
-</p>
-<code>node updoc example.js json</code></div>
+</p></div>
</section>
- <section class="depth0 ">
+ <section class="depth1 header" data-module="90highlighting">
+
+ <h1 id="header-Highlighting">Highlighting</h1>
+
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">The default template uses
+<a href="http://code.google.com/p/google-code-prettify/">prettify</a>.
+To get code highlighting, just put prettify.js and prettify.css in the same
+directory as your output. Then put code in a code element like this:
+<code>&lt;code>function() {}&lt;/code></code>
+</p></div>
+
+ </section>
+
+ <section class="depth1 " data-module="91footer">
@@ -666,6 +709,8 @@ <h1 id="header-Templates">Templates</h1>
+
+
</ul>
<div class="description">Created by <a href="http://incompl.com">Greg Smith</a>
@@ -676,7 +721,7 @@ <h1 id="header-Templates">Templates</h1>
</div>
</div>
<footer>
- generated by <a href="https://github.com/incompl/updoc">updoc</a> 0.1
+ generated by <a href="https://github.com/incompl/updoc">updoc</a> 0.0.1
</footer>
<script>
(function() {
@@ -688,4 +733,4 @@ <h1 id="header-Templates">Templates</h1>
})();
</script>
</body>
-</html>
+</html>
View
48 site.js
@@ -23,6 +23,7 @@
* @header Features
* @flexible so you can use whatever properties you want
* @aware of function and var names
+ * @code is organized by modules
* @templates are easy to create and modify
* @html allowed in comments
* @json output if you want it
@@ -43,8 +44,18 @@
*/
/**
+ * @module 5using
+ * @header Using updoc
+ * @description Install updoc like this:
+ * <code>sudo npm install updoc -g</code>
+ * Use updoc like this:
+ * <code>updoc input.js output.html</code>
+ * An optional 3rd argument specifies the template.
+ */
+
+/**
* not documented
- * @module 5rules
+ * @module 6rules
* @header Rules
* @start updoc comments with /** on new line
* @close updoc comments with &#42;/ on new line
@@ -56,28 +67,23 @@
*/
/**
- * @module 6using
- * @header Using updoc
- * @description You can use updoc like this:
- * <code>node updoc input.js output.html</code>
- * An optional 3rd argument specifies the template.
- *
- */
-
-/**
* @module 7modules
* @header Modules
* @description updoc organizes your documentation by modules. Each comment
* block can have a &#64;module property. It looks like this:
* <code>&#64;module app.util.foobar</code>
+ * The function or var name is added to the end of the module if appropriate.
+ * Code of this form has its module set automatically:
+ * <code>foo.bar.bat = function() {} // my module is foo.bar.bat</code>
* Sections are nested by
* the module's depth and sorted by name. The sort order follows:
* <ol>
* <li>alphabetical by module</li>
* <li>alphabetical by name (for functions and vars)</li>
* <li>order of appearance in source</li>
* </ol>
- * If the module property is omitted it is a top-level section.
+ * If the module property is omitted and isn't detected it is a top-level
+ * section.
*/
/**
@@ -89,14 +95,14 @@
* properties provided in the updoc comments, with a few bonus properties.
* </p>
<code>{
-&nbsp;version: '0.1', // updoc version
+&nbsp;version: '0.0.1', // updoc version
&nbsp;sections: [ // each updoc comment is a section
&nbsp;&nbsp;{
&nbsp;&nbsp; name: 'foo' // var name or function name. may be absent
&nbsp;&nbsp; type: 'function', // function or var or other
&nbsp;&nbsp; prop: 'val', // &#64;prop val
-&nbsp;&nbsp; module: 'example.util', // &#64;module example.util
-&nbsp;&nbsp; depth: 2 // module depth. &#64;module foo.bar.bat is depth 3
+&nbsp;&nbsp; module: 'example.util.foo', // &#64;module example.util
+&nbsp;&nbsp; depth: 3 // module depth. &#64;module foo.bar.bat is depth 3
&nbsp; }
&nbsp;]
}</code>
@@ -114,10 +120,22 @@
* <p>
* You can view the raw json output by specifying "json" as the output file
* </p>
- * <code>node updoc example.js json</code>
*/
/**
+ * @module 90highlighting
+ * @header Highlighting
+ * @description
+ * The default template uses
+ * <a href="http://code.google.com/p/google-code-prettify/">prettify</a>.
+ * To get code highlighting, just put prettify.js and prettify.css in the same
+ * directory as your output. Then put code in a code element like this:
+ * <code>&lt;code>function() {}&lt;/code></code>
+ * </p>
+ */
+
+/**
+ * @module 91footer
* @description Created by <a href="http://incompl.com">Greg Smith</a>
* at <a href="http://bocoup.com">Bocoup</a>
*/
View
21 templates/default._template
@@ -8,7 +8,7 @@
<style>
body {
padding: 0;
- margin: 0;
+ margin: 1em 0 0;
font-family: sans-serif;
line-height: 1.4em;
}
@@ -125,15 +125,14 @@ code {
}
.depth0 {
- margin: 0em;
+ margin: 1em 0em;
}
.depth0 h1 {
text-shadow: 1px 1px 0 #cc7800;
}
.depth0.header {
- margin: 1em 0;
border-style: none solid solid none;
border-width: 2px;
border-color: #9e5d00;
@@ -142,7 +141,7 @@ code {
}
.depth1 {
- margin: 1em 0 1em 2em;
+ margin: 1em 0 1em 1em;
}
.depth1 h1 {
@@ -154,22 +153,13 @@ code {
border-color: #00416e;
border-width: 2px;
background-color: #c9e9ff;
- margin: 1em 0 1em 1em;
}
.depth2 {
- margin: 1em 0 1em 3em;
-}
-
-.depth2.header {
margin: 1em 0 1em 2em;
}
.depth3 {
- margin: 1em 0 1em 4em;
-}
-
-.depth3.header {
margin: 1em 0 1em 3em;
}
</style>
@@ -182,7 +172,6 @@ code {
<% if (s.header || s.name) { %>
<li>
<%
- if (s.name) {print("-");}
for (var i = 0; i < s.depth; i++) {print("-");}
%>
<% if (s.header) { %>
@@ -198,7 +187,7 @@ code {
</nav>
<div id="sections">
<% _.each(sections, function(s) { %>
- <section class="depth<%= s.depth %> <%= s.header ? "header" : "" %>">
+ <section class="depth<%= s.depth %> <%= s.header ? "header" : "" %>" data-module="<%= s.module %>">
<%= s.header ? '<h1 id="header-' + s.header.replace(/ /g, '-') + '">' + s.header + "</h1>" : "" %>
@@ -249,4 +238,4 @@ code {
})();
</script>
</body>
-</html>
+</html>
View
49 tests/modules.js
@@ -0,0 +1,49 @@
+/**
+ * @description ...
+ */
+var gar = {};
+
+/**
+ * @header module test
+ */
+
+/**
+ * @description ...
+ */
+gar.b = {};
+
+/**
+ * @description ...
+ */
+gar.a = {};
+
+/**
+ * @description ...
+ */
+gar.a.cat = function() {};
+
+
+/**
+ * @description ...
+ */
+gar.a.bat = function() {};
+
+/**
+ * @description ...
+ */
+var foo = {};
+
+/**
+ * @description ...
+ */
+foo.bar = {};
+
+/**
+ * @description ...
+ */
+foo.bar.bat = function() {};
+
+/**
+ * @description ...
+ */
+gar.b.ape = function() {};
View
599 tests/updoc.html
@@ -0,0 +1,599 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>updoc</title>
+ <script src="prettify.js"></script>
+ <link rel="stylesheet" href="prettify.css">
+ <style>
+body {
+ padding: 0;
+ margin: 1em 0 0;
+ font-family: sans-serif;
+ line-height: 1.4em;
+}
+
+a:link {
+ color: #000498;
+}
+a:hover {
+ color: #4549ff;
+}
+a:visited {
+ color: black;
+}
+a:active {
+ color: black;
+}
+
+section {
+ padding: .6em 1em .4em;
+ margin: 1em;
+ background-color: #dce8f1;
+ border-radius: 10px;
+}
+
+h1, h2, h3 {
+ text-shadow: 1px 1px 0 #838383;
+ margin: 0 0 .2em;
+}
+
+h1 {
+ font-size: 1.6em;
+}
+
+h2 {
+ font-size: 1.4em;
+}
+
+h3 {
+ font-size: 1.2em;
+}
+
+p {
+ margin: .4em 0;
+}
+
+ul {
+ margin: 0;
+}
+
+.description {
+ background-color: rgba(255, 255, 255, .5);
+ border-radius: 5px;
+ padding: .3em .5em;
+ margin: .5em 0 .3em;
+}
+
+#content {
+ width: 900px;
+ margin: 0 auto;
+}
+
+nav {
+ float: left;
+ width: 150px;
+ padding: 8px;
+ background-color: #dce8f1;
+ border-radius: 10px;
+ border-style: none solid solid none;
+ border-width: 2px;
+ border-color: #8895a0;
+}
+
+nav ul {
+ padding: 2px 7px;
+ list-style-type: none;
+ background-color: rgba(255, 255, 255, .5);
+ border-radius: 5px;
+}
+
+#sections {
+ margin-left: 180px;
+}
+
+footer {
+ text-align: center;
+ padding: .5em 0;
+ color: #858585;
+}
+
+footer a:link, footer a:visited {
+ color: #5b5c88;
+}
+
+code {
+ display: block;
+ font-family: monospace;
+ font-size: 1.3em;
+ white-space: pre;
+ margin: .3em 0;
+ padding: .3em .5em;
+ background-color: rgba(255, 255, 255, .8);
+ border-radius: 5px;
+ color: #1f1f1f;
+}
+
+.header {
+ border-style: none solid solid none;
+ border-width: 2px;
+ border-color: #8895a0;
+}
+
+.property {
+ font-weight: bold;
+}
+
+.depth0 {
+ margin: 1em 0em;
+}
+
+.depth0 h1 {
+ text-shadow: 1px 1px 0 #cc7800;
+}
+
+.depth0.header {
+ border-style: none solid solid none;
+ border-width: 2px;
+ border-color: #9e5d00;
+ border-radius: 20px;
+ background-color: #ffc571;
+}
+
+.depth1 {
+ margin: 1em 0 1em 1em;
+}
+
+.depth1 h1 {
+ text-shadow: 1px 1px 0 #005896;
+}
+
+.depth1.header {
+ border-style: none solid solid none;
+ border-color: #00416e;
+ border-width: 2px;
+ background-color: #c9e9ff;
+}
+
+.depth2 {
+ margin: 1em 0 1em 2em;
+}
+
+.depth3 {
+ margin: 1em 0 1em 3em;
+}
+ </style>
+ </head>
+ <body>
+ <div id="content">
+ <nav>
+ <ul>
+
+
+ <li>
+
+
+ <a href="#header-module-test">module test</a>
+
+
+ </li>
+
+
+
+ <li>
+ -
+
+
+ <a href="#name-foo">foo</a>
+
+ </li>
+
+
+
+ <li>
+ --
+
+
+ <a href="#name-bar">bar</a>
+
+ </li>
+
+
+
+ <li>
+ ---
+
+
+ <a href="#name-bat">bat</a>
+
+ </li>
+
+
+
+ <li>
+ -
+
+
+ <a href="#name-gar">gar</a>
+
+ </li>
+
+
+
+ <li>
+ --
+
+
+ <a href="#name-a">a</a>
+
+ </li>
+
+
+
+ <li>
+ ---
+
+
+ <a href="#name-bat">bat</a>
+
+ </li>
+
+
+
+ <li>
+ ---
+
+
+ <a href="#name-cat">cat</a>
+
+ </li>
+
+
+
+ <li>
+ --
+
+
+ <a href="#name-b">b</a>
+
+ </li>
+
+
+
+ <li>
+ ---
+
+
+ <a href="#name-ape">ape</a>
+
+ </li>
+
+
+ </ul>
+ </nav>
+ <div id="sections">
+
+ <section class="depth0 header" data-module="">
+
+ <h1 id="header-module-test">module test</h1>
+
+
+
+ <ul>
+
+
+
+
+
+
+
+ </ul>
+
+
+
+ </section>
+
+ <section class="depth1 " data-module="foo">
+
+
+
+
+ <h2 id="name-foo">
+
+
+ var
+
+ foo
+ </h2>
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">...</div>
+
+ </section>
+
+ <section class="depth2 " data-module="foo.bar">
+
+
+
+
+ <h2 id="name-bar">
+
+
+
+
+ bar
+ </h2>
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">...</div>
+
+ </section>
+
+ <section class="depth3 " data-module="foo.bar.bat">
+
+
+
+
+ <h2 id="name-bat">
+ function
+
+
+
+ bat
+ </h2>
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">...</div>
+
+ </section>
+
+ <section class="depth1 " data-module="gar">
+
+
+
+
+ <h2 id="name-gar">
+
+
+ var
+
+ gar
+ </h2>
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">...</div>
+
+ </section>
+
+ <section class="depth2 " data-module="gar.a">
+
+
+
+
+ <h2 id="name-a">
+
+
+
+
+ a
+ </h2>
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">...</div>
+
+ </section>
+
+ <section class="depth3 " data-module="gar.a.bat">
+
+
+
+
+ <h2 id="name-bat">
+ function
+
+
+
+ bat
+ </h2>
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">...</div>
+
+ </section>
+
+ <section class="depth3 " data-module="gar.a.cat">
+
+
+
+
+ <h2 id="name-cat">
+ function
+
+
+
+ cat
+ </h2>
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">...</div>
+
+ </section>
+
+ <section class="depth2 " data-module="gar.b">
+
+
+
+
+ <h2 id="name-b">
+
+
+
+
+ b
+ </h2>
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">...</div>
+
+ </section>
+
+ <section class="depth3 " data-module="gar.b.ape">
+
+
+
+
+ <h2 id="name-ape">
+ function
+
+
+
+ ape
+ </h2>
+
+
+ <ul>
+
+
+
+
+
+
+
+
+
+
+
+ </ul>
+
+ <div class="description">...</div>
+
+ </section>
+
+ </div>
+ </div>
+ <footer>
+ generated by <a href="https://github.com/incompl/updoc">updoc</a> 0.0.1
+ </footer>
+ <script>
+(function() {
+ var codes = document.getElementsByTagName("code")
+ for (var i = 0; i < codes.length; i++) {
+ codes[i].className = codes[i].className + " prettyprint";
+ }
+ prettyPrint();
+})();
+ </script>
+ </body>
+</html>
View
100 updoc.js
@@ -53,33 +53,50 @@ updoc = function(file, targetFile, templateFile) {
var blockComment = commentAndNextLine.match(/^\s*\/\*\*[\s\S]*?\*\//gm)[0];
var properties = blockComment.match(/@[^@]*/g);
var potentialValue;
+ var potentialModule;
var blockData = {};
var moduleData;
var deleteProps = {};
- // determine variable or function name
- if (lastLine.match("function")) {
- potentialValue = lastLine.match(/function ([\w$_]+)/);
+ // module and name for
+ // foo.bar.baz = ...;
+ potentialModule = lastLine.match(/^([\w$_.]+)\s+=\s+(.*)/);
+ if (potentialModule && potentialModule[1] && potentialModule[2]) {
+ blockData.module = potentialModule[1];
+ blockData.name = potentialModule[1].substr(potentialModule[1].lastIndexOf(".") + 1);
+ if (potentialModule[2].match(/function\s*\(/)) {
+ blockData.type = "function";
+ }
+ else {
+ blockData.type = "other";
+ }
+ }
+ // function name for
+ // function foo() {
+ // and
+ // foo: function() {
+ else if (lastLine.match("function")) {
+ potentialValue = lastLine.match(/function ([\w$_]+)/);
+ if (potentialValue) {
+ blockData.name = potentialValue[1];
+ }
+ else {
+ potentialValue = lastLine.match(/([\w$_]+):\s*function/);
if (potentialValue) {
blockData.name = potentialValue[1];
}
- else {
- potentialValue = lastLine.match(/([\w$_]+):\s*function/);
- if (potentialValue) {
- blockData.name = potentialValue[1];
- }
- }
- blockData.type = "function";
+ }
}
+ // var name for
+ // var foo = 5;
else if (lastLine.match("var")) {
- blockData.name = lastLine.match(/var ([\w$_]+)/)[1];
- blockData.type = "var";
+ blockData.name = lastLine.match(/var ([\w$_]+)/)[1];
+ blockData.type = "var";
}
else {
- blockData.type = "other";
+ blockData.type = "other";
}
-
_.each(properties, function(property) {
var propInfo;
var propName;
@@ -106,27 +123,42 @@ updoc = function(file, targetFile, templateFile) {
});
// add number to prop names if there is more than one with same name
- numberedPropName = propName;
- while (blockData[numberedPropName]) {
- propNum = numberedPropName.match(/\d+$/);
- if (propNum) {
- numberedPropName = numberedPropName.match(/(\D+)\d+/)[1] + (Number(propNum) + 1);
- }
- else {
- blockData[numberedPropName + "1"] = blockData[numberedPropName];
- numberedPropName = numberedPropName + "2";
- deleteProps[propName] = true;
+ if (propName === "module") {
+ blockData.module = propValLines[0];
+ }
+ else {
+ numberedPropName = propName;
+ while (blockData[numberedPropName]) {
+ propNum = numberedPropName.match(/\d+$/);
+ if (propNum) {
+ numberedPropName = numberedPropName.match(/(\D+)\d+/)[1] + (Number(propNum) + 1);
+ }
+ else {
+ blockData[numberedPropName + "1"] = blockData[numberedPropName];
+ numberedPropName = numberedPropName + "2";
+ deleteProps[propName] = true;
+ }
}
+ blockData[numberedPropName] = propValLines.join("\n");
}
- blockData[numberedPropName] = propValLines.join("\n");
});
// If we have numbered versions, delete the unnumbered version
_.each(deleteProps, function(val, prop) {
delete blockData[prop];
});
- // Module info
+ // if module wasn't detected, add the name to the provided @module
+ if (!potentialModule && blockData.name) {
+ if (blockData.module) {
+ blockData.module += "." + blockData.name;
+ }
+ else {
+ blockData.module = blockData.name;
+ }
+ }
+
+ // depth
if (blockData.module) {
moduleData = blockData.module.split(".");
blockData.depth = moduleData.length;
@@ -142,15 +174,21 @@ updoc = function(file, targetFile, templateFile) {
json.sections.sort(function(a, b) {
if (a.module === b.module) {
if (a.name === undefined) {
- return false;
+ return -1;
}
if (b.name === undefined) {
- return true;
+ return 1;
}
- return a.name > b.name;
+ return a.name > b.name ? 1 : -1;
+ }
+ else if (a.module === undefined) {
+ return -1;
+ }
+ else if (b.module === undefined) {
+ return 1;
}
else {
- return a.module > b.module;
+ return a.module > b.module ? 1 : -1;
}
});
@@ -177,4 +215,4 @@ updoc = function(file, targetFile, templateFile) {
});
-}
+}

0 comments on commit a4a4eed

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