Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tpldata): provide tplroot #51814

Merged
merged 4 commits into from
Jun 20, 2019
Merged

feat(tpldata): provide tplroot #51814

merged 4 commits into from
Jun 20, 2019

Conversation

myii
Copy link
Contributor

@myii myii commented Feb 26, 2019

Note: Happy to rebase the commits to remove the commit body text if a hindrance of any kind.


What does this PR do?

Working on making SaltStack Formulas portable, find the need for a
common point of reference. Comparing the import of map.jinja with and
without context:

tpldata without context with context
tplfile template/map.jinja template/pkg/install.sls
tpldir template template/pkg
tpldot template template.pkg
tplroot template template

With tplroot, it is possible to use a single point of reference for
all paths, avoiding the various incantations currently used, such as:

  • from tpldir ~ "/map.jinja" import ...
  • from salt.file.dirname(tpldir) ~ "/map.jinja" import ...
  • from salt['file.dirname'](tpldir) ~ "/map.jinja" import ...

In all of the above circumstances, this simply becomes:

  • from tplroot ~ "/map.jinja" import ...

Additional benefits are gained when referencing by colon : for pillars
or by period . for include statements or for any requisites.

What issues does this PR fix or reference?

Related issues: #10838, #41195.
Related PR: saltstack-formulas/template-formula#48.

Tests written?

No.

Commits signed with GPG?

No.

* http://jinja.pocoo.org/docs/2.10/templates/#math -- re: `+`
  - "This, however, is not the preferred way to concatenate strings!"
* http://jinja.pocoo.org/docs/2.10/templates/#other-operators -- re: `~`
  - "Converts all operands into strings and concatenates them."
Working on making SaltStack Formulas portable, find the need for a
common point of reference.  Comparing the import of `map.jinja` with and
without context:

| `tpldata` | without context    | with context             |
|-----------|--------------------|--------------------------|
| `tplfile` | template/map.jinja | template/pkg/install.sls |
| `tpldir`  | template           | template/pkg             |
| `tpldot`  | template           | template.pkg             |
| `tplroot` | template           | template                 |

With `tplroot`, it is possible to use a single point of reference for
all paths, avoiding the various incantations currently used, such as:

* `from tpldir ~ "/map.jinja" import ...`
* `from salt.file.dirname(tpldir) ~ "/map.jinja" import ...`
* `from salt['file.dirname'](tpldir) ~ "/map.jinja" import ...`

In all of the above circumstances, this simply becomes:

* `from tplroot ~ "/map.jinja" import ...`

Additional benefits are gained when referencing by colon `:` for pillars
or by period `.` for `include` statements or for any requisites.

Related issues: saltstack#10838, saltstack#41195.
@cmcmarrow cmcmarrow self-requested a review June 14, 2019 20:17
@Akm0d Akm0d merged commit c24dfef into saltstack:develop Jun 20, 2019
myii added a commit to myii/template-formula that referenced this pull request Jun 25, 2019
myii added a commit to myii/template-formula that referenced this pull request Jun 25, 2019
@myii myii deleted the feature/tplroot branch January 21, 2020 18:14
@sagetherage sagetherage added has master-port port to master has been created and removed master-port labels May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has master-port port to master has been created
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants