Git Product home page Git Product logo

ember-cli-addon-docs-yuidoc's Introduction

This project uses GitHub Actions for continuous integration.

ember-cli-addon-docs-yuidoc

YUIDoc plugin for Ember CLI Addon Docs. This plugin adds automatic API documentation to your addon through a modified version of YUIDoc with support for:

  • Modules
  • Plain, non-class functions and constants
  • Classes
    • Added support for accessors and fields
  • Components (including arguments and yields)
  • Helper functions
  • Markdown in comments

Compatibility

  • Ember.js v3.16 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above

Installation

ember install ember-cli-addon-docs-yuidoc

Usage

Documenting a Class

You can document classes using standard YUIDoc syntax with a few modifications

  • You can use @field as an alias for @property
  • You can use @accessor to reference a native getter/setter, or @computed for an Ember computed. These document the same, but @computed assumes a setter exists, whereas @accessor requires you to add the @set tag.
  • You can add @static, @async, and @generator modifiers to methods
/**
  A foo class

  @class Foo
  @anArbitraryTag
  @public
*/
export default class Foo {
  /**
    A field named foo

    @field foo
    @type number
  */
  foo = 123;

  /**
    An accessor named baz

    @accessor baz
    @type any
    @set
  */
  get bar() {
    return this._baz;
  }

  set bar(val) {
    this._baz = val;
  }

  /**
    A static async method named grault

    @method grault
    @static
    @async
  */
  static async baz() {
    // ...
  }
}

Documenting Components

Components can be documented the same as classes, and will be automatically detected based on folder structure. They also have two extra types of properties:

  • @yield which must be applied to the class itself
  • @argument which is meant to represent an argument passed into the component
/**
  A foo-bar component. Usage:

  ```hbs
    {{#foo-bar baz=123 as |hash|}}

    {{/foo-bar}}
  ```

  @class FooBarComponent
  @yield {Hash} hash
  @yield {number} hash.foo
*/
export default Ember.Component.extend({
  /**
    @argument baz
    @type {number}
  */
  baz: -1
});

Documenting Modules

Modules will automatically be detected - no need to use @module. You can use the following tags:

  • @function documents plain functions
  • @variable, @const, or @constant documents variable values
  • @export [named|default] specifies the export type
    • Classes are considered the default export unless specified otherwise, functions and variables are considered named unless specified otherwwise.
/**
  @class Foo
  @export named
*/
export class Foo {}

/**
  @function bar
  @export default
*/
export default function bar() {}

/**
  @const baz
  @type {number}
*/
export const baz = 123;

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

ember-cli-addon-docs-yuidoc's People

Contributors

allthesignals avatar btecu avatar dependabot-preview[bot] avatar dependabot[bot] avatar ef4 avatar ember-tomster avatar esbanarango avatar heroiceric avatar ijlee2 avatar kdagnan avatar pzuraq avatar robbiethewagner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-cli-addon-docs-yuidoc's Issues

TypeError: Cannot read property 'methods' of undefined

Not sure what exactly is going on here, but I've gotten the following error when trying to port the docs for ember-intl to use ember-cli-addon-docs:

TypeError: Cannot read property 'methods' of undefined
    at generateYuiDocJsonApi (/Users/tbieniek/Code/ember-intl/node_modules/ember-cli-addon-docs-yuidoc/lib/preprocessors/generate-yuidoc-jsonapi.js:70:13)
    at DocsGenerator.build (/Users/tbieniek/Code/ember-intl/node_modules/ember-cli-addon-docs-yuidoc/lib/broccoli/generator.js:23:16)
    at /Users/tbieniek/Code/ember-intl/node_modules/broccoli-caching-writer/index.js:149:21
    at tryCatch (/Users/tbieniek/Code/ember-intl/node_modules/rsvp/dist/rsvp.js:525:12)
    at invokeCallback (/Users/tbieniek/Code/ember-intl/node_modules/rsvp/dist/rsvp.js:538:13)
    at publish (/Users/tbieniek/Code/ember-intl/node_modules/rsvp/dist/rsvp.js:508:7)
    at flush (/Users/tbieniek/Code/ember-intl/node_modules/rsvp/dist/rsvp.js:2415:5)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Documenting Component Composition

I'm writing docs for ember-animated. There are a lot of shared arguments because we composed components out of other components. Here is an example where key, use, rules, etc are all shared options that should share the same documentation as on the animated-each.

It seems like the @uses feature in the yuidoc could handle this case but it doesn't work.

Cannot read property 'push' of undefined

I get this error on 'ember serve' with a fresh master of "ember-cli-addon".

"error.dump.c5baf14fda76f05db0477fbf39589732.log":

Cannot read property 'push' of undefined
  - name: Error
  - nodeAnnotation: DocsGenerator
  - nodeName: DocsGenerator
  - originalErrorMessage: Cannot read property 'push' of undefined
  - stack: TypeError: Cannot read property 'push' of undefined
    at generateYuiDocJsonApi (C:\Users\kudgo\workspace\ember-cli-addon-docs\node_modules\ember-cli-addon-docs-yuidoc\lib\preprocessors\generate-yuidoc-jsonapi.js:76:22)
    at DocsGenerator.build (C:\Users\kudgo\workspace\ember-cli-addon-docs\node_modules\ember-cli-addon-docs-yuidoc\lib\broccoli\generator.js:23:16)
    at C:\Users\kudgo\workspace\ember-cli-addon-docs\node_modules\broccoli-caching-writer\index.js:149:21
    at tryCatch (C:\Users\kudgo\workspace\ember-cli-addon-docs\node_modules\rsvp\dist\rsvp.js:525:12)
    at invokeCallback (C:\Users\kudgo\workspace\ember-cli-addon-docs\node_modules\rsvp\dist\rsvp.js:538:13)
    at publish (C:\Users\kudgo\workspace\ember-cli-addon-docs\node_modules\rsvp\dist\rsvp.js:508:7)
    at flush (C:\Users\kudgo\workspace\ember-cli-addon-docs\node_modules\rsvp\dist\rsvp.js:2415:5)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

=================================================================================

The error happens in

klass.arguments.push(new Argument(item));
tries to push to the non-existing Class instance's arguments property.

YUIDoc issue w/ @ character, e.g. decorators and angle brackets

Actually I haven't experienced an issue here (as I am not using), but still opening this as I am pretty sure users of this addon will eventually be hit by the same underlying issue of YUIDoc: yui/yuidoc#347.

Basically any code sample that starts with an @ sign will fail to parse correctly, which will be the case for decorators or multiline angle bracket invocation.

Related: emberjs/ember.js#18063 (comment)

A possible workaround is to escape the @ sign and unescape when rendering (see the PRs linked to the above issue, or ember-bootstrap/ember-bootstrap#829)

Example of working `@extends`?

I have components that extend from a base component. I'd like them to inherit the documentation from the base component but when using @extends it doesn't seem to give me the result I'm looking for.

In my base class:

/**
 * The base component
 * 
 * @class BaseComponent
 * @interface BaseComponentArgs
 * @export default
 * @public
 */

In my extended components:

/**
 * Extended component
 *
 * @class ExtendedComponent
 * @extends BaseComponent
 */

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.