|
@@ -11,6 +11,12 @@ class ReflexJinjaEnvironment(Environment):
|
|
|
|
|
|
def __init__(self) -> None:
|
|
|
"""Set default environment."""
|
|
|
+ from reflex.state import (
|
|
|
+ FrontendEventExceptionState,
|
|
|
+ OnLoadInternalState,
|
|
|
+ UpdateVarsInternalState,
|
|
|
+ )
|
|
|
+
|
|
|
extensions = ["jinja2.ext.debug"]
|
|
|
super().__init__(
|
|
|
extensions=extensions,
|
|
@@ -42,9 +48,9 @@ class ReflexJinjaEnvironment(Environment):
|
|
|
"set_color_mode": constants.ColorMode.SET,
|
|
|
"use_color_mode": constants.ColorMode.USE,
|
|
|
"hydrate": constants.CompileVars.HYDRATE,
|
|
|
- "on_load_internal": constants.CompileVars.ON_LOAD_INTERNAL,
|
|
|
- "update_vars_internal": constants.CompileVars.UPDATE_VARS_INTERNAL,
|
|
|
- "frontend_exception_state": constants.CompileVars.FRONTEND_EXCEPTION_STATE_FULL,
|
|
|
+ "on_load_internal": f"{OnLoadInternalState.get_name()}.on_load_internal",
|
|
|
+ "update_vars_internal": f"{UpdateVarsInternalState.get_name()}.update_vars_internal",
|
|
|
+ "frontend_exception_state": FrontendEventExceptionState.get_full_name(),
|
|
|
}
|
|
|
|
|
|
|
|
@@ -60,61 +66,172 @@ def get_template(name: str) -> Template:
|
|
|
return ReflexJinjaEnvironment().get_template(name=name)
|
|
|
|
|
|
|
|
|
-# Template for the Reflex config file.
|
|
|
-RXCONFIG = get_template("app/rxconfig.py.jinja2")
|
|
|
+def rxconfig():
|
|
|
+ """Template for the Reflex config file.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the Reflex config file.
|
|
|
+ """
|
|
|
+ return get_template("app/rxconfig.py.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def document_root():
|
|
|
+ """Code to render a NextJS Document root.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the NextJS Document root.
|
|
|
+ """
|
|
|
+ return get_template("web/pages/_document.js.jinja2")
|
|
|
|
|
|
-# Code to render a NextJS Document root.
|
|
|
-DOCUMENT_ROOT = get_template("web/pages/_document.js.jinja2")
|
|
|
|
|
|
-# Code to render NextJS App root.
|
|
|
-APP_ROOT = get_template("web/pages/_app.js.jinja2")
|
|
|
+def app_root():
|
|
|
+ """Code to render NextJS App root.
|
|
|
|
|
|
-# Template for the theme file.
|
|
|
-THEME = get_template("web/utils/theme.js.jinja2")
|
|
|
+ Returns:
|
|
|
+ Template: The template for the NextJS App root.
|
|
|
+ """
|
|
|
+ return get_template("web/pages/_app.js.jinja2")
|
|
|
|
|
|
-# Template for the context file.
|
|
|
-CONTEXT = get_template("web/utils/context.js.jinja2")
|
|
|
|
|
|
-# Template for Tailwind config.
|
|
|
-TAILWIND_CONFIG = get_template("web/tailwind.config.js.jinja2")
|
|
|
+def theme():
|
|
|
+ """Template for the theme file.
|
|
|
|
|
|
-# Template to render a component tag.
|
|
|
-COMPONENT = get_template("web/pages/component.js.jinja2")
|
|
|
+ Returns:
|
|
|
+ Template: The template for the theme file.
|
|
|
+ """
|
|
|
+ return get_template("web/utils/theme.js.jinja2")
|
|
|
|
|
|
-# Code to render a single NextJS page.
|
|
|
-PAGE = get_template("web/pages/index.js.jinja2")
|
|
|
|
|
|
-# Code to render the custom components page.
|
|
|
-COMPONENTS = get_template("web/pages/custom_component.js.jinja2")
|
|
|
+def context():
|
|
|
+ """Template for the context file.
|
|
|
|
|
|
-# Code to render Component instances as part of StatefulComponent
|
|
|
-STATEFUL_COMPONENT = get_template("web/pages/stateful_component.js.jinja2")
|
|
|
+ Returns:
|
|
|
+ Template: The template for the context file.
|
|
|
+ """
|
|
|
+ return get_template("web/utils/context.js.jinja2")
|
|
|
|
|
|
-# Code to render StatefulComponent to an external file to be shared
|
|
|
-STATEFUL_COMPONENTS = get_template("web/pages/stateful_components.js.jinja2")
|
|
|
|
|
|
-# Sitemap config file.
|
|
|
-SITEMAP_CONFIG = "module.exports = {config}".format
|
|
|
+def tailwind_config():
|
|
|
+ """Template for Tailwind config.
|
|
|
|
|
|
-# Code to render the root stylesheet.
|
|
|
-STYLE = get_template("web/styles/styles.css.jinja2")
|
|
|
+ Returns:
|
|
|
+ Template: The template for the Tailwind config
|
|
|
+ """
|
|
|
+ return get_template("web/tailwind.config.js.jinja2")
|
|
|
|
|
|
-# Code that generate the package json file
|
|
|
-PACKAGE_JSON = get_template("web/package.json.jinja2")
|
|
|
|
|
|
-# Code that generate the pyproject.toml file for custom components.
|
|
|
-CUSTOM_COMPONENTS_PYPROJECT_TOML = get_template(
|
|
|
- "custom_components/pyproject.toml.jinja2"
|
|
|
-)
|
|
|
+def component():
|
|
|
+ """Template to render a component tag.
|
|
|
|
|
|
-# Code that generates the README file for custom components.
|
|
|
-CUSTOM_COMPONENTS_README = get_template("custom_components/README.md.jinja2")
|
|
|
+ Returns:
|
|
|
+ Template: The template for the component tag.
|
|
|
+ """
|
|
|
+ return get_template("web/pages/component.js.jinja2")
|
|
|
|
|
|
-# Code that generates the source file for custom components.
|
|
|
-CUSTOM_COMPONENTS_SOURCE = get_template("custom_components/src.py.jinja2")
|
|
|
|
|
|
-# Code that generates the init file for custom components.
|
|
|
-CUSTOM_COMPONENTS_INIT_FILE = get_template("custom_components/__init__.py.jinja2")
|
|
|
+def page():
|
|
|
+ """Code to render a single NextJS page.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the NextJS page.
|
|
|
+ """
|
|
|
+ return get_template("web/pages/index.js.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def components():
|
|
|
+ """Code to render the custom components page.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the custom components page.
|
|
|
+ """
|
|
|
+ return get_template("web/pages/custom_component.js.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def stateful_component():
|
|
|
+ """Code to render Component instances as part of StatefulComponent.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the StatefulComponent.
|
|
|
+ """
|
|
|
+ return get_template("web/pages/stateful_component.js.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def stateful_components():
|
|
|
+ """Code to render StatefulComponent to an external file to be shared.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the StatefulComponent.
|
|
|
+ """
|
|
|
+ return get_template("web/pages/stateful_components.js.jinja2")
|
|
|
+
|
|
|
|
|
|
-# Code that generates the demo app main py file for testing custom components.
|
|
|
-CUSTOM_COMPONENTS_DEMO_APP = get_template("custom_components/demo_app.py.jinja2")
|
|
|
+def sitemap_config():
|
|
|
+ """Sitemap config file.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the sitemap config file.
|
|
|
+ """
|
|
|
+ return "module.exports = {config}".format
|
|
|
+
|
|
|
+
|
|
|
+def style():
|
|
|
+ """Code to render the root stylesheet.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the root stylesheet
|
|
|
+ """
|
|
|
+ return get_template("web/styles/styles.css.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def package_json():
|
|
|
+ """Code that generate the package json file.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the package json file
|
|
|
+ """
|
|
|
+ return get_template("web/package.json.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def custom_components_pyproject_toml():
|
|
|
+ """Code that generate the pyproject.toml file for custom components.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the pyproject.toml file
|
|
|
+ """
|
|
|
+ return get_template("custom_components/pyproject.toml.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def custom_components_readme():
|
|
|
+ """Code that generates the README file for custom components.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the README file
|
|
|
+ """
|
|
|
+ return get_template("custom_components/README.md.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def custom_components_source():
|
|
|
+ """Code that generates the source file for custom components.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the source file
|
|
|
+ """
|
|
|
+ return get_template("custom_components/src.py.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def custom_components_init():
|
|
|
+ """Code that generates the init file for custom components.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the init file
|
|
|
+ """
|
|
|
+ return get_template("custom_components/__init__.py.jinja2")
|
|
|
+
|
|
|
+
|
|
|
+def custom_components_demo_app():
|
|
|
+ """Code that generates the demo app main py file for testing custom components.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ Template: The template for the demo app main py file
|
|
|
+ """
|
|
|
+ return get_template("custom_components/demo_app.py.jinja2")
|