Skip to content

Commit

Permalink
get preact from script tag
Browse files Browse the repository at this point in the history
doesn't seem to like loading with require
  • Loading branch information
minrk committed Jan 4, 2017
1 parent 11bd42c commit cbd6eef
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
11 changes: 5 additions & 6 deletions notebook/static/notebook/js/notebook.js
Expand Up @@ -30,9 +30,7 @@ define([
'./celltoolbarpresets/attachments',
'./scrollmanager',
'./commandpalette',
// FIXME: shortcut-editor uses preact,
// which doesn't boewr install
// 'notebook/js/shortcuteditor',
'./shortcuteditor',
], function (
$,
IPython,
Expand All @@ -57,10 +55,11 @@ define([
slideshow_celltoolbar,
attachments_celltoolbar,
scrollmanager,
commandpalette
// ShortcutEditor
commandpalette,
shortcuteditor
) {

var ShortcutEditor = shortcuteditor.ShortcutEditor;
var _SOFT_SELECTION_CLASS = 'jupyter-soft-selected';

function soft_selected(cell){
Expand Down Expand Up @@ -443,7 +442,7 @@ define([

Notebook.prototype.show_shortcuts_editor = function() {
// FIXME: ShortcutEditor disabled for now
// new ShortcutEditor(this);
new ShortcutEditor(this);
};

/**
Expand Down
15 changes: 9 additions & 6 deletions notebook/templates/page.html
Expand Up @@ -16,7 +16,10 @@
{% endblock %}
<link rel="stylesheet" href="{{ base_url }}custom/custom.css" type="text/css" />
<script src="{{static_url("components/es6-promise/promise.min.js")}}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url("components/requirejs/require.js") }}" type="text/javascript" charset="utf-8"></script>
<script src="{{static_url('components/preact/dist/preact.min.js')}}" type="text/javascript"></script>
<script src="{{static_url('components/proptypes/index.js')}}" type="text/javascript"></script>
<script src="{{static_url('components/preact-compat/dist/preact-compat.min.js')}}" type="text/javascript"></script>
<script src="{{static_url('components/requirejs/require.js') }}" type="text/javascript" charset="utf-8"></script>
<script>
require.config({
{% if version_hash %}
Expand All @@ -39,11 +42,11 @@
termjs: 'components/xterm.js/dist/xterm',
typeahead: 'components/jquery-typeahead/dist/jquery.typeahead.min',
},
map: { // for backward compatibility
"*": {
"jqueryui": "jquery-ui",
}
},
map: { // for backward compatibility
"*": {
"jqueryui": "jquery-ui",
}
},
shim: {
typeahead: {
deps: ["jquery"],
Expand Down
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -16,5 +16,9 @@
"bower": "*",
"less": "~2",
"requirejs": "^2.1.17"
},
"dependencies": {
"preact": "^7.1.0",
"preact-compat": "^3.9.4"
}
}
32 changes: 27 additions & 5 deletions setupbase.py
Expand Up @@ -14,9 +14,10 @@
from __future__ import print_function

import os
import pipes
import shutil
import sys

import pipes
from distutils import log
from distutils.cmd import Command
from fnmatch import fnmatch
Expand Down Expand Up @@ -342,6 +343,15 @@ def should_run(self):
return True
if not os.path.exists(self.bower_dir):
return True

# check npm packages
for pkg in ['preact', 'preact-compat', 'proptypes']:
npm_pkg = os.path.join(self.node_modules, pkg)
bower_pkg = os.path.join(self.bower_dir, pkg)
if not os.path.exists(npm_pkg) or not os.path.exists(bower_pkg):
return True
if mtime(bower_pkg) < mtime(npm_pkg):
return True
return mtime(self.bower_dir) < mtime(pjoin(repo_root, 'bower.json'))

def should_run_npm(self):
Expand All @@ -351,7 +361,17 @@ def should_run_npm(self):
if not os.path.exists(self.node_modules):
return True
return mtime(self.node_modules) < mtime(pjoin(repo_root, 'package.json'))


def npm_components(self):
"""Stage npm frontend dependencies into components"""
for pkg in ['preact', 'preact-compat', 'proptypes']:
npm_pkg = os.path.join(self.node_modules, pkg)
bower_pkg = os.path.join(self.bower_dir, pkg)
log.info("Staging %s -> %s" % (npm_pkg, bower_pkg))
if os.path.exists(bower_pkg):
shutil.rmtree(bower_pkg)
shutil.copytree(npm_pkg, bower_pkg)

def run(self):
if not self.should_run():
print("bower dependencies up to date")
Expand All @@ -375,6 +395,7 @@ def run(self):
print("Failed to run bower: %s" % e, file=sys.stderr)
print("You can install js dependencies with `npm install`", file=sys.stderr)
raise
self.npm_components()
os.utime(self.bower_dir, None)
# update package data in case this created new files
update_package_data(self.distribution)
Expand Down Expand Up @@ -444,6 +465,7 @@ def finalize_options(self):

def sources(self, name):
"""Generator yielding .js sources that an application depends on"""
yield pjoin(repo_root, 'tools', 'build-main.js')
yield pjoin(static, name, 'js', 'main.js')

for sec in [name, 'base', 'auth']:
Expand Down Expand Up @@ -549,11 +571,11 @@ def run(self):
# die if strict or any targets didn't build
prefix = os.path.commonprefix([repo_root + os.sep] + missing)
missing = [ m[len(prefix):] for m in missing ]
log.warning("rebuilding js and css failed. The following required files are missing: %s" % missing)
log.warn("rebuilding js and css failed. The following required files are missing: %s" % missing)
raise e
else:
log.warning("rebuilding js and css failed (not a problem)")
log.warning(str(e))
log.warn("rebuilding js and css failed (not a problem)")
log.warn(str(e))

# check again for missing targets, just in case:
missing = [ t for t in targets if not os.path.exists(t) ]
Expand Down
2 changes: 1 addition & 1 deletion tools/build-main.js
Expand Up @@ -54,7 +54,7 @@ var rjs_config = {
"jquery-ui": {
deps: ["jquery"],
exports: "$"
}
},
},

exclude: [
Expand Down

0 comments on commit cbd6eef

Please sign in to comment.