-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
execute custom code to update environment
- Loading branch information
Showing
8 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
def update_environment(jinja_environment): | ||
|
||
def display_environment_change(new, old, display_type): | ||
added = ['"' + s + '"' for s in sorted(new - old)] | ||
count = len(added) | ||
added = ', '.join(added) | ||
|
||
print(f'CUSTOM: Added { count } { display_type }: { added }.') | ||
|
||
|
||
def uppercase_first(string): | ||
return string[0].upper() + string[1:].lower() | ||
|
||
|
||
def add_exclamation_mark(string, is_spanish=False): | ||
if is_spanish: | ||
string = '¡' + string | ||
return string + '!' | ||
|
||
|
||
old_filters = set(jinja_environment.filters) | ||
|
||
jinja_environment.filters["upper_first"] = uppercase_first | ||
jinja_environment.filters["add_exclamation_mark"] = add_exclamation_mark | ||
|
||
new_filters = set(jinja_environment.filters) | ||
display_environment_change(new_filters, old_filters, 'filters') | ||
|
||
return jinja_environment | ||
|
||
|
||
update_environment(jinja_environment) # noqa: F821 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
def update_environment(jinja_environment): | ||
|
||
def display_environment_change(new, old, display_type): | ||
added = ['"' + s + '"' for s in sorted(new - old)] | ||
count = len(added) | ||
added = ', '.join(added) | ||
|
||
print(f'CUSTOM: Added { count } { display_type }: { added }.') | ||
|
||
|
||
def is_spanish(string): | ||
return 'este es' in string | ||
|
||
|
||
old_tests = set(jinja_environment.tests) | ||
|
||
jinja_environment.tests["spanish"] = is_spanish | ||
|
||
new_tests = set(jinja_environment.tests) | ||
display_environment_change(new_tests, old_tests, 'tests') | ||
|
||
return jinja_environment | ||
|
||
|
||
update_environment(jinja_environment) # noqa: F821 |