2017-07-15 11:38:10 -04:00
|
|
|
# Overview
|
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
[Plunker](http://plnkr.co) is an online tool for creating, collaborating and sharing ideas. In AIO
|
|
|
|
we use it to share one or more runnable versions of our examples.
|
2017-07-15 11:38:10 -04:00
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
Plunker comes in two flavours. The [classic UI](http://plnkr.co/edit) and an [embedded UI](http://embed.plnkr.co).
|
|
|
|
The latter can be used both in a new tab or embedded within a guide. The AIO project uses the
|
|
|
|
embedded version in both ways.
|
|
|
|
|
|
|
|
* `regularPlunker.js` - generates an HTML file for each example that will post to Plunker to create
|
|
|
|
a new editable project, when rendered.
|
|
|
|
* `embeddedPlunker.js` - generates an HTML file for each example that can be used in an iframe to
|
|
|
|
render an embedded Plunker project.
|
|
|
|
* `generatePlunkers.js` - executes each of the `regularPlunker.js` and `embeddedPlunker.js` utilities
|
|
|
|
to generate all the example plunker files.
|
2017-07-15 11:38:10 -04:00
|
|
|
|
2017-07-19 10:32:28 -04:00
|
|
|
## Plunker generation
|
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
Both flavours are created within `builder.js`. How is a plunker created? What is the process from a
|
|
|
|
directory with files to a link with a plunker.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
An "executable" plunker is an HTML file with a `<form>` that makes a post to plunker on submit. It
|
|
|
|
contains an `<input>` element for each file we need in the plunker.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
The form will be submitted on load, so you can either double click the HTML file or open it with an
|
|
|
|
anchor tag to open the plunker.
|
2017-07-31 07:34:22 -04:00
|
|
|
|
2017-07-19 10:32:28 -04:00
|
|
|
So the `builder.js` job is to get all the needed files from an example and build this HTML file for you.
|
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
For plunkers, we use a special `systemjs.config` that exists in
|
|
|
|
`/aio/tools/examples/shared/boilerplate/src/systemjs.config.web.js` and we also add the Google's copyright
|
|
|
|
to each file.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
|
|
|
## Customizing the generation per example basis
|
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
How does this tool know what is an example and what is not? It will look for all folders containing a
|
|
|
|
`plnkr.json` file. If found, all files within the folder and subfolders will be used in the plunker, with
|
|
|
|
a few generic exceptions that you can find at `builder.js`.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
|
|
|
You can use the `plnkr.json` to customize the plunker generation. For example:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"description": "Tour of Heroes: Part 6",
|
|
|
|
"basePath": "src/",
|
|
|
|
"files":[
|
|
|
|
"!**/*.d.ts",
|
|
|
|
"!**/*.js",
|
|
|
|
"!**/*.[1,2].*"
|
|
|
|
],
|
|
|
|
"tags": ["tutorial", "tour", "heroes", "http"]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
Here you can specify a description for the plunker, some tags, a basePath and also a files array where you
|
|
|
|
can specify extra files to add or to ignore.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
|
|
|
## Classic plunkers and embedded ones
|
|
|
|
|
2017-07-31 07:34:22 -04:00
|
|
|
Luckily, both kind of plunkers are very similar, they are created in the same way with minor exceptions.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
To handle those exceptions, we have the `embeddedPlunker.js` and the `regularPlunker.js`. Thanks to them,
|
|
|
|
the `builder.js` is as generic as possible.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
|
|
|
## Executing the plunker generation
|
|
|
|
|
2017-07-31 07:34:22 -04:00
|
|
|
`generatePlunkers.js` will create a classic plunker and an embedded plunker for each `plnkr.json` it finds.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
2017-07-31 07:34:22 -04:00
|
|
|
Where? At `src/generated/live-examples/`.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
Then the `<live-example>` embedded component will look at this folder to get the plunker it needs for the
|
|
|
|
example.
|
2017-07-19 10:32:28 -04:00
|
|
|
|
2017-07-31 07:34:22 -04:00
|
|
|
## Appendix: Why not generating plunkers at runtime?
|
2017-07-19 10:32:28 -04:00
|
|
|
|
2017-09-21 06:16:27 -04:00
|
|
|
At AngularJS, all the plunkers were generated a runtime. The downside is that all the example codes would
|
|
|
|
need to be deployed as well and they won't be no longer useful after the plunker is generated. This tool
|
|
|
|
takes a few seconds to run, and the end result is only 3mb~.
|