Skip to content

Commit

Permalink
Collect styles and templates as separate packages under static folder
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Jul 11, 2024
1 parent 1c79b52 commit d92174c
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions qe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
"from IPython.display import display\n",
"from jinja2 import Environment\n",
"\n",
"from aiidalab_qe.app import App, static\n",
"from aiidalab_qe.app import App\n",
"from aiidalab_qe.app.static import templates, styles\n",
"\n",
"from aiidalab_qe.version import __version__"
]
},
Expand All @@ -61,8 +63,8 @@
"source": [
"env = Environment()\n",
"\n",
"template = files(static).joinpath(\"welcome.jinja\").read_text()\n",
"style = files(static).joinpath(\"style.css\").read_text()\n",
"template = files(templates).joinpath(\"welcome.jinja\").read_text()\n",
"style = files(styles).joinpath(\"style.css\").read_text()\n",
"welcome_message = ipw.HTML(env.from_string(template).render(style=style))\n",
"current_year = datetime.now().year\n",
"footer = ipw.HTML(\n",
Expand Down
8 changes: 4 additions & 4 deletions src/aiidalab_qe/app/result/summary_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ def _generate_report_html(report):
"""Read from the bulider parameters and generate a html for reporting
the inputs for the `QeAppWorkChain`.
"""
from importlib import resources
from importlib.resources import files

from jinja2 import Environment

from aiidalab_qe.app import static
from aiidalab_qe.app.static import styles, templates

def _fmt_yes_no(truthy):
return "Yes" if truthy else "No"
Expand All @@ -168,8 +168,8 @@ def _fmt_yes_no(truthy):
"fmt_yes_no": _fmt_yes_no,
}
)
template = resources.read_text(static, "workflow_summary.jinja")
style = resources.read_text(static, "style.css")
template = files(templates).joinpath("workflow_summary.jinja").read_text()
style = files(styles).joinpath("style.css").read_text()
report = {key: value for key, value in report.items() if value is not None}

return env.from_string(template).render(style=style, **report)
Expand Down
8 changes: 4 additions & 4 deletions src/aiidalab_qe/app/result/workchain_viewer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import shutil
import typing as t
from importlib import resources
from importlib.resources import files
from pathlib import Path
from tempfile import TemporaryDirectory

Expand All @@ -16,7 +16,7 @@
from IPython.display import HTML, display
from jinja2 import Environment

from aiidalab_qe.app import static
from aiidalab_qe.app.static import styles, templates
from aiidalab_qe.app.utils import get_entry_items

from .summary_viewer import SummaryView
Expand Down Expand Up @@ -173,8 +173,8 @@ def __init__(self, node, export_dir=None, **kwargs):
)
final_calcjob = self._get_final_calcjob(node)
env = Environment()
template = resources.read_text(static, "workflow_failure.jinja")
style = resources.read_text(static, "style.css")
template = files(templates).joinpath("workflow_failure.jinja").read_text()
style = files(styles).joinpath("style.css").read_text()
output = ipw.HTML(
env.from_string(template).render(
style=style,
Expand Down
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.

0 comments on commit d92174c

Please sign in to comment.