-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from HaudinFlorence/create_theme_exporter
Create theme exporter
- Loading branch information
Showing
22 changed files
with
1,122 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import pytest | ||
|
||
pytest_plugins = ("pytest_jupyter.jupyter_server", ) | ||
|
||
|
||
@pytest.fixture | ||
def jp_server_config(jp_server_config): | ||
return {"ServerApp": {"jpserver_extensions": {"jupyter_theme_editor": True}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"NotebookApp": { | ||
"nbserver_extensions": { | ||
"jupyter_theme_editor": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"ServerApp": { | ||
"jpserver_extensions": { | ||
"jupyter_theme_editor": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,35 @@ | ||
from ._version import __version__ | ||
from .handlers import setup_handlers | ||
|
||
|
||
|
||
def _jupyter_labextension_paths(): | ||
return [{ | ||
"src": "labextension", | ||
"dest": "jupyter-theme-editor" | ||
}] | ||
|
||
|
||
|
||
def _jupyter_server_extension_points(): | ||
return [{ | ||
"module": "jupyter_theme_editor" | ||
}] | ||
|
||
|
||
def _load_jupyter_server_extension(server_app): | ||
"""Registers the API handler to receive HTTP requests from the frontend extension. | ||
Parameters | ||
---------- | ||
server_app: jupyterlab.labapp.LabApp | ||
JupyterLab application instance | ||
""" | ||
setup_handlers(server_app.web_app) | ||
name = "jupyter_theme_editor" | ||
server_app.log.info(f"Registered {name} server extension") | ||
|
||
|
||
# For backward compatibility with notebook server - useful for Binder/JupyterHub | ||
load_jupyter_server_extension = _load_jupyter_server_extension | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import json | ||
from jupyter_server.base.handlers import APIHandler | ||
from jupyter_server.utils import url_path_join | ||
import tornado | ||
from jinja2 import Environment, PackageLoader | ||
from pathlib import Path | ||
|
||
class RouteHandler(APIHandler): | ||
# The following decorator should be present on all verb methods (head, get, post, | ||
# patch, put, delete, options) to ensure only authorized user can request the | ||
# Jupyter server | ||
|
||
def initialize(self, env: Environment, path: str): | ||
self._env = env | ||
self._path = path | ||
|
||
@tornado.web.authenticated | ||
def post(self): | ||
# input_data is a dictionary with a key "name" | ||
input_data = self.get_json_body() | ||
new_input_data = {} | ||
for key, value in input_data.items(): | ||
value = str(input_data[key]) | ||
new_value = value.strip() | ||
new_key = key.replace('--jp-', '').replace('-', '_') | ||
new_input_data[new_key] = new_value | ||
|
||
|
||
j2_template = self._env.get_template(self._path) | ||
output_data = j2_template.render(new_input_data) | ||
self.set_header("content-type", "text/css") | ||
self.set_header("cache-control", "no-cache") | ||
self.set_header("content-disposition", | ||
"attachment; filename=variables.css") | ||
self.set_header("content-length", len(output_data.encode())) | ||
self.finish(output_data) | ||
|
||
|
||
def setup_handlers(web_app): | ||
host_pattern = ".*$" | ||
|
||
base_url = web_app.settings["base_url"] | ||
route_pattern = url_path_join( | ||
base_url, 'jupyter-theme-editor', "send_cssProperties") | ||
handlers = [(route_pattern, RouteHandler, {"env":Environment(loader=PackageLoader( | ||
"jupyter_theme_editor", "templates")), "path": "template.css" })] | ||
web_app.add_handlers(host_pattern, handlers) |
Oops, something went wrong.