Skip to content

Instantly share code, notes, and snippets.

@justindujardin
Created March 17, 2012 20:15
Show Gist options
  • Save justindujardin/2064894 to your computer and use it in GitHub Desktop.
Save justindujardin/2064894 to your computer and use it in GitHub Desktop.
Docco template for filtering out private doc sections
docco -t private_filter.jst private_filter.coffee
# This file contains private API docs and code that we wish to be
# removed from the `docco` output. To accomplish this, we add a
# custom marker `@private` to any comment/code blocks that we want
# to hide from the output. The token `@private` must be on its own
# line, or be preceeded by a space, so that quoting it in strings
# will not hide sections.
#
# We then remove them from the output using a modified docco template
# that will skip over sections that contain this marker, by using a
# simple regex match.
#
# For the simplest case of updating the default `docco.jst` template,
# simply find the lines:
#
# <% for (var i=0, l=sections.length; i<l; i++) { %>
# <% var section = sections[i]; %>
#
# ...then add the following chunk, directly below the second line
#
# <% if(section.docs_html.match(/[\n\s]@private/m)) continue; %>
#
# ### Main
# This file contains two function definitions, but you should only see
# one on this page.
# The only public api this file exposes.
exports.main = () ->
console.log "Doing things..."
# An internal helper function that is not documented.
# @private
_internal_helper = () ->
console.log "Doing some private things..."
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="all" href="<%= css %>" />
</head>
<body>
<div id="container">
<div id="background"></div>
<% if (sources.length > 1) { %>
<div id="jump_to">
Jump To &hellip;
<div id="jump_wrapper">
<div id="jump_page">
<% for (var i=0, l=sources.length; i<l; i++) { %>
<% var source = sources[i]; %>
<a class="source" href="<%= path.basename(destination(source)) %>">
<%= path.basename(source) %>
</a>
<% } %>
</div>
</div>
</div>
<% } %>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="docs">
<h1>
<%= title %>
</h1>
</th>
<th class="code">
</th>
</tr>
</thead>
<tbody>
<% for (var i=0, l=sections.length; i<l; i++) { %>
<% var section = sections[i]; %>
<%
/* Skip over sections that have @private in the docstring. */
if(section.docs_html.match(/[\n\s]@private/m)) continue;
%>
<tr id="section-<%= i + 1 %>">
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-<%= i + 1 %>">&#182;</a>
</div>
<%= section.docs_html %>
</td>
<td class="code">
<%= section.code_html %>
</td>
</tr>
<% } %>
</tbody>
</table>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment