Update docs

This commit is contained in:
Chris de Graaf 2017-08-22 11:25:00 -05:00
parent 580e1c212c
commit 3c05c3f9d5
3 changed files with 28 additions and 36 deletions

View File

@ -21,7 +21,7 @@ GenericPlugin
CustomPlugin CustomPlugin
``` ```
### `CustomPlugin` required methods ### `CustomPlugin` Required Methods
#### `gen_plugin` #### `gen_plugin`
@ -30,8 +30,8 @@ gen_plugin
interactive interactive
``` ```
**Note**: `interactive` is not strictly required, however without it, your custom plugin **Note**: [`interactive`](@ref) is not strictly required, however without it, your custom
will not be available when creating templates with [`interactive_template`](@ref). plugin will not be available when creating templates with [`interactive_template`](@ref).
#### `badges` #### `badges`

View File

@ -282,31 +282,13 @@ end
""" """
substitute(template::AbstractString, view::Dict{String, Any}) -> String substitute(template::AbstractString, view::Dict{String, Any}) -> String
Replace placeholders in `template` with values in `view`. `template` is not modified. Replace placeholders in `template` with values in `view` via
[`Mustache`](https://github.com/jverzani/Mustache.jl). `template` is not modified.
# Notes For information on how to structure `template`, see "Defining Template Files" section in
Due to a bug in `Mustache`, conditionals often insert undesired newlines (more detail [Custom Plugins](@ref).
[here](https://github.com/jverzani/Mustache.jl/issues/47)).
For example: **Note**: Conditionals in `template` without a corresponding key in `view` won't error,
```
A
{{#B}}B{{/B}}
C
```
When `view` doesn't have a `"B"` key (or it does, but it's false), this becomes
`"A\\n\\nC"` We can get around this by writing ugly template files, like so:
```
A{{#B}}
B{{/B}}
C
```
In this case, the result is `"A\\nB\\nC"`, like we want it to be.
Also note that conditionals without a corresponding key in `view` won't error,
but will simply be evaluated as false. but will simply be evaluated as false.
""" """
substitute(template::AbstractString, view::Dict{String, Any}) = render(template, view) substitute(template::AbstractString, view::Dict{String, Any}) = render(template, view)

View File

@ -10,7 +10,7 @@ Generic plugins are plugins that add any number of patterns to the generated pac
to an empty string, there should be a default file in `defaults` that will be copied. to an empty string, there should be a default file in `defaults` that will be copied.
That file's name is usually the same as the plugin's name, except in all lowercase and That file's name is usually the same as the plugin's name, except in all lowercase and
with the `.yml` extension. If this is not the case, an `interactive` method needs to be with the `.yml` extension. If this is not the case, an `interactive` method needs to be
implemented to call `interactive(; file="other-filename.ext")`. implemented to call `interactive(; file="file.ext")`.
* `dest::AbstractString`: Path to the generated file, relative to the root of the generated * `dest::AbstractString`: Path to the generated file, relative to the root of the generated
package repository. package repository.
* `badges::Vector{Badge}`: Array of [`Badge`](@ref)s containing information used to * `badges::Vector{Badge}`: Array of [`Badge`](@ref)s containing information used to
@ -59,16 +59,16 @@ interactive(plugin_type::Type{MyPlugin}) = interactive(plugin_type; file="my-plu
The above plugin ignores files ending with `.mgp`, copies `defaults/my-plugin.toml` by The above plugin ignores files ending with `.mgp`, copies `defaults/my-plugin.toml` by
default, and creates a badge that links to the project on its own site, using the default default, and creates a badge that links to the project on its own site, using the default
substitutions with one addition: `{{YEAR}} => Dates.year(now()`. Since the default substitutions with one addition: `{{YEAR}} => Dates.year(now()`. Since the default config
config template file doesn't follow the generic naming convention, we added another template file doesn't follow the generic naming convention, we added another `interactive`
`interactive` method to correct the assumed filename. method to correct the assumed filename.
""" """
abstract type GenericPlugin <: Plugin end abstract type GenericPlugin <: Plugin end
""" """
Custom plugins are plugins whose behaviour does not follow the [`GenericPlugin`](@ref) Custom plugins are plugins whose behaviour does not follow the [`GenericPlugin`](@ref)
pattern. They can implement [`gen_plugin`](@ref) and [`badges`](@ref) in any way they pattern. They can implement [`gen_plugin`](@ref), [`badges`](@ref), and
choose. [`interactive`](@ref) in any way they choose.
# Attributes # Attributes
* `gitignore::Vector{AbstractString}`: Array of patterns to be added to the `.gitignore` of * `gitignore::Vector{AbstractString}`: Array of patterns to be added to the `.gitignore` of
@ -117,11 +117,21 @@ choose.
end end
end end
end end
interactive(plugin_type::Type{MyPlugin}) = MyPlugin()
``` ```
This plugin doesn't do much, but it demonstrates how [`gen_plugin`](@ref) and This plugin doesn't do much, but it demonstrates how [`gen_plugin`](@ref), [`badges`](@ref)
[`badges`](@ref) can be implemented using [`substitute`](@ref), [`gen_file`](@ref), and [`interactive`](@ref) can be implemented using [`substitute`](@ref),
[`Badge`](@ref), and [`format`](@ref). [`gen_file`](@ref), [`Badge`](@ref), and [`format`](@ref).
# Defining Template Files
Often, the contents of the config file that your plugin generates depends on variables like
the package name, the user's username, etc. Template files (which are stored in `defaults`)
can use [here](https://github.com/jverzani/Mustache.jl)'s syntax to define replacements.
**Note**: Due to a bug in `Mustache`, conditionals can insert undesired newlines
(more detail [here](https://github.com/jverzani/Mustache.jl/issues/47)).
""" """
abstract type CustomPlugin <: Plugin end abstract type CustomPlugin <: Plugin end
@ -203,7 +213,7 @@ end
""" """
interactive( interactive(
plugin_type::Type{P <: Plugin}; plugin_type::Type{P <: Plugin};
file::Union{AbstractString, Void}, file::Union{AbstractString, Void}="",
) -> Union{Plugin, Void} ) -> Union{Plugin, Void}
Interactively create a plugin of type `plugin_type`, where `file` is the plugin type's Interactively create a plugin of type `plugin_type`, where `file` is the plugin type's