-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from jg-rp/compat
Add Shopify compatible tags and filters
- Loading branch information
Showing
25 changed files
with
951 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.0.3" | ||
__version__ = "0.0.4" |
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
# noqa: D104 | ||
from .environment import Environment | ||
|
||
__all__ = ("Environment",) |
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 @@ | ||
"""An environment that's configured for maximum compatibility with Shopify/Liquid. | ||
This environment will be updated without concern for backwards incompatible changes to | ||
template rendering behavior. | ||
""" | ||
|
||
from ..environment import Environment as DefaultEnvironment # noqa: TID252 | ||
from .filters._base64 import base64_decode | ||
from .filters._base64 import base64_encode | ||
from .filters._base64 import base64_url_safe_decode | ||
from .filters._base64 import base64_url_safe_encode | ||
from .tags.tablerow_tag import TablerowTag | ||
|
||
|
||
class Environment(DefaultEnvironment): | ||
"""An environment configured for maximum compatibility with Shopify/Liquid.""" | ||
|
||
def setup_tags_and_filters(self) -> None: | ||
"""Set up Shopify compatible tags and filters.""" | ||
super().setup_tags_and_filters() | ||
self.tags["tablerow"] = TablerowTag(self) | ||
self.filters["base64_decode"] = base64_decode | ||
self.filters["base64_encode"] = base64_encode | ||
self.filters["base64_url_safe_decode"] = base64_url_safe_decode | ||
self.filters["base64_url_safe_encode"] = base64_url_safe_encode |
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 @@ | ||
# noqa: D104 |
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,45 @@ | ||
"""Filter functions that operate on strings.""" | ||
|
||
from __future__ import annotations | ||
|
||
import base64 | ||
import binascii | ||
|
||
from liquid2.exceptions import LiquidValueError | ||
from liquid2.filter import string_filter | ||
|
||
|
||
@string_filter | ||
def base64_encode(val: str) -> str: | ||
"""Return _val_ encoded in base64.""" | ||
return base64.b64encode(val.encode()).decode() | ||
|
||
|
||
@string_filter | ||
def base64_decode(val: str) -> str: | ||
"""Return _val_ decoded as base64. | ||
The decoded value is assumed to be UTF-8 and will be decoded as UTF-8. | ||
""" | ||
try: | ||
return base64.b64decode(val).decode() | ||
except binascii.Error as err: | ||
raise LiquidValueError("invalid base64-encoded string", token=None) from err | ||
|
||
|
||
@string_filter | ||
def base64_url_safe_encode(val: str) -> str: | ||
"""Return _val_ encoded in URL-safe base64.""" | ||
return base64.urlsafe_b64encode(val.encode()).decode() | ||
|
||
|
||
@string_filter | ||
def base64_url_safe_decode(val: str) -> str: | ||
"""Return _val_ decoded as URL-safe base64. | ||
The decoded value is assumed to be UTF-8 and will be decoded as UTF-8. | ||
""" | ||
try: | ||
return base64.urlsafe_b64decode(val).decode() | ||
except binascii.Error as err: | ||
raise LiquidValueError("invalid base64-encoded string", token=None) from err |
Oops, something went wrong.