GitXplorerGitXplorer
c

api_doc_updater

public
1 stars
1 forks
2 issues

Commits

List of commits on branch master.
Unverified
7ac0a50cc940af224d2b1aecab5b8028ab7faca4

Mark as deprecated, and link to replacement

cchalin committed 7 years ago
Unverified
94bd64be89281a111ec717328b6c8e9f2e400986

Enable build and test on Travis (#5)

cchalin committed 8 years ago
Unverified
f90c52a7535d05cd8e2a7ce1a93ca3759852c4c4

Remove fragment's trailing blank lines (#4)

cchalin committed 8 years ago
Unverified
64b5c744f6253fe0bdf93b2dbfe9112436cff012

Trim whitespace from code fragment lines (#1)

cchalin committed 8 years ago
Unverified
c7acfa8efd142732e285574be9e2ac58d0185816

First release

cchalin committed 8 years ago
Unverified
a7f6c893ce0a976eb86d5377cd17130ea8df396f

Initial commit

cchalin committed 8 years ago

README

The README file for this repository.

DEPRECATED - Dart API doc source-code-fragment updater

Superseded by https://github.com/chalin/code_excerpt_updater.

This is the repo for a simple line-based Dart API doc updater for {@source} code fragment directives. That is, the updater processes input source files line-by-line, looking for {@source} directives contained within public API markdown code blocks.

Usage

Use the api_doc_updater tool to update code fragments marked with {@source} directives in Dart API docs.

Usage: api_doc_updater [OPTIONS] dart_file_or_directory...

-p, --fragment-path-prefix    Path prefix to directory containing code fragment files.
                              (Default is current working directory.)

-h, --help                    Show command help.
-i, --in-place                Update files in-place.

For example, you could run the updater over AngularDart source as follows:

angular2> dart ../api_doc_updater/bin/api_doc_updater.dart -p doc/api/_fragments/ -i lib

@source syntax

Because this is a simple line-based processing tool, the {@source} directive syntax is strict to avoid misinterpreting occurrences of @source in Dart code (vs. public API doc comments), that are not {@source} code fragment directives.

The updater only processes {@source} directives in public API doc comments; these are expected to be contained in code markdown blocks like this:

/// ```lang
/// {@source "relative/path/to/fragment/file.ext" region="region-name"}
/// ...
/// ```

Notes:

  • The {@source token can optionally be preceded by an (open) comment token such as // or <!--.
  • Path, and region name if given, must be enclosed in double quotes.
  • region is optional.
  • Whitespace is significant: for example, the opening token has no space between the { and the @source.

Code fragment updating

The updater does not create code fragment files, but it does expect such files to exist and be named following the conventions described below.

For a directive like {@source "dir/file.ext" region="rname"}, the updater will search the fragment folder, for a file named:

  • dir/file-rname.ext.txt
    or
  • dir/file.ext.txt
    if the region is omitted

If the updater can find the fragment file, it will replace the lines contained within the directive's markdown code block with those from the fragment file, indenting each fragment file line with the same indentation as the {@source} directive itself. For example, if hello.dart.txt contains the line "print('Hi');" then

/// ```dart
///   // {@source "hello.dart"}
///   print('Bonjour');
/// ```

will be updated to

/// ```dart
///   // {@source "hello.dart"}
///   print('Hi');
/// ```

Example

Consider the following API doc excerpt from the NgStyle class.

    /// ### Examples
    ///
    /// Try the [live example][ex] from the [Template Syntax][guide] page. Here are
    /// the relevant excerpts from the example's template and the corresponding
    /// component class:
    ///
    /// ```html
    /// <!-- {@source "docs/template-syntax/lib/app_component.html" region="NgStyle"} -->
    /// ```
    ///
    /// ```dart
    /// // {@source "docs/template-syntax/lib/app_component.dart" region="NgStyle"}
    /// ```

Given an appropriate path to the folder containing code fragment files, this update tool would generate:

    /// ### Examples
    ///
    /// Try the [live example][ex] from the [Template Syntax][guide] page. Here are
    /// the relevant excerpts from the example's template and the corresponding
    /// component class:
    ///
    /// ```html
    /// <!-- {@source "docs/template-syntax/lib/app_component.html" region="NgStyle"} -->
    /// <div>
    ///   <p [ngStyle]="setStyle()" #styleP>Change style of this text!</p>
    /// 
    ///   <label>Italic: <input type="checkbox" [(ngModel)]="isItalic"></label> |
    ///   <label>Bold: <input type="checkbox" [(ngModel)]="isBold"></label> |
    ///   <label>Size: <input type="text" [(ngModel)]="fontSize"></label>
    /// 
    ///   <p>Style set to: <code>'{{styleP.style.cssText}}'</code></p>
    /// </div>
    /// ```
    ///
    /// ```dart
    /// // {@source "docs/template-syntax/lib/app_component.dart" region="NgStyle"}
    /// bool isItalic = false;
    /// bool isBold = false;
    /// String fontSize = 'large';
    /// String fontSizePx = '14';
    /// 
    /// Map<String, String> setStyle() {
    ///   return {
    ///     'font-style': isItalic ? 'italic' : 'normal',
    ///     'font-weight': isBold ? 'bold' : 'normal',
    ///     'font-size': fontSize
    ///   };
    /// }
    /// ```

Tests

Repo tests can be launched from test/main.dart.