From b8eaa649c6ccbdd6f3c4e64ec12fbfc42d8242ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 24 Apr 2019 15:17:55 +0200 Subject: [PATCH] [REF] playground: load templates from a xml file --- playground/src/app.js | 60 ++++-------------------------------- playground/src/templates.xml | 45 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 54 deletions(-) create mode 100644 playground/src/templates.xml diff --git a/playground/src/app.js b/playground/src/app.js index cdb401fa..e44bc201 100644 --- a/playground/src/app.js +++ b/playground/src/app.js @@ -1,7 +1,5 @@ import { SAMPLES } from "./samples.js"; -const { QWeb, Component } = owl; - const MODES = { js: "ace/mode/javascript", css: "ace/mode/css", @@ -14,20 +12,10 @@ const DEFAULT_XML = ` //------------------------------------------------------------------------------ // Tabbed editor //------------------------------------------------------------------------------ -const EDITOR_TEMPLATE = ` -
-
- JS - XML - CSS -
-
-
`; - -class TabbedEditor extends Component { +class TabbedEditor extends owl.Component { constructor() { super(...arguments); - this.inlineTemplate = EDITOR_TEMPLATE; + this.template = "tabbed-editor"; this.state = { currentTab: this.props.display.split("|")[0] }; @@ -102,49 +90,12 @@ class TabbedEditor extends Component { //------------------------------------------------------------------------------ // MAIN APP //------------------------------------------------------------------------------ - -const TEMPLATE = ` -
-
- - - - - - -
- - -
-
-
-
-
🦉 Odoo Web Library 🦉
-
v
- -
Note: these examples require a recent browser to work without a transpilation step.
-
-
- -
-
-
-
`; - -class App extends Component { +class App extends owl.Component { constructor(...args) { super(...args); + this.template = "playground"; this.version = owl._version; this.SAMPLES = SAMPLES; - this.inlineTemplate = TEMPLATE; this.widgets = { TabbedEditor }; this.state = { @@ -279,7 +230,8 @@ class App extends Component { //------------------------------------------------------------------------------ document.title = `${document.title} (v${owl._version})`; document.addEventListener("DOMContentLoaded", async function() { - const qweb = new QWeb(); + const templates = await owl.utils.loadTemplates("src/templates.xml"); + const qweb = new owl.QWeb(templates); const env = { qweb }; const app = new App(env); app.mount(document.body); diff --git a/playground/src/templates.xml b/playground/src/templates.xml new file mode 100644 index 00000000..74f2a9fa --- /dev/null +++ b/playground/src/templates.xml @@ -0,0 +1,45 @@ + +
+
+ JS + XML + CSS +
+
+
+ +
+
+ + + + + + +
+ + +
+
+
+
+
🦉 Odoo Web Library 🦉
+
v
+ +
Note: these examples require a recent browser to work without a transpilation step.
+
+
+ +
+
+
+
+ \ No newline at end of file