Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Use template extensions to share code between welcome and notebook pages

  • Loading branch information...
KesterTong committed Aug 22, 2014
1 parent 3c868ea commit 0822e72b118deef39d5a04bb7291e393e88eb60b
@@ -6,7 +6,8 @@
import shutil
import urllib

from jinja2 import Template
from jinja2 import Environment
from jinja2 import FileSystemLoader

from install_lib import COLAB_ROOT_PATH
from install_lib import pjoin
@@ -51,11 +52,12 @@ def BundleStatic(colab_root, dest, extra_template_args=None):
CopyTreeRecursively(closure, pjoin(dest, 'closure'))

# instantiate templates and stage the /, /welcome/, and /notebook/ URLs
template_path = os.path.join(colab_resources, "colab")
env = Environment(loader=FileSystemLoader(template_path))

CopyTreeRecursively(colab_static, pjoin(dest, 'static'))
for name in ['welcome', 'notebook']:
s = pjoin(colab_resources, 'colab', name + os.extsep + 'html');
with open(s) as f:
template = Template(f.read());
template = env.get_template(name + os.extsep + 'html');

for d in [pjoin(dest, name, 'index' + os.extsep + 'html'), pjoin(dest, 'colab', name + os.extsep + 'html')]:
path, filename = os.path.split(d)
@@ -21,15 +21,15 @@ goog.require('goog.Promise');
* Whether this webpage is being run inside a webview in a Chrome App.
* @type {boolean}
*/
colab.app.appMode = document.head.getAttribute('data-app-mode') == 'True';
colab.app.appMode = document.body.getAttribute('data-app-mode') == 'True';


/**
* Origin of messages from the Chrome App
* @type {string}
* @private
*/
colab.app.extensionOrigin_ = document.head.getAttribute('data-app-origin');
colab.app.extensionOrigin_ = document.body.getAttribute('data-app-origin');


/**
@@ -1,12 +1,6 @@
<!DOCTYPE html>
<html>
<head
{% extends "page.html" %}

data-app-mode="{{app_mode}}"
data-app-origin="{{app_origin}}"

>
<title>coLaboratory</title>
{% block head %}
<script type="text/javascript">
var pageLoadStart = new Date().getTime();
</script>
@@ -18,12 +12,31 @@

<link rel="stylesheet" href="/ipython/components/codemirror/lib/codemirror.css"/>
<link rel="stylesheet" href="/ipython/components/codemirror/addon/hint/show-hint.css"/>
</head>
<body>

<script src="/ipython/components/jquery/jquery.min.js"></script>
<link rel="stylesheet" href="/extern/polymer/paper-shadow/paper-shadow.css">
<link rel="stylesheet" href="/closure/css/common.css">
<link rel="stylesheet" href="/closure/css/menu.css">
<link rel="stylesheet" href="/closure/css/menubar.css">
<link rel="stylesheet" href="/closure/css/menubutton.css">
<link rel="stylesheet" href="/closure/css/menuitem.css">
<link rel="stylesheet" href="/closure/css/menuseparator.css">
<link rel="stylesheet" href="/closure/css/toolbar.css">
<link rel="stylesheet" href="/closure/css/combobox.css">
<link rel="stylesheet" href="/closure/css/dialog.css">
<link rel="stylesheet" href="/closure/css/tab.css">
<link rel="stylesheet" href="/closure/css/tabbar.css">
<link rel="stylesheet" href="/colab/css/main.css"/>
<link rel="stylesheet" href="/colab/css/cell.css"/>
<link rel="stylesheet" href="/colab/css/celltoolbar.css"/>
<link rel="stylesheet" href="/colab/css/ansi.css"/>
<link rel="stylesheet" href="/colab/css/header.css"/>
<link rel="stylesheet" href="/colab/css/form.css"/>
<link rel="stylesheet" href="/colab/css/comments.css"/>
<link rel="stylesheet" href="/colab/css/ipython.css"/>
{% endblock %}

<script src="/closure/base.js"></script>
{% block js %}
<script src="/ipython/components/jquery/jquery.min.js"></script>

<!-- Load the CodeMirror libraries. -->
<script src="/ipython/components/codemirror/lib/codemirror.js"></script>
@@ -56,42 +69,25 @@
charset="utf-8">
</script>

{% if raw == '1' %}
<script type="text/javascript" src="/colab/js/colab.dep"></script>
<script type="text/javascript">
goog.require('colab');
</script>
{% else %}
<script src="js/modules/js_compiled.js"></script>
{% endif %}


<!-- Load the Markdown libraries. -->
<script type="text/javascript" src="/extern/pagedown/Markdown.Converter.js"></script><style type="text/css"></style>
<script type="text/javascript" src="/extern/pagedown/Markdown.Sanitizer.js"></script>
<script type="text/javascript" src="/extern/pagedown/Markdown.Editor.js"></script>


{% endblock %}

{% block closure_entrypoint %}
<script type="text/javascript">
goog.require('colab');
</script>
{% endblock %}

{% block html %}
<!-- Load bootstrapping code for interactive notebooks -->
<script src="/colab/js/colabtools.js"></script>
<link rel="stylesheet" href="/extern/polymer/paper-shadow/paper-shadow.css">
<link rel="stylesheet" href="/closure/css/common.css">
<link rel="stylesheet" href="/closure/css/menu.css">
<link rel="stylesheet" href="/closure/css/menubar.css">
<link rel="stylesheet" href="/closure/css/menubutton.css">
<link rel="stylesheet" href="/closure/css/menuitem.css">
<link rel="stylesheet" href="/closure/css/menuseparator.css">
<link rel="stylesheet" href="/closure/css/toolbar.css">
<link rel="stylesheet" href="/closure/css/combobox.css">
<link rel="stylesheet" href="/closure/css/dialog.css">
<link rel="stylesheet" href="/closure/css/tab.css">
<link rel="stylesheet" href="/closure/css/tabbar.css">
<link rel="stylesheet" href="/colab/css/main.css"/>
<link rel="stylesheet" href="/colab/css/cell.css"/>
<link rel="stylesheet" href="/colab/css/celltoolbar.css"/>
<link rel="stylesheet" href="/colab/css/ansi.css"/>
<link rel="stylesheet" href="/colab/css/header.css"/>
<link rel="stylesheet" href="/colab/css/form.css"/>
<link rel="stylesheet" href="/colab/css/comments.css"/>
<link rel="stylesheet" href="/colab/css/ipython.css"/>

<div id="top-floater">
<div id="header">
@@ -192,5 +188,4 @@

<!-- Notebook will be inserted here at the end of the document.
Don't add any html after this line -->
</body>
</html>
{% endblock %}
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>

<title>{% block title %}coLaboratory{% endblock %}</title>

{% block head %} {% endblock %}
</head>

<!-- Uses template variables to set data attributes -->
<body data-app-mode="{{app_mode}}" data-app-origin="{{app_origin}}"
{% block params %} {% endblock %}>

{% block js %} {% endblock %}

<script src="/closure/base.js"></script>

{% if raw == '1' %}
<!-- In raw mode, loads colab.dep for dependencies. The closure-entrypoint
block allows extensions of this template to specify goog.require statements
that will load the specified namespace and their dependencies.
-->
<script type="text/javascript" src="/colab/js/colab.dep"></script>
{% block closure_entrypoint %}
<!--
Extensions should override this block with something like
<script type="text/javascript">
goog.require('entrypoint.for.page');
entrypoint.for.page.run();
</script>
-->
{% endblock %}
{% else %}
<script src="js/modules/js_compiled.js"></script>
{% endif %}

{% block html %} {% endblock %}

</body>
</html>
@@ -1,37 +1,26 @@
<!DOCTYPE html>
<html>
<head
{% extends "page.html" %}

data-app-mode="{{app_mode}}"
data-app-origin="{{app_origin}}"

>
<title>coLaboratory</title>

<!-- Load the closure . -->
<!-- For compiled version use js/modules/lib_closure.js
TODO(kayur, sandler): When this becomes a template, we could
switch automatically based on url parameters or config.
-->
<script src="/closure/base.js"></script>
{% block head %}
<link rel="stylesheet" href="/closure/css/common.css">
<link rel="stylesheet" href="/colab/css/header.css"/>
<link rel="stylesheet" href="/colab/css/main.css"/>
<link rel="stylesheet" href="/colab/css/welcome.css"/>
{% endblock %}

{% block js %}
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:300,600">

<!-- Fav icon -->
<link rel="shortcut icon" href="/colab/img/colab-black.png">
{% endblock %}

<script type="text/javascript" src="/colab/js/colab.dep"></script>
<script type="text/javascript">
goog.require('colab.welcome');
</script>

<link rel="stylesheet" href="/closure/css/common.css">
<link rel="stylesheet" href="/colab/css/header.css"/>
<link rel="stylesheet" href="/colab/css/main.css"/>
<link rel="stylesheet" href="/colab/css/welcome.css"/>
</head>
<body>
{% block closure_entrypoint %}
<script type="text/javascript">
goog.require('colab.welcome');
</script>
{% endblock %}

{% block html %}
<div id="main-content">
<div id="welcome-title">Welcome to coLaboratory</div>
<div id="welcome-content">
@@ -110,5 +99,4 @@
</div>
</div>
</div>
</body>
</html>
{% endblock %}

0 comments on commit 0822e72

Please sign in to comment.
You can’t perform that action at this time.