textfilters
Class info¶
🛈 DocStrings¶
dirname_to_title
¶
Return a page tile obtained from a directory name.
Replaces dashes and underscores with spaces and capitalizes the first letter in case all letters are lowercase
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dirname
|
str | PathLike[str]
|
directory to get a title for |
required |
Source code in src/jinjarope/textfilters.py
escape
¶
Escape text using Markupsafe library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
text to escape |
required |
extract_body
cached
¶
Get body of source code of given function / class.
Strips off the signature / decorators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
str
|
Source code to extract the body from |
required |
Source code in src/jinjarope/textfilters.py
format_code
cached
¶
format_code(code: str, line_length: int = 100) -> str
Format code to given line length using black.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The code to format |
required |
line_length
|
int
|
Line length limit for formatted code |
100
|
Source code in src/jinjarope/textfilters.py
format_filter_signature
¶
format_filter_signature(
fn: Callable[..., Any],
filter_name: str,
follow_wrapped: bool = True,
eval_str: bool = False,
) -> str
Create a signature for a jinja filter based on filter name and callable.
Outputs text in shape of "code: 'str' | test(line_length: 'int' = 100)"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any]
|
The callable to format the signature from |
required |
filter_name
|
str
|
Name of the jinja filter |
required |
follow_wrapped
|
bool
|
Whether to unwrap the callable |
True
|
eval_str
|
bool
|
Un-stringize annotations using eval |
False
|
Source code in src/jinjarope/textfilters.py
format_signature
cached
¶
format_signature(
fn: Callable[..., Any],
follow_wrapped: bool = True,
eval_str: bool = True,
remove_jinja_arg: bool = False,
) -> str
Format signature of a callable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any]
|
The callable to format the signature from |
required |
follow_wrapped
|
bool
|
Whether to unwrap the callable |
True
|
eval_str
|
bool
|
Un-stringize annotations using eval |
True
|
remove_jinja_arg
|
bool
|
If true, remove the first argument for pass_xyz decorated fns. |
False
|
Source code in src/jinjarope/textfilters.py
format_timestamp
¶
format_timestamp(timestamp: float, fmt: str) -> str
Format Unix timestamp to date string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp
|
float
|
Unix timestamp to format |
required |
fmt
|
str
|
Format string according to strftime() format codes |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted date string |
Source code in src/jinjarope/textfilters.py
lower_camel_case
¶
Convert given text to lower-camel-case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The string to convert |
required |
Source code in src/jinjarope/textfilters.py
lstrip
¶
Strip given chars from beginning of string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to strip the chars from |
required |
chars
|
str | None
|
The chars to remove |
None
|
removeprefix
¶
Return given prefix from text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to strip the prefix from |
required |
prefix
|
str
|
The prefix to remove |
required |
removesuffix
¶
Return given suffix from text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to strip the suffix from |
required |
suffix
|
str
|
The suffix to remove |
required |
rstrip
¶
Strip given chars from end of string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to strip the chars from |
required |
chars
|
str | None
|
The chars to remove |
None
|
slugify
¶
Create a slug for given text.
Returned text only contains alphanumerical and underscore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | PathLike[str]
|
text to get a slug for |
required |
Source code in src/jinjarope/textfilters.py
snake_case
¶
Convert given text to snake-case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The string to convert |
required |