瀏覽代碼

wip cleanup and allow for base_url

Steven Silvester 6 年之前
父節點
當前提交
a2aed3b256

+ 5 - 2
examples/app/index.js

@@ -1,8 +1,11 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-// ES6 Promise polyfill
-require('es6-promise/auto');
+import { PageConfig, URLExt } from '@jupyterlab/coreutils';
+__webpack_public_path__ = URLExt.join(
+  PageConfig.getBaseUrl(),
+  'example/static/'
+);
 
 window.addEventListener('load', function() {
   require('font-awesome/css/font-awesome.min.css');

+ 16 - 13
examples/app/main.py

@@ -2,8 +2,9 @@
 # Distributed under the terms of the Modified BSD License.
 
 from jupyterlab_server import LabServerApp, LabConfig
+from notebook.utils import url_path_join as ujoin
 import os
-from traitlets import Unicode
+from traitlets import Unicode, default
 
 HERE = os.path.dirname(__file__)
 
@@ -16,20 +17,22 @@ class ExampleApp(LabServerApp):
     default_url = Unicode('/example',
                           help='The default URL to redirect to from `/`')
 
-    lab_config = LabConfig(
-        app_name = 'JupyterLab Example App',
-        app_settings_dir = os.path.join(HERE, 'build', 'application_settings'),
-        page_url = '/example',
-        schemas_dir = os.path.join(HERE, 'build', 'schemas'),
-        settings_dir = os.path.join(HERE, 'build', 'settings'),
-        static_dir = os.path.join(HERE, 'build'),
-        templates_dir = os.path.join(HERE, 'templates'),
-        themes_dir = os.path.join(HERE, 'build', 'themes'),
-        user_settings_dir = os.path.join(HERE, 'build', 'user_settings'),
-        workspaces_dir = os.path.join(HERE, 'build', 'workspaces'),
-    )
+    def _get_lab_config(self):
+        return LabConfig(
+            app_name = 'JupyterLab Example App',
+            app_settings_dir = os.path.join(HERE, 'build', 'application_settings'),
+            page_url = ujoin(self.base_url, '/example'),
+            schemas_dir = os.path.join(HERE, 'build', 'schemas'),
+            settings_dir = os.path.join(HERE, 'build', 'settings'),
+            static_dir = os.path.join(HERE, 'build'),
+            templates_dir = os.path.join(HERE, 'templates'),
+            themes_dir = os.path.join(HERE, 'build', 'themes'),
+            user_settings_dir = os.path.join(HERE, 'build', 'user_settings'),
+            workspaces_dir = os.path.join(HERE, 'build', 'workspaces'),
+        )
 
     def start(self):
+        self.lab_config = self._get_lab_config()
         settings = self.web_app.settings
 
         # By default, make terminals available.

+ 1 - 1
examples/cell/src/index.ts

@@ -3,7 +3,7 @@
 
 import { PageConfig, URLExt } from '@jupyterlab/coreutils';
 // @ts-ignore
-__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'static');
+__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'example/');
 
 import '@jupyterlab/application/style/index.css';
 import '@jupyterlab/cells/style/index.css';

+ 1 - 1
examples/console/src/index.ts

@@ -3,7 +3,7 @@
 
 import { PageConfig, URLExt } from '@jupyterlab/coreutils';
 // @ts-ignore
-__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'static');
+__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'example/');
 
 import '@jupyterlab/application/style/index.css';
 import '@jupyterlab/console/style/index.css';

+ 1 - 1
examples/example_check.py

@@ -27,7 +27,7 @@ class ExampleCheckApp(mod.ExampleApp):
 
     open_browser = Bool(False)
     default_url = '/example'
-    base_url = '/foo'
+    base_url = '/foo/'
     ip = '127.0.0.1'
 
     def start(self):

+ 1 - 1
examples/filebrowser/src/index.ts

@@ -3,7 +3,7 @@
 
 import { PageConfig, URLExt } from '@jupyterlab/coreutils';
 // @ts-ignore
-__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'static');
+__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'example/');
 
 import '@jupyterlab/application/style/index.css';
 import '@jupyterlab/filebrowser/style/index.css';

+ 1 - 1
examples/notebook/src/index.ts

@@ -3,7 +3,7 @@
 
 import { PageConfig, URLExt } from '@jupyterlab/coreutils';
 // @ts-ignore
-__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'static');
+__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'example/');
 
 import '@jupyterlab/application/style/index.css';
 import '@jupyterlab/notebook/style/index.css';

+ 1 - 1
examples/terminal/src/index.ts

@@ -3,7 +3,7 @@
 
 import { PageConfig, URLExt } from '@jupyterlab/coreutils';
 // @ts-ignore
-__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'static');
+__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'example/');
 
 import '@jupyterlab/application/style/index.css';
 import '@jupyterlab/terminal/style/index.css';

+ 1 - 1
packages/services/examples/browser-require/index.html

@@ -33,6 +33,6 @@
         }
     });
     </script>
-    <script src="example/index.js"></script>
+    <script src="{{base_url}}example/index.js"></script>
   </body>
 </html>

+ 5 - 6
packages/services/examples/browser-require/main.py

@@ -6,6 +6,7 @@ from notebook.notebookapp import NotebookApp
 import os
 from jinja2 import FileSystemLoader
 from notebook.base.handlers import IPythonHandler, FileFindHandler
+from notebook.utils import url_path_join as ujoin
 from traitlets import Unicode
 
 
@@ -27,18 +28,16 @@ class ExampleHander(IPythonHandler):
         return LOADER.load(self.settings['jinja2_env'], name)
 
 
-default_handlers = [
-    (r'/example/?', ExampleHander),
-    (r'/example/(.*)', FileFindHandler, {'path': HERE}),
-]
-
-
 class ExampleApp(NotebookApp):
     """A notebook app that runs the example."""
 
     default_url = Unicode('/example')
 
     def start(self):
+        default_handlers = [
+            (ujoin(self.base_dir, r'/example/?'), ExampleHander),
+            (ujoin(self.base_dir, r'/example/(.*)'), FileFindHandler, {'path': HERE}),
+        ]
         self.web_app.add_handlers('.*$', default_handlers)
         super(ExampleApp, self).start()
 

+ 1 - 1
packages/services/examples/browser/index.html

@@ -6,7 +6,7 @@
   </head>
   <body>
     <script id='jupyter-config-data' type="application/json">{ "baseUrl": "{{base_url}}" }</script>
-    <script src="example/bundle.js"></script>
+    <script src="{{base_url}}example/bundle.js"></script>
     <pre id='output'></pre>
   </body>
 </html>

+ 5 - 5
packages/services/examples/browser/main.py

@@ -6,6 +6,7 @@ from notebook.notebookapp import NotebookApp
 import os.path as osp
 from jinja2 import FileSystemLoader
 from notebook.base.handlers import IPythonHandler, FileFindHandler
+from notebook.utils import url_path_join as ujoin
 from traitlets import Unicode
 
 
@@ -27,17 +28,16 @@ class ExampleHander(IPythonHandler):
         return LOADER.load(self.settings['jinja2_env'], name)
 
 
-default_handlers = [
-    (r'/example/?', ExampleHander),
-    (r'/example/(.*)', FileFindHandler, {'path': osp.join(HERE, 'build')}),
-]
-
 class ExampleApp(NotebookApp):
     """A notebook app that runs the example."""
 
     default_url = Unicode('/example')
 
     def start(self):
+        default_handlers = [
+            (ujoin(self.base_url, r'/example/?'), ExampleHander),
+            (ujoin(self.base_url, r'/example/(.*)'), FileFindHandler, {'path': osp.join(HERE, 'build')}),
+        ]
         self.web_app.add_handlers('.*$', default_handlers)
         super(ExampleApp, self).start()
 

+ 3 - 2
packages/services/examples/browser/src/index.ts

@@ -4,8 +4,9 @@
 | Distributed under the terms of the Modified BSD License.
 |----------------------------------------------------------------------------*/
 
-// Polyfill for ES6 Promises
-import 'es6-promise';
+import { PageConfig, URLExt } from '@jupyterlab/coreutils';
+// @ts-ignore
+__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'example/');
 
 import { Session } from '@jupyterlab/services';
 

+ 1 - 1
packages/services/examples/typescript-browser-with-output/index.html

@@ -6,7 +6,7 @@
   </head>
   <body>
     <script id='jupyter-config-data' type="application/json">{ "baseUrl": "{{base_url}}" }</script>
-    <script src="example/bundle.js"></script>
+    <script src="{{base_url}}example/bundle.js"></script>
     <span id='outputarea'></span>
   </body>
 </html>

+ 6 - 7
packages/services/examples/typescript-browser-with-output/main.py

@@ -6,6 +6,7 @@ from notebook.notebookapp import NotebookApp
 import os
 from jinja2 import FileSystemLoader
 from notebook.base.handlers import IPythonHandler, FileFindHandler
+from notebook.utils import url_path_join as ujoin
 from traitlets import Unicode
 
 
@@ -26,19 +27,17 @@ class ExampleHander(IPythonHandler):
         return LOADER.load(self.settings['jinja2_env'], name)
 
 
-default_handlers = [
-    (r'/example/?', ExampleHander),
-    (r"/example/(.*)", FileFindHandler,
-        {'path': os.path.join(HERE, 'build')}),
-]
-
-
 class ExampleApp(NotebookApp):
     """A notebook app that runs the example."""
 
     default_url = Unicode('/example')
 
     def start(self):
+        default_handlers = [
+            (ujoin(self.base_url, r'/example/?'), ExampleHander),
+            (ujoin(self.base_url, r"/example/(.*)"), FileFindHandler,
+                {'path': os.path.join(HERE, 'build')}),
+        ]
         self.web_app.add_handlers(".*$", default_handlers)
         super(ExampleApp, self).start()
 

+ 3 - 2
packages/services/examples/typescript-browser-with-output/src/index.ts

@@ -4,8 +4,9 @@
 | Distributed under the terms of the Modified BSD License.
 |----------------------------------------------------------------------------*/
 
-// Polyfill for ES6 Promises
-import 'es6-promise';
+import { PageConfig, URLExt } from '@jupyterlab/coreutils';
+// @ts-ignore
+__webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'example/');
 
 import { OutputArea, OutputAreaModel } from '@jupyterlab/outputarea';