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
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
escape
¶
Escape text using Markupsafe library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
text to escape |
required |
Source code in src/jinjarope/textfilters.py
213 214 215 216 217 218 219 220 221 |
|
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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
format_code
cached
¶
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
86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
format_filter_signature
¶
format_filter_signature(
fn: Callable, 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
|
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
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
format_signature
cached
¶
format_signature(
fn: Callable,
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
|
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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
format_timestamp
¶
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
224 225 226 227 228 229 230 231 232 233 234 |
|
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
61 62 63 64 65 66 67 68 69 70 71 |
|
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
|
Source code in src/jinjarope/textfilters.py
41 42 43 44 45 46 47 48 |
|
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 |
Source code in src/jinjarope/textfilters.py
31 32 33 34 35 36 37 38 |
|
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 |
Source code in src/jinjarope/textfilters.py
21 22 23 24 25 26 27 28 |
|
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
|
Source code in src/jinjarope/textfilters.py
51 52 53 54 55 56 57 58 |
|
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
181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
snake_case
¶
Convert given text to snake-case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The string to convert |
required |
Source code in src/jinjarope/textfilters.py
74 75 76 77 78 79 80 81 82 83 |
|