Skip to content

Commit

Permalink
Rename filename to file
Browse files Browse the repository at this point in the history
`filename` is still available in the template rendering context.
  • Loading branch information
rossmacarthur committed Apr 27, 2020
1 parent f8d5647 commit c62600a
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 118 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ variable. A plugin will apply a template if you add the template name to the

Available built in templates are

- **source**: source each filename in a plugin.
- **source**: source each file in a plugin.
- **PATH**: add the plugin directory to the `PATH` variable.
- **FPATH**: add the plugin directory to the `FPATH` variable.
- **path**: add the plugin directory to the `path` variable.
Expand All @@ -364,7 +364,7 @@ As template strings they could be represented like this

```toml
[templates]
source = { value = 'source "{{ filename }}"', each = true }
source = { value = 'source "{{ file }}"', each = true }
PATH = 'export PATH="{{ dir }}:$PATH"'
FPATH = 'export FPATH="{{ dir }}:$FPATH"'
path = 'path=( "{{ dir }}" $path )'
Expand All @@ -383,8 +383,8 @@ apply = ["PATH", "fpath"]
```

The `each` value, as used in the `source` template above, specifies that the
template should be applied to each matched filename for the plugin. This
defaults to `false`.
template should be applied to each matched file for the plugin. This defaults to
`false`.

### Custom templates

Expand All @@ -399,10 +399,9 @@ Plugins all have the following information that can be used in templates
- **A directory.** In git sources this is the location of the cloned repository,
for local sources, it is the directory specified. This directory can be used
in templates with `{{ dir }}`.
- **Zero or more filenames.** These are the matched files in the plugin
directory either discovered using the the global `match` field or specified as
a plugin option with `use`. These can be used in templates using `{{ filename
}}`.
- **Zero or more files.** These are the matched files in the plugin directory
either discovered using the the global `match` field or specified as a plugin
option with `use`. These can be used in templates using `{{ file }}`.

You can use the following global information in templates

Expand All @@ -415,7 +414,7 @@ directory. We could create a new template with name **function**, like this

```toml
[templates]
function = { value = 'ln -sf "{{ filename }}" "~/.zsh/functions/{{ name }}"', each = true }
function = { value = 'ln -sf "{{ file }}" "~/.zsh/functions/{{ name }}"', each = true }
```

It can then be applied to the plugin like this
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ apply = ["PATH", "source"]
# Custom user defined templates, the `each` field means that these will be
# applied for all matched files.
[templates]
function = { value = 'ln -sf "{{ filename }}" "{{ root }}/functions/{{ name }}"', each = true }
prompt = { value = 'ln -sf "{{ filename }}" "{{ root }}/functions/prompt_{{ name }}_setup"', each = true }
function = { value = 'ln -sf "{{ file }}" "{{ root }}/functions/{{ name }}"', each = true }
prompt = { value = 'ln -sf "{{ file }}" "{{ root }}/functions/prompt_{{ name }}_setup"', each = true }

[plugins.async]
# `github` sources provide the repository in the form {username}/{repository}.
Expand Down
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const GITHUB_HOST: &str = "github.com";
pub struct Template {
/// The actual template string.
pub value: String,
/// Whether this template should be applied to each filename.
/// Whether this template should be applied to each file.
pub each: bool,
}

Expand Down Expand Up @@ -119,7 +119,7 @@ pub struct RawPlugin {
/// Which files to use in this plugin's directory. If this is `None` then
/// this will figured out based on the global `matches` field.
///
/// These filenames can contain template parameters.
/// These files can contain template parameters.
#[serde(rename = "use")]
pub uses: Option<Vec<String>>,
/// What templates to apply to each matched file. If this is `None` then the
Expand Down Expand Up @@ -479,7 +479,7 @@ fn validate_template_names(
}

impl Template {
/// Set whether this `Template` should be applied to every filename.
/// Set whether this `Template` should be applied to every file.
pub fn each(mut self, each: bool) -> Self {
self.each = each;
self
Expand Down
4 changes: 2 additions & 2 deletions src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ tag = '0.1.0'
apply = ["PATH", "source"]
[templates]
prompt = { value = 'ln -sf "{{ filename }}" "{{ root }}/functions/prompt_{{ name }}_setup"', each = true }
prompt = { value = 'ln -sf "{{ file }}" "{{ root }}/functions/prompt_{{ name }}_setup"', each = true }
# yes this is the pure plugin
[plugins.pure]
Expand All @@ -221,7 +221,7 @@ use = ["{{ name }}.zsh"]
apply = ["PATH", "source"]
[templates]
prompt = { value = 'ln -sf "{{ filename }}" "{{ root }}/functions/prompt_{{ name }}_setup"', each = true }
prompt = { value = 'ln -sf "{{ file }}" "{{ root }}/functions/prompt_{{ name }}_setup"', each = true }
# yes this is the pure plugin
[plugins.pure]
Expand Down
Loading

0 comments on commit c62600a

Please sign in to comment.