Unindent jinja template code (#1001)

This commit is contained in:
Nikhil Rao 2023-05-10 23:26:01 -07:00 committed by GitHub
parent 01aac494dd
commit 8c42c99ecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 19 additions and 59 deletions

View File

@ -3,7 +3,7 @@
{% block export %} {% block export %}
export default function Document() { export default function Document() {
return ( return (
{{utils.render(document, indent_width=4)}} {{utils.render(document, indent_width=0)}}
) )
} }
{% endblock %} {% endblock %}

View File

@ -67,7 +67,7 @@ export default function Component() {
{% endfor %} {% endfor %}
return ( return (
{{utils.render(render, indent_width=4)}} {{utils.render(render, indent_width=0)}}
) )
} }
{% endblock %} {% endblock %}

View File

@ -1,8 +1,8 @@
{# Renderting components recursively. #} {# Rendering components recursively. #}
{# Args: #} {# Args: #}
{# component: component dictionary #} {# component: component dictionary #}
{# indent_width: indent width #} {# indent_width: indent width #}
{% macro render(component, indent_width=2) %} {% macro render(component, indent_width=0) %}
{% filter indent(width=indent_width) %} {% filter indent(width=indent_width) %}
{%- if component is not mapping %} {%- if component is not mapping %}
{{- component }} {{- component }}
@ -18,7 +18,7 @@
{% endfilter %} {% endfilter %}
{% endmacro %} {% endmacro %}
{# Renderting self close tag. #} {# Rendering self close tag. #}
{# Args: #} {# Args: #}
{# component: component dictionary #} {# component: component dictionary #}
{% macro render_self_close_tag(component) %} {% macro render_self_close_tag(component) %}
@ -29,7 +29,7 @@
{%- endif %} {%- endif %}
{% endmacro %} {% endmacro %}
{# Renderting close tag with args and props. #} {# Rendering close tag with args and props. #}
{# Args: #} {# Args: #}
{# component: component dictionary #} {# component: component dictionary #}
{% macro render_tag(component) %} {% macro render_tag(component) %}
@ -46,7 +46,7 @@
{%- endmacro %} {%- endmacro %}
{# Renderting condition component. #} {# Rendering condition component. #}
{# Args: #} {# Args: #}
{# component: component dictionary #} {# component: component dictionary #}
{% macro render_condition_tag(component) %} {% macro render_condition_tag(component) %}
@ -58,7 +58,7 @@
{%- endmacro %} {%- endmacro %}
{# Renderting iterable component. #} {# Rendering iterable component. #}
{# Args: #} {# Args: #}
{# component: component dictionary #} {# component: component dictionary #}
{% macro render_iterable_tag(component) %} {% macro render_iterable_tag(component) %}
@ -70,7 +70,7 @@
{%- endmacro %} {%- endmacro %}
{# Renderting props of a component. #} {# Rendering props of a component. #}
{# Args: #} {# Args: #}
{# component: component dictionary #} {# component: component dictionary #}
{% macro render_props(props) %} {% macro render_props(props) %}
@ -78,7 +78,7 @@
{% endmacro %} {% endmacro %}
{# Renderting content with args. #} {# Rendering content with args. #}
{# Args: #} {# Args: #}
{# component: component dictionary #} {# component: component dictionary #}
{% macro render_arg_content(component) %} {% macro render_arg_content(component) %}

View File

@ -34,7 +34,7 @@ WEB_TEMPLATE_DIR = os.path.join(TEMPLATE_DIR, "web")
# The assets subdirectory of the template directory. # The assets subdirectory of the template directory.
ASSETS_TEMPLATE_DIR = os.path.join(TEMPLATE_DIR, APP_ASSETS_DIR) ASSETS_TEMPLATE_DIR = os.path.join(TEMPLATE_DIR, APP_ASSETS_DIR)
# The jinja template directory. # The jinja template directory.
JINJA_TEMPLATE_DIR = os.path.join(ROOT_DIR, MODULE_NAME, "templates") JINJA_TEMPLATE_DIR = os.path.join(TEMPLATE_DIR, "jinja")
# The frontend directories in a project. # The frontend directories in a project.
# The web folder where the NextJS app is compiled to. # The web folder where the NextJS app is compiled to.

View File

@ -1,5 +1,4 @@
"""Pynecone middleware.""" """Pynecone middleware."""
from .hydrate_middleware import HydrateMiddleware from .hydrate_middleware import HydrateMiddleware
from .logging_middleware import LoggingMiddleware
from .middleware import Middleware from .middleware import Middleware

View File

@ -1,38 +0,0 @@
"""Logging middleware."""
from __future__ import annotations
from typing import TYPE_CHECKING
from pynecone.event import Event
from pynecone.middleware.middleware import Middleware
from pynecone.state import State, StateUpdate
if TYPE_CHECKING:
from pynecone.app import App
class LoggingMiddleware(Middleware):
"""Middleware to log requests and responses."""
async def preprocess(self, app: App, state: State, event: Event):
"""Preprocess the event.
Args:
app: The app to apply the middleware to.
state: The client state.
event: The event to preprocess.
"""
print(f"Event {event}")
async def postprocess(
self, app: App, state: State, event: Event, update: StateUpdate
):
"""Postprocess the event.
Args:
app: The app to apply the middleware to.
state: The client state.
event: The event to postprocess.
update: The current state update.
"""
print(f"Update {update}")

View File

@ -9,8 +9,7 @@ import typer
from pynecone import constants from pynecone import constants
from pynecone.config import get_config from pynecone.config import get_config
from pynecone.telemetry import pynecone_telemetry from pynecone.utils import build, console, exec, prerequisites, processes, telemetry
from pynecone.utils import build, console, exec, prerequisites, processes
# Create the app. # Create the app.
cli = typer.Typer() cli = typer.Typer()
@ -49,10 +48,10 @@ def init(
prerequisites.create_config(app_name) prerequisites.create_config(app_name)
prerequisites.initialize_app_directory(app_name, template) prerequisites.initialize_app_directory(app_name, template)
build.set_pynecone_project_hash() build.set_pynecone_project_hash()
pynecone_telemetry("init", get_config().telemetry_enabled) telemetry.send("init", get_config().telemetry_enabled)
else: else:
build.set_pynecone_project_hash() build.set_pynecone_project_hash()
pynecone_telemetry("reinit", get_config().telemetry_enabled) telemetry.send("reinit", get_config().telemetry_enabled)
# Initialize the .gitignore. # Initialize the .gitignore.
prerequisites.initialize_gitignore() prerequisites.initialize_gitignore()
@ -123,7 +122,7 @@ def run(
assert frontend_cmd and backend_cmd, "Invalid env" assert frontend_cmd and backend_cmd, "Invalid env"
# Post a telemetry event. # Post a telemetry event.
pynecone_telemetry(f"run-{env.value}", get_config().telemetry_enabled) telemetry.send(f"run-{env.value}", get_config().telemetry_enabled)
# Run the frontend and backend. # Run the frontend and backend.
try: try:
@ -210,7 +209,7 @@ def export(
) )
# Post a telemetry event. # Post a telemetry event.
pynecone_telemetry("export", get_config().telemetry_enabled) telemetry.send("export", get_config().telemetry_enabled)
if zipping: if zipping:
console.rule( console.rule(

View File

@ -14,7 +14,7 @@ from pynecone import constants
from pynecone.config import get_config from pynecone.config import get_config
from pynecone.utils import console, prerequisites, processes from pynecone.utils import console, prerequisites, processes
from pynecone.utils.build import export_app, setup_backend, setup_frontend from pynecone.utils.build import export_app, setup_backend, setup_frontend
from pynecone.watch import AssetFolderWatch from pynecone.utils.watch import AssetFolderWatch
if TYPE_CHECKING: if TYPE_CHECKING:
from pynecone.app import App from pynecone.app import App

View File

@ -67,7 +67,7 @@ class Telemetry(Base):
python_version: str = get_python_version() python_version: str = get_python_version()
def pynecone_telemetry(event: str, telemetry_enabled: bool) -> None: def send(event: str, telemetry_enabled: bool) -> None:
"""Send anonymous telemetry for Pynecone. """Send anonymous telemetry for Pynecone.
Args: Args:

View File

@ -1,6 +1,6 @@
import json import json
from pynecone import telemetry from pynecone.utils import telemetry
def versiontuple(v): def versiontuple(v):