Skip to content

Commit

Permalink
Merge pull request #16 from Kitware/add-translator-support
Browse files Browse the repository at this point in the history
feat(translator): template patching via translator
  • Loading branch information
jourdain authored Dec 8, 2023
2 parents 8c67f76 + c08f80f commit 0e854ac
Show file tree
Hide file tree
Showing 22 changed files with 550 additions and 40 deletions.
2 changes: 1 addition & 1 deletion examples/test/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from trame.ui.html import DivLayout
from trame.widgets import html

server = get_server()
server = get_server(client_type="vue3")

# Test to dynamically add a fake directive
html.Div.register_directive("v_seb_directive")
Expand Down
2 changes: 1 addition & 1 deletion examples/test/reactivity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from trame.app import get_server
from trame_client.utils.testing import enable_testing

server = get_server()
server = get_server(client_type="vue3")
server.state.count = 1
server.state.trame__template_main = """
<div>
Expand Down
3 changes: 1 addition & 2 deletions examples/vue2/client_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from trame.widgets import html, client
from trame.ui.html import DivLayout

server = get_server()
server.client_type = "vue2"
server = get_server(client_type="vue2")
state, ctrl = server.state, server.controller

dyna_var_count = 1
Expand Down
3 changes: 1 addition & 2 deletions examples/vue2/core_reactive_state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from trame.app import get_server

server = get_server()
server.client_type = "vue2" # default until trame>=3.x
server = get_server(client_type="vue2")
state, ctrl = server.state, server.controller

state.count = 2
Expand Down
3 changes: 1 addition & 2 deletions examples/vue2/dynamic_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from trame.ui.html import DivLayout
from trame_client.utils.testing import enable_testing

server = enable_testing(get_server(), "count")
server.client_type = "vue2"
server = enable_testing(get_server(client_type="vue2"), "count")
state, ctrl = server.state, server.controller

state.count = 1
Expand Down
3 changes: 1 addition & 2 deletions examples/vue2/getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
# Trame setup
# -----------------------------------------------------------------------------

server = get_server()
server.client_type = "vue2"
server = get_server(client_type="vue2")
state, ctrl = server.state, server.controller

state.message_1 = "Hello 1"
Expand Down
3 changes: 1 addition & 2 deletions examples/vue2/js_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from trame.ui.html import DivLayout
from trame_client.utils.testing import enable_testing

server = enable_testing(get_server(), "message")
server.client_type = "vue2"
server = enable_testing(get_server(client_type="vue2"), "message")
state, ctrl = server.state, server.controller


Expand Down
3 changes: 1 addition & 2 deletions examples/vue2/life_cycle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from trame.app import get_server

server = get_server()
server.client_type = "vue2"
server = get_server(client_type="vue2")
ctrl = server.controller
server.state.trame__template_main = "Life Cycle App"

Expand Down
31 changes: 31 additions & 0 deletions examples/vue2/namespace_nested.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from trame.app import get_server

import sys
import os

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../tests"))
from test_translator import NestedApp # noqa: E402

CLIENT_TYPE = "vue2"
ISOLATED = False


def main():
root_server = get_server(client_type=CLIENT_TYPE)

root_app = NestedApp(root_server, client_type=CLIENT_TYPE)

if not ISOLATED:
root_app.child_a_app.server.translator.add_translation("f", "common_f")
root_app.child_b_app.server.translator.add_translation("f", "common_f")

root_app.ui

root_server.controller.on_server_ready.add(
lambda **kwargs: print("Root server ready")
)
root_app.server.start()


if __name__ == "__main__":
main()
34 changes: 34 additions & 0 deletions examples/vue2/namespace_prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from trame.app import get_server

import sys
import os

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../tests"))
from test_translator import BasicApp # noqa: E402

CLIENT_TYPE = "vue2"


def main():
root_server = get_server(client_type=CLIENT_TYPE)
one_of_the_app = None
for app_name in ["main", "a", "b", "c"]:
child_server = root_server.create_child_server(prefix=f"{app_name}_")
app = BasicApp(child_server, app_name, CLIENT_TYPE)
app.ui
app.add()
app.ctrl.plus()
one_of_the_app = app

# root_server.controller.on_server_ready.add(lambda **kwargs: print(json.dumps(root_server.state.to_dict(), indent=2)))
root_server.controller.on_server_ready.add(
lambda **kwargs: print("Root server ready")
)
one_of_the_app.server.controller.on_server_ready.add(
lambda **kwargs: print("Sub server ready")
)
one_of_the_app.server.start()


if __name__ == "__main__":
main()
3 changes: 1 addition & 2 deletions examples/vue3/client_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from trame.widgets import html, client
from trame.ui.html import DivLayout

server = get_server()
server.client_type = "vue3"
server = get_server(client_type="vue3")
state, ctrl = server.state, server.controller

dyna_var_count = 1
Expand Down
3 changes: 1 addition & 2 deletions examples/vue3/core_reactive_state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from trame.app import get_server

server = get_server()
server.client_type = "vue3"
server = get_server(client_type="vue3")
state, ctrl = server.state, server.controller

state.count = 2
Expand Down
3 changes: 1 addition & 2 deletions examples/vue3/dynamic_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from trame.ui.html import DivLayout
from trame_client.utils.testing import enable_testing

server = get_server()
server.client_type = "vue3"
server = get_server(client_type="vue3")
state, ctrl = server.state, server.controller

state.count = 1
Expand Down
3 changes: 1 addition & 2 deletions examples/vue3/getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
# Trame setup
# -----------------------------------------------------------------------------

server = get_server()
server.client_type = "vue3"
server = get_server(client_type="vue3")
state, ctrl = server.state, server.controller

state.message_1 = "Hello 1"
Expand Down
3 changes: 1 addition & 2 deletions examples/vue3/js_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from trame.ui.html import DivLayout
from trame_client.utils.testing import enable_testing

server = enable_testing(get_server(), "message")
server.client_type = "vue3"
server = enable_testing(get_server(client_type="vue3"), "message")
state, ctrl = server.state, server.controller


Expand Down
3 changes: 1 addition & 2 deletions examples/vue3/life_cycle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from trame.app import get_server

server = get_server()
server.client_type = "vue3"
server = get_server(client_type="vue3")
ctrl = server.controller
server.state.trame__template_main = "Life Cycle App"

Expand Down
31 changes: 31 additions & 0 deletions examples/vue3/namespace_nested.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from trame.app import get_server

import sys
import os

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../tests"))
from test_translator import NestedApp # noqa: E402

CLIENT_TYPE = "vue3"
ISOLATED = False


def main():
root_server = get_server(client_type=CLIENT_TYPE)

root_app = NestedApp(root_server, client_type=CLIENT_TYPE)

if not ISOLATED:
root_app.child_a_app.server.translator.add_translation("f", "common_f")
root_app.child_b_app.server.translator.add_translation("f", "common_f")

root_app.ui

root_server.controller.on_server_ready.add(
lambda **kwargs: print("Root server ready")
)
root_app.server.start()


if __name__ == "__main__":
main()
34 changes: 34 additions & 0 deletions examples/vue3/namespace_prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from trame.app import get_server

import sys
import os

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../tests"))
from test_translator import BasicApp # noqa: E402

CLIENT_TYPE = "vue3"


def main():
root_server = get_server(client_type=CLIENT_TYPE)
one_of_the_app = None
for app_name in ["main", "a", "b", "c"]:
child_server = root_server.create_child_server(prefix=f"{app_name}_")
app = BasicApp(child_server, app_name, CLIENT_TYPE)
app.ui
app.add()
app.ctrl.plus()
one_of_the_app = app

# root_server.controller.on_server_ready.add(lambda **kwargs: print(json.dumps(root_server.state.to_dict(), indent=2)))
root_server.controller.on_server_ready.add(
lambda **kwargs: print("Root server ready")
)
one_of_the_app.server.controller.on_server_ready.add(
lambda **kwargs: print("Sub server ready")
)
one_of_the_app.server.start()


if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ seleniumbase
pixelmatch
Pillow
pytest-xprocess
trame
trame
trame-server>=2.13.1
Loading

0 comments on commit 0e854ac

Please sign in to comment.