misc (14)
add¶
add(text: str | None, prefix: str = '', suffix: str = '') -> str
Add a pre- or suffix to a value if the value is true-ish.
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str | None
|
The text to check |
required |
prefix
|
str
|
Prefix to add if text is true-ish |
''
|
suffix
|
str
|
Suffix to add if text is true-ish |
''
|
Source code in src/jinjarope/envglobals.py
68 69 70 71 72 73 74 75 76 |
|
attr¶
attr(environment: 'Environment', obj: Any, name: str) -> Union[jinja2.runtime.Undefined, Any]
Get an attribute of an object. foo|attr("bar")
works like
Example
Jinja call:
Result:<built-in method removesuffix of str object at 0x7f8dd45baf10>
Example
Jinja call:
Result:[<built-in method upper of str object at 0x7f8df0fc9e40>, <built-in method upper of str object at 0x7f8df05837e0>]
DocStrings
Source code in .venv/lib/python3.12/site-packages/jinja2/filters.py
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 |
|
check_output¶
check_output(call: 'str | Sequence[str]', cwd: 'str | os.PathLike[str] | None' = None, use_cache: 'bool' = False) -> 'str | None'
Execute a system call and return its output as a string.
Example
Jinja call:
Result:LICENSE docs mkdocs.yml pyproject.toml tests
README.md duties.py overrides src uv.lock
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
call
|
str | Sequence[str]
|
The system call to make |
required |
cwd
|
str | PathLike[str] | None
|
The working directory for the call |
None
|
use_cache
|
bool
|
Whether to cache the output of calls |
False
|
Source code in src/jinjarope/envglobals.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
default¶
default(value: ~V, default_value: ~V = '', boolean: bool = False) -> ~V
If the value is undefined it will return the passed default value,
Aliases: d
DocStrings
Source code in .venv/lib/python3.12/site-packages/jinja2/filters.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
|
get_hash¶
get_hash(obj: Any, hash_length: int | None = 7) -> str
Get a Md5 hash for given object.
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to get a hash for () |
required |
hash_length
|
int | None
|
Optional cut-off value to limit length |
7
|
Source code in src/jinjarope/utils.py
128 129 130 131 132 133 134 135 136 137 138 |
|
getenv¶
getenv(key, default=None)
Get an environment variable, return None if it doesn't exist.
DocStrings
Source code in python3.12/os.py
808 809 810 811 812 |
|
hasattr¶
hasattr(obj, name, /)
Return whether the object has an attribute with the given name.
DocStrings
import_module¶
import_module(name, package=None)
Import a module.
Example
Jinja call:
Result:<module 'jinja2' from '/home/runner/work/jinjarope/jinjarope/.venv/lib/python3.12/site-packages/jinja2/__init__.py'>
DocStrings
Source code in importlib/__init__.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
load_file¶
load_file(path: 'str | os.PathLike[str]') -> 'str'
Return the text-content of file at given path.
Example
Jinja call:
Result: `## Emoji extension indexMkNodes provides a custom emoji index for the pymdownx.emoji extension in order to provide access to all > 180.000 icons provided by the Iconify framework.
Example: becomes:
Info
For compatibility, icons can also be accessed from the same name as the Material-MkDocs icon index, making
the MkNodes
index a superset of the MkDocs-Material
index.
Icon node¶
MkNodes also includes a node for Pyconify-Icons named [MkIcon][mknodes.MkIcon]. It can be used to include icons with custom color, rotation and size. `
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | PathLike[str]
|
The path to get str content from |
required |
Source code in src/jinjarope/envglobals.py
21 22 23 24 25 26 27 28 29 30 31 |
|
map¶
map(context: 'Context', value: Iterable[Any], *args: Any, **kwargs: Any) -> Iterable[Any]
Applies a filter on a sequence of objects or looks up an attribute.
Example
Jinja call:
Result:<generator object sync_do_map at 0x7f8dcfa16440>
DocStrings
Source code in .venv/lib/python3.12/site-packages/jinja2/filters.py
1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 |
|
match¶
match(obj: Any, mapping: dict[str | type, str] | None = None, **kwargs: Any) -> str
A filter trying to imitate a python match-case statement.
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
match object |
required |
mapping
|
dict[str | type, str] | None
|
a mapping for the different cases. If key is type, an isinstance will be performed. If key is a str, check for equality. |
None
|
kwargs
|
Any
|
Same functionality as mapping, but provided as keyword arguments for convenience. |
{}
|
Examples:
{{ "a" | match(a="hit", b="miss")
{{ MyClass() | match({MyClass: "hit", OtherClass: "miss"}) }}
Source code in src/jinjarope/envglobals.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
partial¶
partial(fn: 'Callable', *args: 'Any', **kwargs: 'Any')
Create new function with partial application of given arguments / keywords.
Example
Jinja call:
Result:functools.partial(<function join at 0x7f8df051cb80>, 'abc')
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn
|
Callable
|
The function to generate a partial from |
required |
args
|
Any
|
patially applied arguments |
()
|
kwargs
|
Any
|
partially applied keywords |
{}
|
Source code in src/jinjarope/utils.py
26 27 28 29 30 31 32 33 34 |
|
random¶
random(context: 'Context', seq: 't.Sequence[V]') -> 't.Union[V, Undefined]'
Return a random item from the sequence.
DocStrings
Source code in .venv/lib/python3.12/site-packages/jinja2/filters.py
695 696 697 698 699 700 701 |
|
ternary¶
ternary(value: Any, true_val: Any, false_val: Any, none_val: Any = None)
Value ? true_val : false_val.
DocStrings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
The value to check. |
required |
true_val
|
Any
|
The value to return if given value is true-ish |
required |
false_val
|
Any
|
The value to return if given value is false-ish |
required |
none_val
|
Any
|
Optional value to return if given value is None |
None
|
Source code in src/jinjarope/envglobals.py
79 80 81 82 83 84 85 86 87 88 89 90 |
|