can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
760 lines (500 loc) • 21.5 kB
HTML
<!--####################################################################
THIS IS A GENERATED FILE -- ANY CHANGES MADE WILL BE OVERWRITTEN
INSTEAD CHANGE:
source: [object Object]
@page guides/contributing/documentation
######################################################################## -->
<html lang="en">
<head>
<meta charset="utf-8">
<title>CanJS - Documentation</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" type="text/css" href="../../static/bundles/bit-docs-site/static.css">
<link rel="shortcut icon" sizes="16x16 24x24 32x32 48x48 64x64" href="/docs/images/canjs_favicon.ico">
<link rel="apple-touch-icon" sizes="57x57" href="../../../docs/images/canjs_favicon_57x57.png">
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="../../../docs/images/canjs_favicon_57x57.png">
<link rel="apple-touch-icon" sizes="72x72" href="../../../docs/images/canjs_favicon_72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="../../../docs/images/canjs_favicon_114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="../../../docs/images/canjs_favicon_128x128.png">
<link rel="apple-touch-icon" sizes="144x144" href="../../../docs/images/canjs_favicon_144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="../../../docs/images/canjs_favicon_152x152.png">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta name="apple-mobile-web-app-status-bar-style" content="white-translucent">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-2302003-11', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger"/>
<label for="nav-trigger">Menu</label>
<div id="everything">
<div id="left" class="column">
<div class="top-left">
<div class="brand">
<div class="logo">
<a href="../../../index.html" alt="CanJS"></a>
<div class="dropdown project-dropdown">
<a href="https://donejs.com/">DoneJS</a>
<a href="http://stealjs.com/">StealJS</a>
<a href="http://jquerypp.com/">jQuery ++</a>
<a href="https://funcunit.com/">FuncUnit</a>
<a href="http://documentjs.com/">DocumentJS</a>
</div>
</div>
<div class="version">
<div class="version-number">
3.0.0
</div>
<div class="dropdown version-dropdown">
<a href="https://v2.canjs.com">2.3.27</a>
</div>
</div>
</div>
<div class="search-bar">
<p>
</p>
</div>
</div>
<div class="bottom-left">
<div class="social-side-container">
<ul class="social-side">
<li>
<a class="header-mobile github" href="https://github.com/canjs/canjs" target="_blank"><img class="social-icon-small" src="../../../docs/images/github.png">Github</a>
</li>
<li>
<a class="header-mobile twitter" href="https://twitter.com/canjs" target="_blank"><img class="social-icon-small" src="../../../docs/images/twitter.png">Twitter</a>
</li>
</ul>
<ul class="social-side">
<li>
<a class="header-mobile" href="https://gitter.im/canjs/canjs" target="_blank">Chat</a>
</li>
<li>
<a class="header-mobile" href="http://forums.donejs.com/c/canjs" target="_blank">Forum</a>
</li>
</ul>
</div>
<ul>
<li class="
parent
expanded">
<a class="page"
href="../../guides.html"
title="Welcome to CanJS! These guides are here to help you develop and improve your relationship with CanJS. After all, picking a JavaScript framework is a commitment. We want CanJS to be the
framework you marry. This page helps you know how advance through the different stages of this
relationship:">
Guides
</a>
<ul>
<li>
<span>introduction</span>
<ul>
<li class="
">
<a class="page"
href="../mission.html"
title="Learn about CanJS's mission, why it matters, and how we've worked (and will keep working) to accomplish it.">
Mission
</a>
</li>
<li class="
">
<a class="page"
href="../technical.html"
title="">
Technical Highlights
</a>
</li>
<li class="
">
<a class="page"
href="../who-uses-canjs.html"
title="">
Who uses CanJS?
</a>
</li>
</ul>
</li>
<li>
<span>experiment</span>
<ul>
<li class="
">
<a class="page"
href="../chat.html"
title="This guide walks through building real time chat application with CanJS's Core libraries. It takes about 30 minutes to complete.">
Chat Guide
</a>
</li>
<li class="
">
<a class="page"
href="../todomvc.html"
title="This guide walks through building a slightly modified version of TodoMVC with CanJS's Core libraries and can-fixture. It takes about 1 hour to complete.">
TodoMVC Guide
</a>
</li>
<li class="
">
<a class="page"
href="../atm.html"
title="This guide walks through building and testing an ATM application with CanJS's
Core libraries. It teaches how to do test driven development (TDD)
and manage complex state. It takes about 2 hours to complete.">
ATM Guide
</a>
</li>
<li class="
">
<a class="page"
href="../setup.html"
title="CanJS is packaged in multiple ways so that it can fit into any development workflow. Learn how to setup CanJS in different environments.">
Setting up CanJS
</a>
</li>
</ul>
</li>
<li>
<span>commitment</span>
<ul>
<li class="
">
<a class="page"
href="../api.html"
title="This page walks through how to use and understand CanJS's API documentation.">
API Guide
</a>
</li>
<li class="
">
<a class="page"
href="../examples.html"
title="">
Examples
</a>
</li>
<li class="
">
<a class="page"
href="../../roadmap.html"
title="Learn about CanJS's future plans and how we make them, and how you can influence them.">
Roadmap
</a>
</li>
<li class="
">
<a class="page"
href="../../migrate-3.html"
title="">
Migrating to 3.0
</a>
</li>
</ul>
</li>
<li>
<span>contribute</span>
<ul>
<li class="
">
<a class="page"
href="bug-report.html"
title="Learn how to submit a bug report.">
Bug Report
</a>
</li>
<li class="
">
<a class="page"
href="code.html"
title="Learn how contribute a code change to CanJS.">
Code
</a>
</li>
<li class="current
parent
expanded">
<a class="page"
href="documentation.html"
title="Learn how to improve CanJS's site and documentation.">
Documentation
</a>
</li>
<li class="
">
<a class="page"
href="evangelism.html"
title="Learn about resources that can help you spread the word about CanJS.">
Evangelism
</a>
</li>
<li class="
">
<a class="page"
href="feature-suggestion.html"
title="Learn how to suggest a feature.">
Feature Suggestion
</a>
</li>
<li class="
">
<a class="page"
href="releases.html"
title="Release and hosting information for CanJS maintainers.">
Releases
</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="
">
<a class="page"
href="../../can-core.html"
title="The best, most hardened and generally useful libraries in CanJS.">
Core
</a>
</li>
<li class="
">
<a class="page"
href="../../can-ecosystem.html"
title="Useful libraries that extend or add important features to the core collection.">
Ecosystem
</a>
</li>
<li class="
">
<a class="page"
href="../../can-infrastructure.html"
title="Utility libraries that power the core and ecosystem collection.">
Infrastructure
</a>
</li>
<li class="
">
<a class="page"
href="../../can-legacy.html"
title="Former libraries that we still accept patches for, but are not under active development.">
Legacy
</a>
</li>
</ul>
</div>
</div>
<div id="right" class="column">
<div class="top-right">
<div class="top-right-top">
<ul class="top-right-bitovi">
<li class="dropdown">
<a href="http://bitovi.com" class="bitovi icon-bits">Bitovi</a>
<ul class="dropdown-menu">
<li><a href="http://bitovi.com">Bitovi.com</a></li>
<li><a href="http://bitovi.com/blog/">Blog</a></li>
<li><a href="http://bitovi.com/consulting/">Consulting</a></li>
<li><a href="http://bitovi.com/training/">Training</a></li>
<li><a href="http://bitovi.com/open-source/">Open Source</a></li>
</ul>
</li>
</ul>
<div class="brand">
<div class="logo">
<a href="../../../index.html" alt="CanJS"></a>
</div>
</div>
<ul class="top-right-links">
<li>
<a href="https://gitter.im/canjs/canjs">Chat</a>
</li>
<li>
<a href="http://forums.donejs.com/c/canjs">Forum</a>
</li>
<li>
<a class="github-button nav-social" href="https://github.com/canjs/canjs" data-count-href="/canjs/canjs/stargazers" data-count-api="/repos/canjs/canjs#stargazers_count">Star</a>
</li>
<li>
<a href="https://twitter.com/canjs" class="twitter-follow-button nav-social" data-show-count="true" data-show-screen-name="false">Follow @canjs</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</li>
</ul>
</div>
<div class="breadcrumb">
<li><a href="../../../index.html">CanJS</a></li> /
<li><a href="../../guides.html">Guides</a></li> /
<li><a href="documentation.html">Documentation</a></li>
<li class="breadcrumb-dropdown">/ <a> On this page</a>
<ul class="on-this-page"></ul>
</li>
<div class="nav-toggle" title="Back to top"></div>
</div>
</div>
<div class="bottom-right">
<article>
<section class="title">
<div class="page-type">
<h1>Documentation</h1>
<div>page</div>
</div>
<section class="description">
<p>Learn how to improve CanJS's site and documentation.</p>
</section>
</section>
<section class="on-this-page-table">
</section>
<section class="title-footer">
<ul class="title-links">
<!-- <li><a href="#">docco</a></li> -->
<li><a href="//github.com/canjs/canjs/tree/v3.0.0/docs/can-guides/contribute/documentation.md">source</a></li>
<!-- <li><a href="#">download</a></li> -->
<!-- <li><a href="#">tests</a></li> -->
</ul>
</section>
<section class="body">
<h2>Overview</h2>
<p>The CanJS site is generated with <a href="https://github.com/bit-docs/bit-docs">bit-docs</a>,
a modified version of <a href="http://documentjs.com">DocumentJS</a>. Its
content is hosted using Github pages publishing the <a href="https://github.com/canjs/canjs/tree/gh-pages">canjs/canjs#gh-pages</a> repo.</p>
<p><code>bit-docs</code> reads JavaScript comments and markdown files within the <code>canjs</code> repo as well as
the individual repositories within <code>node_modules</code> to produce a static site.</p>
<p>The high level content (Ex: homepage) and the guides content for the site is within the
<code>canjs/docs</code> folder. Individual repositories contain their own markdown and commented
JavaScript files used to produce their API pages.</p>
<h2>Generate the documentation locally</h2>
<p>To generate the CanJS site:</p>
<ol>
<li><p>Clone <a href="https://github.com/canjs/canjs">https://github.com/canjs/canjs</a></p>
<pre><code>> git clone git@github.com:canjs/canjs
</code></pre></li>
<li><p>Install dependencies:</p>
<pre><code>> npm install
</code></pre></li>
<li><p>Run <code>bit-docs</code>:</p>
<pre><code>> ./node_modules/.bin/bit-docs -d
</code></pre></li>
</ol>
<p>This should produce a static site in your <code>canjs</code> folder. Open <code>canjs/index.html</code>
and you should see the site. You might want to use <a href="https://www.npmjs.com/package/http-server">http-server</a> to start
a simple static file server.</p>
<h2>Improve the theme's design and styles</h2>
<p>The CanJS theme is in
<a href="https://github.com/canjs/bit-docs-html-canjs">bit-docs-html-canjs</a>. It's
<a href="https://github.com/canjs/bit-docs-html-canjs/blob/master/readme.md">readme</a>
has instructions on how to test out the theme. Once the theme is updated and published,</p>
<ol>
<li>Open canjs/package.json. Update "bit-docs-html-canjs"'s version to the new theme version.</li>
<li>Run <code>./node_modules/.bin/bit-docs -df</code> to make sure the theme is correctly applied.</li>
</ol>
<h2>Test out content from other repos</h2>
<p>As noted above, the API docs from each package come from that package. So if you're
improving the docs for say <code>can-compute</code>, you want to see what <code>can-compute</code>'s docs look like,
install your local <code>can-compute</code> and re-run bit-docs like:</p>
<pre><code>> npm install ../can-compute && ./node_modules/.bin/bit-docs -d
</code></pre>
<h2>Publish the documentation</h2>
<p>Once the docs look right locally, commit your changes, then run:</p>
<pre><code>> make
</code></pre>
<p>The make script will generate the documentation again and push out the <code>gh-pages</code> branch.</p>
<h2>Writing API documentation</h2>
<p>Our documentation is modeled off of jQuery's. Please read
their <a href="https://github.com/jquery/api.jquery.com/blob/master/README.md">guidelines</a>. Also read our
<a href="../api.html" title="This page walks through how to use and understand CanJS's API documentation.">API Guide</a>.</p>
<p>Generally speaking there are three parts to every documentation page:</p>
<ul>
<li>Its description</li>
<li>Its signatures</li>
<li>The body (typically "Use" section)</li>
</ul>
<h3>Description</h3>
<p>The description section should be a one or two sentence explanation of what this
piece of documentation does from a <em>user</em> centric view. Descriptions are a quick summary
of the <strong>why</strong> and the <strong>what</strong>. It should take on an
active voice. For example, <a href="../../can-component.html" title="Create a custom element that can be used to manage widgets or application logic.">can-component</a>'s description:</p>
<blockquote>
<p>Create a custom element that can be used to manage widgets or application logic.</p>
</blockquote>
<p>Notice that it uses "Create" not "Creates".</p>
<h3>Signatures</h3>
<p>Signatures are the <strong>what</strong> and the <strong>how</strong>. They should include all or most of the following:</p>
<ul>
<li><strong>What the signature does</strong>, if different from the description, especially if there are
multiple signatures.</li>
<li>High level details on <strong>how the code works</strong>.</li>
<li>A simple example showing <strong>how to use the code</strong>.</li>
</ul>
<p><a href="../../can-compute.html" title="Create an observable value.">can-compute</a>'s first signature is a good example of this. First, it explains
<strong>what that signature does</strong>:</p>
<blockquote>
<p>Create a compute that derives its value from other observables.</p>
</blockquote>
<p>Then it briefly explains <strong>how the code works</strong>:</p>
<blockquote>
<p>Uses can-observation to call the getterSetter and track observables.</p>
</blockquote>
<p>Finally, it provides minimal sample code:</p>
<pre><code class="language-js">var age = compute(32);
var nameAndAge = compute(function(){
return "Matthew - " + age();
});
nameAndAge() // -> "Matthew - 32"
age(33);
nameAndAge() // -> "Matthew - 33"
</code></pre>
<p>Not all signatures need to hit all three points. For example <a href="../../can-event/batch/batch.html" title="Adds task batching abilities to event dispatching.">can-event/batch/batch</a>'s
signature simply adds a bit more depth to the purpose of <a href="../../can-event/batch/batch.html" title="Adds task batching abilities to event dispatching.">can-event/batch/batch</a>
and then details <strong>how the code works</strong>. <strong>How to use the code</strong> is
left for the <code>body</code> section as importing the module is not necessary to show.</p>
<p>Signature titles should follow jQuery's conventions:</p>
<ul>
<li>Static methods like: <code>TypeAlias.method()</code></li>
<li>Prototype methods like: <code>typeAlias.method()</code></li>
<li>Spaces in between arguments: <code>typeAlias.method( arg1, arg2 )</code></li>
<li>Brackets around optional args: <code>typeAlias.method( arg1 [, arg2 ], arg3 )</code> or
<code>typeAlias.method( arg1 [, arg2 ][, arg3 ] )</code></li>
</ul>
<p>Make sure to fully document the a signature's parameters and return
value. There's a lot of flexibility in documenting the <a href="http://documentjs.com/docs/documentjs.typeExpression.html">type expression</a> of
a return value or parameters and the <a href="http://documentjs.com/docs/documentjs.nameExpression.html">name expression</a> of
parameters.</p>
<ul>
<li>Parameter and descriptions should start with a <code>Capital</code> and end with a period like:
<code>@param {Type} name Indicates that something should happen.</code></li>
</ul>
<h3>body</h3>
<p>Most body sections start with a <code>## Use</code> subsection. This is a mini guide on
how to use that piece of code. Modules should have long bodies that span
multiple topics. For example <a href="../../can-component.html" title="Create a custom element that can be used to manage widgets or application logic.">can-component</a>'s body has examples and
information about nearly all of its sub-functions. However
<a href="../../can-component.prototype.tag.html" title="Specifies the HTML tag (or node-name) the can-component will be created on.">can-component.prototype.tag</a> doesn't have a
use section because it's covered in <a href="../../can-component.html" title="Create a custom element that can be used to manage widgets or application logic.">can-component</a>.</p>
<h3>structuring documentation</h3>
<ul>
<li>Group names (like <code>prototype</code>) should be lower case.</li>
<li>Types should be capitalized <code>{String}</code> except when they are describing a function <a href="../../can-fixture.requestHandler.html" title="">requestHandler</a>.</li>
</ul>
</section>
<script type="text/javascript">
var docObject = {"src":{"path":"docs/can-guides/contribute/documentation.md"},"description":"Learn how to improve CanJS's site and documentation. \n","name":"guides/contributing/documentation","title":"Documentation","type":"page","parent":"guides/contribute","comment":" ","pathToRoot":"../../.."};
</script>
</article>
<footer><p>CanJS is part of <a href="http://donejs.com" target="_blank">DoneJS</a>. Created and maintained by the core <a href="https://donejs.com/About.html#section=section_Team" target="_blank">DoneJS team</a> and <a href="http://bitovi.com" target="_blank">Bitovi</a>. <strong>Currently 3.0.0.</strong></p></footer>
</div>
</div>
</div>
<script>
steal = {
instantiated: {
"bundles/bit-docs-site/static.css!$css" : null
}
};
</script>
<script type='text/javascript' data-main="bit-docs-site/static" src="../../static/node_modules/steal/steal.production.js"></script>
<script async defer src="https://buttons.github.io/buttons.js"></script>
</body>
</html>