Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.

External Examples #182

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

External Examples #182

wants to merge 2 commits into from

Conversation

wolf-daniel
Copy link

We found it too cumbersome to write the actual example code/files inline in the documentation markdown.

We thought that being able to have the examples in external files on the filesystem, could be better due to several reasons:

  1. Using external files, one could test these examples independently from the ngdocs mechanism. They would be little, actual, runnable web applications.
  2. Much easier to write code and markup in real files.
  3. Much easier to read the source files later, when the documentation blocks are not massive.
  4. Easier to maintain.

The path we took is defining a new annotation, called '@external-example' which is in fact parsed by the grunt-ngdocs plugin.
The hint given to this annotation, i.e. '@external-example:my.example' will look for a directory named 'my/example/' under the base examples directory in the project (by default, a directory named 'examples' under the root dir). All of the files in this example directory will become blocks in the markdown.

Moreover, if the index.html of the example is in fact a full-blown HTML (with and other resources) - the '@external-example' would know to take only the section, since the HTML in the embedded documentation would be generated automatically later.

The base examples directory can be configured in the grunt-ngdocs plugin, the following way:

ngdocs: {
options: {
examplesDir: "my-custom-examples-dir"
}
}

I hope this is clear and useful to others.
Thanks in any case,
Daniel

The idea is that writing <example> in the actual code is very clumsy and messy.
We'd rather have external files that hold the examples, and can even be run separately, without using any ngdocs compiler.

We incorporate those external examples using a hint in the documentation itself:

@external-example:some.example

This will look for a directory named 'example' inside another directory named 'some', under the base examples directory (which can be configured in the Gruntfile, and is named 'examples' by default).
Every file under that directory will become a <file> in the documentation.
The AngularJS module will have the name of the example, i.e. 'some.example'.

HTML files that are used this way can be real, full HTMLs.
The plugin will know to only take the <body> part and include it in the <file> section.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant