Giter Club home page Giter Club logo

cod's Introduction

⚠️ No longer maintained ⚠️

cod is no longer being updated or maintained.

Take a look at jaames/cod for a modernized rewrite if you're interested in trying cod but are having trouble getting this repo building/running locally.

cod

An unassuming documentation format that works with any language.


/**
@Example
  Text can go anywhere.
     Whitespace is preserved.
  @flag
  @number 42
  @string Hello, cod
  @nested
    @property yay
    Nested text.
  @list A
  @list B
  @list C
*/
{
  "Example": {
    "!text": "Text can go anywhere.\n   Whitespace is preserved.",
    "flag": true,
    "number": 42,
    "string": "Hello, cod",
    "nested": {
      "!text": "Nested text.",
      "property": "yay"
    },
    "list": ["A", "B", "C"]
  }
}

stupid by design

cod is not a documentation generator.

It is a documentation format that outputs nearly "1-to-1" JSON.

cod does zero code analysis.

cod doesn't know what @class, @return, @param or @any @other tag means.

cod does not generate HTML, PDFs, or any traditionally human-readable documentation; that part is left up to you.

As such, cod is not a standalone replacement for tools like doxygen or Sphinx, but it functions as the first step in a more flexible doc-generation process for those who need finer control.

cod may not be smart, but it's not stubborn, either.

You write your docs in cod's format, and it faithfully outputs JSON. That's it.

Use whatever tags you need.

Anything that isn't a @tag is text.

Text sections are left untouched. You can process it as Markdown later. Or HTML. Or just keep it as plain text.

Once you have the JSON, use it however you like:

  • Utilize existing templates and styles.
  • Build an app that can consume multiple versions of your API docs.
  • Easily compare specific versions of your API at the structural level.

cod is naturally language-agnostic; all it needs to know is the pattern you use to denote a doc-block (i.e. /** and */).

format

Tags without values are treated as boolean flags:

@flag
{
  "flag": true
}

There are also numbers and strings, and you can explicitly set a flag to false:

@number 42
@string Hello there.
@boolean false
{
  "number": 42,
  "string": "Hello there.",
  "boolean": false
}

Structure is designated by indentation.

@root
  @nested value
{
  "root": {
    "nested": "value"
  }
}

Whitespace after indentation is preserved in text blocks.

@example
  This is some example text.

  It can handle multiple lines.
    Indentation is preserved.
{
  "example": {
    "!text": "This is some example text.\n\nIt can handle multiple lines.\n  Indentation is preserved."
  }
}

Specifying a @tag more than once will turn it into a list of values.

@list A
@list B
@list C
{
  "list": [
    "A",
    "B",
    "C"
  ]
}

@tags:like:this are equivalent to nested tags.

@root:inline:nested value
{
  "root": {
    "inline": {
      "nested": "value"
    }
  }
}

Values of tags that have nested properties or text bodies are stored as @complexProperty["!value"].

@simpleTag 100

@complexTag This will be stored as example["!value"]
  This allows for nested text and tags.
  @likeThis
{
  "simpleTag": 100,
  "complexTag": {
    "!value": "This will be stored as example[\"!value\"]",
    "!text": "This allows for nested text and other properties.",
    "likeThis": true
  }
}

CLI

cod *.js # or *.go or *.c or ...
cod -b '###*' -e '###' *.coffee
cod -b "'''*" -e "'''" *.py
cod -b '{-*' -e '-}' *.hs
cod -b '--[[*' -e ']]' *.lua
cat *.js | cod  > api.json
cod --help
              ,
           _-""-,-"'._         
     .-*'``           ``-.__.-`:
  .'o   ))` ` ` ` ` ` `_`.---._:
   `-'.._,,____...--*"` `"     
         ``
cod: An unassuming documentation generator.

Usage:
  cod [-b <doc-begin> -e <doc-end>] [-o <output-file>] [-u] [<input-file>...]
  cod -h | --help | --version

Options:
  -b <doc-begin>    String that marks the start of a doc-block [default: /**]
  -e <doc-end>      String that marks the end of a doc-block [default: */]
  -o <output-file>  Output file [default: STDOUT]
  -u --ugly         Output non-pretty JSON.
  -v --version      Show version.
  -h --help         Show this screen.
  <input-file>...   File(s) containing docs. If none, cod reads from STDIN.

gulp

See gulp-cod.

Grunt

Create an issue if you make a Grunt plugin for cod, and I'll list it here.

API

If text is supplied, cod will parse it and return a plain JS object that contains your doc structure.

Otherwise, cod will return a Transform stream into which your source can be piped. cod will buffer the stream until completion, after which it will output the stringified JSON of your doc's structure.

text (String | Buffer)

Text containing cod-style documentation. Probably source code.

options (Object)

docBegin (String) default: "/**"

String that marks the start of a doc-block

docEnd (String) default: "*/"

String that marks the end of a doc-block

pretty (boolean) default: true

Format the JSON output with JSON.stringify(doc, null, 2) Only applicable in stream mode when text is not supplied

var cod = require('cod');
var doc;

doc = cod([
  '/**',
  'Hello, cod.',
  '@answer 42',
  '*/'
].join('\n'));

console.dir(doc); 

// Output:
// { '!text': 'Hello, cod.', 'answer': 42 }
var fs = require('fs'),
    cod = require('cod');

// file.coffee:
//
// ###*
// Hello, cod.
// @answer 42
// ###
//

fs.createReadStream(__dirname + '/file.coffee')
  .pipe(cod({
    docBegin: '###*',
    docEnd: '###',
    pretty: false
  }))
  .pipe(process.stdout);

// Output:
// {"!text":"Hello, cod.","answer":42}

install

npm install -g cod

license

MIT


Analytics

cod's People

Contributors

namuol 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

Watchers

 avatar  avatar  avatar  avatar

cod's Issues

Intelligently preserve horizontal whitespace in text-blocks.

A lot of people (myself included) want to use Markdown or other whitespace-sensitive languages within their docs' text blocks.

Text-block indentation currently causes some unexpected problems, mostly due to how indentation is detected in the parser.

The parser needs to ignore any indentation that occurs inside a text block once its indentation level has been established, unless it de-indents from the previously-established indentation level.

Example (indentation shown as ..):

@test
..This is an indent
..  this is not
..I can have any whitespace
..   in this text block
..     so long as it
..  stays within the
.. bounds of
..the previous indentation
..
This is a de-indent.

The resulting value of {"test": "!text": (...)} would appear like so:

This is an indent
  this is not
I can have any whitespace
   in this text block
     so long as it
  stays within the
 bounds of
the previous indentation

Support for single-line comments and JavaDoc-like style

Suppose your language only supports single-line comments that start with #.

Your docs might look something like this:

##
# @MyClass
#
#   I can see why some might prefer this.
#
##

But you may also just want this:

/**
 * @MyClass
 *
 *   "It just looks tidier," some might say.
 * 
 */

I'd propose another option called "trim" that is a string to remove from the beginning of any line.

The default should be * and it should always be optional; i.e. this will still work:

/**
 * @MyClass
 *
 *   "It just looks tidier," some might say.
 * 
 */

/**
  @MyClass:property

    But here I just didn't feel like using that style.

*/

Acknowledging Cod in Similar Project

Ciao @namuol!

I wanted to inform you that I'm acknowledging you and Cod in an app I've just published on GitHub (inside another project for now, it's still in Alpha):

The acknowledgments can be found in the (self-generated) documentation (Live HTML link):

Although my app is quite a different beast from yours (not a fish at all), Cod has provided the sparkle of inspiration to find a custom solution to a problem I had been struggling with for quite some time. So I like to give credits where credits are due.

I didn't peak at Cod's source at all, I just took inspiration from its documentation, and the way language agnostic tags were being parsed into regions. That was enough to give me that Eureka! moment where I could see the solution in front of me.

Best regards,

Tristano Ajmone (Italy)

"bare" tag reopening

The ability to re-open tags at their root level so we can do this:

/**
@Something
  @number 42
*/

// Later...

/**
@Something:
  @number 43
  @number 44
  @number 45
*/

...instead of this:

/**
@Something
  @number 42
*/

// Later...

/**
@Something:number 43
@Something:number 44
@Something:number 45
*/

Is this still active?

Hi there

Would be interested in maintaining this and using it as a basis for a language-agnostic docgen tool.

What's your status?

Immediate text inside list items isn't parsed

The following produces unexpected results:

/**
@list
  @item val1
    text 1
  @item val2
    text 2
*/

Expected results:

{
  "list": {
    "item": [
      {
        "!value": "val1",
        "!text": "text 1"
      },
      {
        "!value": "val2",
        "!text": "text 2"
      }
    ]
  }
}

Actual results:

{
  "list": {
    "item": [
      {
        "!value": "val1",
        "!text": "text 1"
      },
      "val2"
    ]
  }
}

Note: Placing a tag before the text 2 piece yields correct results; that is, this only happens in the case where the second @item is immediately followed by a text block. Furthermore, a value must be specified as well.

These all behave as expected:

/**
@list
  @item val1
    text 1
  @item
    text 2
*/
/**
@list
  @item val1
    text 1
  @item val2
    @tag
    text 2
*/

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.