Code Monkey home page Code Monkey logo

dgeni-example's Introduction

What is Dgeni?

Dgeni is a documentation generator developed by the Angular team. Ironically it lacks documentation right now, so we try to develop a very simple step-by-step-guide here, until a better documentation is available. Please share and fork this repo.

Dgeni is currently used in these projects:

Why should I use Dgeni?

Dgeni seems to be very flexible, because it has a modular core and its extensibility with plugins. It seems to be relatively technology agnostic, so it should be good for HTML, CSS and JS documentation alike. It should be suitable for server components or REST API documentation, too. With custom plugins you can even create very framework-specific documentation - say treat controllers and directives similar to native primitives in Angular apps.

How do I install Dgeni?

Install Node, if you don't have it allready. After that you can install Dgeni and an additional module with basic plugins for Dgeni called dgeni-packages:

$ npm install --save-dev dgeni dgeni-packages

How can I use Dgeni with Grunt?

There is no official grunt task but using Dgeni with Grunt is pretty simple. Just create a custom task in your Gruntfile.js:

grunt.registerTask('dgeni', 'Generate docs via dgeni.', function() {
  var done = this.async();
  var dgeni = new Dgeni([require('./docs/dgeni-example')]);
  dgeni.generate().then(done);
});

You can execute this task via:

$ grunt dgeni

This task will load a Dgeni package at docs/dgeni-example.js, which tells Dgeni what to generate.

How can I use Dgeni with Gulp?

Gulp plugins are specifically for file manipulation with streams. Dgeni does not process files in a stream-like manner so it is not appropriate to build a Gulp plugin. Luckily, the way Gulp works it is really easy to run Dgeni from a task:

gulp.task('dgeni', function() {
  var dgeni = new Dgeni([require('./docs/dgeni-example')]);
  return dgeni.generate();
});

You can execute this task via:

$ gulp dgeni

This task will load a Dgeni package at docs/dgeni-example.js, which tells Dgeni what to generate.

How can I configure Dgeni?

Dgeni processing is configured by Dgeni Packages. You must provide at least one Package to tell Dgeni what files to read and how to process them. Check out the dgeni-example package in this project, at docs/dgeni-example.js.

How does Dgeni work?

Say we have a src/ with app.js and a script.js annotated with jsdocs:

// app.js
/**
 * @name log
 * @description This function logs a string.
 */

function log() {
  console.log('Logging.');
}
// script.js
/**
 * @name helloWorld
 * @description This function returns a string.
 *
 * @returns {string} This string has the value 'Hello World'.
 */

function helloWorld() {
  return 'Hello World';
}

We can tell Dgeni to read these these files and render docs based on nunjucks-templates by defining our own Dgeni Package:

// Canonical path provides a consistent path (i.e. always forward slashes) across different OSes
var path = require('canonical-path');

var Package = require('dgeni').Package;

// Create and export a new Dgeni package called dgeni-example. This package depends upon
// the jsdoc and nunjucks packages defined in the dgeni-packages npm module.
module.exports = new Package('dgeni-example', [
  require('dgeni-packages/jsdoc'),
  require('dgeni-packages/nunjucks')
])

// Configure our dgeni-example package. We can ask the Dgeni dependency injector
// to provide us with access to services and processors that we wish to configure
.config(function(log, readFilesProcessor, templateFinder, writeFilesProcessor) {

  // Set logging level
  log.level = 'info';

  // Specify the base path used when resolving relative paths to source and output files
  readFilesProcessor.basePath = path.resolve(__dirname, '..');

  // Specify collections of source files that should contain the documentation to extract
  readFilesProcessor.sourceFiles = [
    {
      // Process all js files in `src` and its subfolders ...
      include: 'src/**/*.js',
      // ... except for this one!
      exclude: 'src/do-not-read.js',
      // When calculating the relative path to these files use this as the base path.
      // So `src/foo/bar.js` will have relative path of `foo/bar.js`
      basePath: 'src'
    }
  ];

  // Add a folder to search for our own templates to use when rendering docs
  templateFinder.templateFolders.unshift(path.resolve(__dirname, 'templates'));

  // Specify how to match docs to templates.
  // In this case we just use the same static template for all docs
  templateFinder.templatePatterns.unshift('common.template.html');

  // Specify where the writeFilesProcessor will write our generated doc files
  writeFilesProcessor.outputFolder  = 'build';
});

We have a single nunjucks template that is used to render the documents. It is stored in docs/templates/common.template.html and looks like this:

<h1>{{ doc.codeName }} ({{ doc.outputPath }})</h1>
<p>{{ doc.description }}</p>

{% if doc.params %}
<h2>Params</h2>
<ul>
{% for param in doc.params %}
<li>
  <strong>{{ param.name }}</strong> { {{ param.typeList }} } - {{ param.description }}
</li>
{% endfor %}
</ul>
{% endif %}

{% if doc.returns %}
<h2>Returns</h2>
<p>
  { {{ doc.returns.typeList }} } - {{ doc.returns.description }}
</p>
{% endif %}

When we run Dgeni (say by running the Gulp or Grunt task defined above) you will get the following files, which refer to each of the jsdoc blocks that were read from the files:

greet.html

<h1>greet (greet.html)</h1>
<p>Display a greeting</p>

<h2>Params</h2>
<ul>
  <li>
    <strong>name</strong> { string } - The name of the person to greet
  </li>
</ul>

helloWorld.html

<h1>helloWorld (helloWorld.html)</h1>
<p>This function returns a string.</p>

<h2>Returns</h2>
<p>
  { string } - This string has the value 'Hello World'.
</p>

log.html

<h1>log (log.html)</h1>
<p>This function logs a string.</p>

myApp.html

<h1>myApp (myApp.html)</h1>
<p>My application</p>

dgeni-example's People

Contributors

donaldpipowitch avatar fvanderwielen avatar ocombe avatar petebacondarwin avatar sroe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dgeni-example's Issues

Grunt example is wrong

"dgeni": "^0.3.0",
"dgeni-packages": "^0.9.3",
"grunt": "~0.4.4",

require('dgeni') returns object making dgeni('docs/dgeni.conf.js') to fail

Markdown example

Hey, this may sound silly, but I cannot for the life of me work out how to process markdown documents for documentation.

I keep getting the following error:

error:   Error: No file reader found for /path/to/folder/dgeni-example/src/tutorials/GettingStarted.md
    at matchFileReader (/path/to/folder/dgeni-example/node_modules/dgeni-packages/base/processors/read-files.js:132:25)

dgeni-config.js (readFilesProcessor)

readFilesProcessor.sourceFiles = [{
    include: ['src/**/*.js', 'src/**/*.md'],
    exclude: 'src/do-not-read.js',
    basePath: 'src'
}];

From what I understand dgeni-packages/nunjucks supports parsing markdown as I can see it has the appropriate rendering tags.

Can you provide an example of parsing a markdown document in this example package please?

Variation: Create only one HTML for documentation

Hi @petebacondarwin,

most dgeni examples I saw so far show how one doc can be converted to one templated HTML. However I have trouble finding out how to generate just on big HTML - instead of multiple small ones.
Given the existing example with app.js and script.js what do I need to change in the config to generate a documentation like this?:

<!-- doc.html -->
<h1>helloWorld</h1>
<p>This function returns a string.</p>

<h2>Returns</h2>
<p>
  { string } - This string has the value 'Hello World'.
</p>

<h1>log</h1>
<p>This function logs a string.</p>

Please provide some info about variables available in template

I'm trying to bootstrap my own documentation app and stuck while making components tree template.
Is there any variable available in template except doc?
I've found that there is docs one.
Maybe there is some place where I can find all that variables?

Dgeni ES6

"Unexpected reserved word"

import {Angular} from 'angular';

"dgeni": "^0.4.1",
"dgeni-packages": "^0.10.13",

Starter example for angular

Hi,

thanks for the example. I am quite not sure, if it is an example for a custom documentation setup
or a full-fledged jsdoc or ngdoc starter setup.

If so, it would be great to provide an example how to have a ngdocs like documentation be generated.

Individual Page generation

From my brief experience with this tool, it seems too manual. I'd like a main page navigation page that breaks things down into modules and their components for easy navigation.

Writing processors for this tool is not something I'm interested in spending time on. Are there any plans for dgeni to do 'more' out of the box?

Dgeni is not defined

For some reasons when I launch the grunt task it says that Dgeni is not defined, even if Dgeni is installed (globally and locally), anybody else had the same issue?

Cannot find module './package

I may being doing something wrong, but It keeps failing when trying to run gulp dgeni with "Cannot find module './package'". the same happens when trying to run grunt dgeni.

I am using node v0.10.25. Maybe this is the issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.