Skip to content

Commit

Permalink
chore: update provider comments and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Dec 24, 2023
1 parent 39086c1 commit 71d647a
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 17 deletions.
36 changes: 32 additions & 4 deletions providers/arithmatic/.tackle.meta.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,52 @@
name: Arithmatic Provider
name: Arithmetic Provider

description: |
Hooks that do arithmatic.
Hooks that perform arithmetic operations.
examples:
- name: "[sum](sum.md)"
description: Sum a list of numbers
content: |
total->: sum [1, 2, 3, 4, 5]
output: |
total: 15
- name: "[average](average.md)"
description: Calculate the average of a list of numbers
content: |
avg->: average [1, 2, 3, 4, 5]
output: |
avg: 3.0
- name: "[modulo](modulo.md)"
description: Take the modulo of a number
content: |
odd->: modulo 5 2
even->: modulo 6 2
output: |
output: 1
odd: 1
even: 0
hook_examples:
sum:
- description: Sum a list of numbers
content: |
total->: sum [1, 2, 3, 4, 5]
output: |
total: 15
average:
- description: Calculate the average of a list of numbers
content: |
avg->: average [1, 2, 3, 4, 5]
output: |
avg: 3.0
modulo:
- description: Take the modulo of a number
content: |
odd->: modulo 5 2
even->: modulo 6 2
output: |
output: 1
odd: 1
even: 0
15 changes: 10 additions & 5 deletions providers/generate/hooks/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,24 @@ class GenerateHook(BaseHook):
)
output: str = Field('.', description="Path to put the output file(s).")
copy_without_render: Union[str, list] = Field(
[], description="List of path to files to only copy and not render."
[],
description="List of path to files to only copy and not render."
)
overwrite_if_exists: bool = Field(
False, description="Overwrite the output if exists."
False,
description="Overwrite the output if exists."
)
skip_if_file_exists: bool = Field(
False, description="Skip creating if path exists."
False,
description="Skip creating if path exists."
)
skip_overwrite_files: list = Field(
[], description="List of files to skip generating over if they exist."
None,
description="List of files to skip generating over if they exist."
)
render_context: dict = Field(
None, description="A render context that invalidates the default context."
None,
description="A render context that invalidates the default context."
)
extra_context: Union[str, dict, List[dict]] = Field(
None,
Expand Down
40 changes: 37 additions & 3 deletions providers/logic/.tackle.meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Logic Provider

description: Hooks for various logical operations such as match/case, assert, and while loops.

#
match_content: |
# Stand in for some kind of thing to match against
selection:
Expand Down Expand Up @@ -48,18 +47,53 @@ examples:
map_type: dict
hook_examples:
return:
- description: The `return` hook stops parsing and returns whatever value by rendering
content: |
foo:
bar: baz
ignored key->: return foo
output: |
bar: baz
- description: The `return` hook can also be a special key
content: |
foo:
bar: baz
return->: foo --if true
output: |
bar: baz
returns:
- description: The `returns` hook stops parsing and returns whatever string value
content: |
foo:
bar: baz
returns->: foo
output: |
bar: baz
- description: The `returns` hook stops parsing
content: |
foo: bar
returns->: foo # Does not render by default vs `return` hook which does
output: |
foo
match:
- description: The `match` hook mimics common match/case statements
content->: var "{{match_content}}" --no_recursion

assert:
- description: Assert if two items are equal. Can also easily be done with jinja but with this hook you can exit based on the assertion.
content: |
stuff: things
assertion->: assert {{stuff}} things # Would exit otherwise
with-jinja->: {{stuff!='things'}} # Equivalent and would not exit
# `assert` is a special key as well and skips output
assert->: things {{stuff}}
# Note - this does not work because of yaml parsing error
#assert->: "{{stuff}}" things
output: |
stuff: things
assertion: true
with-jinja: false
#{% endraw %}
5 changes: 1 addition & 4 deletions providers/strings/hooks/b64.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ class Base64EncodeHook(BaseHook):
_docs_order = 8

def exec(self) -> str:
sample_string_bytes = self.input.encode("utf-8")
base64_bytes = base64.b64encode(sample_string_bytes)
base64_string = base64_bytes.decode("utf-8")
return base64_string
return base64.b64encode(self.input.encode("utf-8")).decode("utf-8")


class Base64DecodeHook(BaseHook):
Expand Down
10 changes: 9 additions & 1 deletion providers/toml/.tackle.meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ name: TOML Provider
description: |
Reading toml files. For writing toml you will need a third party provider since this wraps python's native toml library which only supports reads.
examples: []
examples:
- name: "[toml](toml.md)"
description: Read a toml file into a key
content: |
expanded:
->: toml
path: path/to/toml/file.toml
compact->: toml path/to/toml/file.toml
hook_examples:
toml:
Expand Down

0 comments on commit 71d647a

Please sign in to comment.