Skip to content

Commit

Permalink
fix(www): Allow www tool to support either vue2 or vue3
Browse files Browse the repository at this point in the history
fix #204
  • Loading branch information
jourdain committed Feb 14, 2023
1 parent 06c3043 commit 363dd53
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
5 changes: 4 additions & 1 deletion docs/api/source/tools.www.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ Or you can also do the following as only the pieces needed will be downloaded by
cd www-all
python -m trame.tools.www
Here is a list of known modules: deckgl, markdown, matplotlib, paraview, plotly, router, trame, vega, vtk, vuetify, www (main client)
Here is a list of known modules: deckgl, markdown, matplotlib, paraview, plotly, router, trame, vega, vtk, vuetify, www (main client)

With the add-on support of vue3 backend, you can now provide which client you want to enable by providing `--client-type vue2` or `--client-type vue3`.
Keep in mind that vue2 UI template are not 100% compatible with their vue3 counter part...
1 change: 1 addition & 0 deletions docs/content/docs/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from trame.ui.vuetify import SinglePageLayout # UI layout
from trame.widgets import vuetify, vtk # UI widgets

server = get_server() # Create/retrieve default server
server.client_type = "vue2" # Choose between vue2 and vue3
state, ctrl = server.state, server.controller # Extract server state and controller

# Reset resolution variable to 6
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ install_requires =
trame-server>=2.9.0
trame-client>=2.1.0
trame-router==2.0.1
trame-vuetify==2.1.0
trame-components==2.1.0
trame-plotly==2.1.0
trame-markdown==2.0.2
trame-matplotlib==2.0.1
trame-deckgl==2.0.1
trame-vega==2.0.2
trame-vuetify<3.0.0
trame-vtk<3.0.0
trame-simput<3.0.0
trame-rca<3.0.0
Expand Down
36 changes: 31 additions & 5 deletions trame/tools/www.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,36 @@ class StaticContentGenerator:
def __init__(self):
self.www = None
self.serve = {}
self.client_type = "vue2"

def enable_all(self):
import pkgutil

root = importlib.import_module("trame.modules")
self.enable_modules(*[m.name for m in pkgutil.iter_modules(root.__path__)])

def add_protocol_to_configure(self, *args, **kwargs):
"""Fake server"""
pass

def enable_module(self, module, **kwargs):
load_remaining = False
if "setup" in module.__dict__:
try:
module.setup(self)
load_remaining = True
except TypeError:
pass # Skip incompatible modules
else:
load_remaining = True

if load_remaining:
if "serve" in module.__dict__:
self.serve.update(module.serve)

if "www" in module.__dict__:
self.www = module.www

def enable_modules(self, *names):
for module_name in names:
module = None
Expand All @@ -35,11 +58,7 @@ def enable_modules(self, *names):
print(f"Skipping module: {module_name}")
continue

if "serve" in module.__dict__:
self.serve.update(module.serve)

if "www" in module.__dict__:
self.www = module.www
self.enable_module(module)

def write(self, output_directory=None):
if output_directory is None:
Expand All @@ -63,8 +82,15 @@ def main():
help="Directory to fill with trame client code",
)

parser.add_argument(
"--client-type",
default="vue2",
help="Type of client to use [vue2, vue3]",
)

args, module_names = parser.parse_known_args()
generator = StaticContentGenerator()
generator.client_type = args.client_type
if len(module_names):
generator.enable_modules(*module_names)
else:
Expand Down

0 comments on commit 363dd53

Please sign in to comment.