-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* β¨ Implement a playground powered by pyscript * π [docs] Trigger docs deploy in CI * β¨ Add filter `call` for wild mode * π 0.7.5
- Loading branch information
Showing
11 changed files
with
204 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" /> | ||
|
||
<script src="https://cdn.tailwindcss.com"></script> | ||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script> | ||
<py-env> | ||
- liquidpy | ||
</py-env> | ||
<title>Liquidpy playground</title> | ||
</head> | ||
<body> | ||
<main class="mx-auto w-4/5 pt-16"> | ||
<h1 class="text-2xl text-bold">Liquidpy playground</h1> | ||
<p class="text-xs"> | ||
This is a playground for Liquidpy, powered by <a class="text-blue-600" target="_blank" href="https://pyscript.net">pyscript</a>. | ||
</p> | ||
<p class="text-xs"><py-script> | ||
import liquid | ||
print(f"Liquidpy version: {liquid.__version__}") | ||
</py-script> | ||
</p> | ||
<p> </p> | ||
<div> | ||
<div class="w-1/3 inline-block mr-4"> | ||
<h2>Template</h2> | ||
<textarea id="template" class="w-full h-96 p-2 text-sm font-mono border-2 border-slate-600"></textarea> | ||
</div> | ||
<div class="w-1/4 inline-block mr-4"> | ||
<h2>Variables</h2> | ||
<textarea id="variables" class="w-full h-96 p-2 text-sm font-mono border-2 border-slate-600"># one assignment per line</textarea> | ||
</div> | ||
<div class="w-1/4 inline-block"> | ||
<h2>Filters</h2> | ||
<textarea id="filters" class="w-full h-96 p-2 text-sm font-mono border-2 border-slate-600"></textarea> | ||
</div> | ||
<div class="my-4"> | ||
<select id="mode" class="bg-cyan-500 text-white text-sm py-2 px-4 rounded-lg"> | ||
<option value="default">default</option> | ||
<option value="jekyll">jekyll</option> | ||
<option value="shopify">shopify</option> | ||
<option value="wild">wild</option> | ||
</select> | ||
|
||
<button id="render" pys-onClick="render" class="bg-lime-600 hover:bg-lime-700 text-white text-sm py-2 px-4 rounded-lg">Render</button> | ||
<button id="load_example" pys-onClick="load_example" class="bg-slate-600 hover:bg-slate-700 text-white text-sm py-2 px-4 rounded-lg">Load example</button> | ||
</div> | ||
<div class="my-2"> | ||
<h2>Rendered:</h2> | ||
<textarea id="rendered" readonly style="width: 82.8rem" class="text-sm h-72 p-2 font-mono border-2 border-slate-600"></textarea> | ||
</div> | ||
</div> | ||
<py-script src="./liquid.py"></py-script> | ||
</main> | ||
</body> | ||
</html> |
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,66 @@ | ||
from liquid import Liquid | ||
|
||
EXAMPLE_TEMPLATE = "{{ a | upper }}" | ||
EXAMPLE_VARIABLES = "a = 'hello world!'" | ||
EXAMPLE_FILTERS = """\ | ||
def upper(value): | ||
return value.upper() | ||
""" | ||
|
||
TEMPLATE_CONTAINER = Element("template") | ||
VARIABLES_CONTAINER = Element("variables") | ||
FILTERS_CONTAINER = Element("filters") | ||
MODE_CONTAINER = Element("mode") | ||
RENDERED_CONTAINER = Element("rendered") | ||
|
||
def _remove_class(element, class_name): | ||
element.element.classList.remove(class_name) | ||
|
||
|
||
def _add_class(element, class_name): | ||
element.element.classList.add(class_name) | ||
|
||
|
||
def _error(message): | ||
""" | ||
Displays an error message. | ||
""" | ||
_add_class(RENDERED_CONTAINER, "bg-red-100") | ||
RENDERED_CONTAINER.element.value = message | ||
|
||
|
||
def load_example(*args, **kwargs): | ||
""" | ||
Loads the example template, variables and filters. | ||
""" | ||
TEMPLATE_CONTAINER.element.value = EXAMPLE_TEMPLATE | ||
VARIABLES_CONTAINER.element.value = EXAMPLE_VARIABLES | ||
FILTERS_CONTAINER.element.value = EXAMPLE_FILTERS | ||
|
||
|
||
def render(*args, **kwargs): | ||
""" | ||
Renders the template with the variables and filters. | ||
""" | ||
template = TEMPLATE_CONTAINER.element.value | ||
variables = {} | ||
try: | ||
exec(VARIABLES_CONTAINER.element.value, variables) | ||
except Exception as e: | ||
_error(f"Something wrong when evaluating variables: \n{e}") | ||
return | ||
|
||
filters = {} | ||
try: | ||
exec(FILTERS_CONTAINER.element.value, filters) | ||
except Exception as e: | ||
_error(f"Something wrong when evaluating filters: \n{e}") | ||
return | ||
|
||
mode = MODE_CONTAINER.element.value | ||
_remove_class(RENDERED_CONTAINER, "bg-red-100") | ||
try: | ||
liq = Liquid(template, from_file=False, mode=mode, filters=filters) | ||
RENDERED_CONTAINER.element.value = liq.render(**variables) | ||
except Exception as e: | ||
_error(f"Something wrong when rendering: \n{e}") |
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,5 +1,5 @@ | ||
# use_directory_urls doesn't work for newer versions | ||
mkdocs==1.1.2 | ||
mkdocs-material==7.2.2 | ||
mkdocs | ||
mkdocs-material | ||
pymdown-extensions | ||
mkapi-fix |
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 |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
|
||
patch_jinja() | ||
|
||
__version__ = "0.7.4" | ||
__version__ = "0.7.5" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
from liquid import Liquid | ||
import pytest # noqa | ||
|
||
|
||
def test_ifelse(set_default_wild): | ||
tpl = """{{ a | ifelse: isinstance, (int, ), | ||
"plus", (1, ), | ||
"append", (".html", ) }}""" | ||
|
||
out = Liquid(tpl).render(a=1) | ||
assert out == "2" | ||
|
||
out = Liquid(tpl).render(a="a") | ||
assert out == "a.html" | ||
|
||
|
||
def test_call(set_default_wild): | ||
tpl = """{{ int | call: "1" | plus: 1 }}""" | ||
|
||
out = Liquid(tpl).render() | ||
assert out == "2" |