first commit
This commit is contained in:
commit
a3dbf9cbe3
16 files changed
+471
No files matched your search
@@ -0,0 +1,4 @@
|
||||
from . import for_formatter, if_formatter, var_formatter, block_formatter, static_formatter
|
||||
|
||||
|
||||
formatters = [for_formatter, if_formatter, var_formatter, block_formatter, static_formatter]
|
||||
@@ -0,0 +1,8 @@
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def format(soup: BeautifulSoup) -> None:
|
||||
for element in soup.find_all(attrs={"dj-block": True}):
|
||||
element.insert_before(f"{{% block {element.get("dj-block")} %}}")
|
||||
element.insert_after("{% endblock %}")
|
||||
element.unwrap()
|
||||
@@ -0,0 +1,8 @@
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def format(soup: BeautifulSoup) -> None:
|
||||
for element in soup.find_all(attrs={"dj-for": True}):
|
||||
element.insert_before(f"{{% for {element.get("dj-for")} %}}")
|
||||
element.insert_after("{% endfor %}")
|
||||
element.unwrap()
|
||||
@@ -0,0 +1,26 @@
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def format(soup: BeautifulSoup) -> None:
|
||||
for element in soup.find_all(attrs={"dj-if": True}):
|
||||
element.insert_before(f"{{% if {element.get("dj-if")} %}}")
|
||||
|
||||
participating_blocks = [element]
|
||||
|
||||
current_sibling = element.find_next_sibling()
|
||||
while current_sibling is not None:
|
||||
if current_sibling.has_attr("dj-elif"):
|
||||
current_sibling.insert_before(f"{{% elif {current_sibling.get("dj-elif")} %}}")
|
||||
participating_blocks.append(current_sibling)
|
||||
current_sibling = current_sibling.find_next_sibling()
|
||||
elif current_sibling.has_attr("dj-else"):
|
||||
current_sibling.insert_before("{% else %}")
|
||||
participating_blocks.append(current_sibling)
|
||||
current_sibling = None
|
||||
else:
|
||||
current_sibling = None
|
||||
|
||||
participating_blocks[-1].insert_after("{% endif %}")
|
||||
|
||||
for block in participating_blocks:
|
||||
block.unwrap()
|
||||
@@ -0,0 +1,8 @@
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def format(soup: BeautifulSoup) -> None:
|
||||
for element in soup.find_all(attrs={"dj-static": True}):
|
||||
tag, value = element.get("dj-static").split(";")
|
||||
element[tag] = f"{{% static '{value}' %}}"
|
||||
del element.attrs["dj-static"]
|
||||
@@ -0,0 +1,13 @@
|
||||
"""
|
||||
Find tags with a "dj-var" attribute and replace its content with the
|
||||
value enclosed in {{ }}.
|
||||
"""
|
||||
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def format(soup: BeautifulSoup) -> None:
|
||||
for element in soup.find_all(attrs={"dj-var": True}):
|
||||
element.string = f"{{{{ {element.get("dj-var")} }}}}"
|
||||
del element.attrs["dj-var"]
|
||||
Reference in new issue
Block a user