Combine all required CodeMirror3 CSS and JS at build time
Instead of loading a list of script elements at runtime combine required script fragments together at build time into one file. This cleans up the Loader class and allows the browser to perform a single HTTP GET to download the JavaScript code at runtime. Include CodeMirror3's license text as part of the CSS and JavaScript that is downloaded by browsers. Change-Id: I0cd2b5924da1eda9b9445e6a64752ff59f21b64b
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package net.codemirror.addon;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.resources.client.ClientBundle;
|
||||
import com.google.gwt.resources.client.DataResource;
|
||||
import com.google.gwt.resources.client.DataResource.DoNotEmbed;
|
||||
import com.google.gwt.resources.client.ExternalTextResource;
|
||||
|
||||
public interface Addons extends ClientBundle {
|
||||
public static final Addons I = GWT.create(Addons.class);
|
||||
|
||||
@Source("selection/mark-selection.js")
|
||||
@DoNotEmbed
|
||||
DataResource mark_selection();
|
||||
|
||||
@Source("edit/trailingspace.js")
|
||||
@DoNotEmbed
|
||||
DataResource trailingspace();
|
||||
|
||||
@Source("dialog/dialog.css")
|
||||
ExternalTextResource dialogCss();
|
||||
|
||||
@Source("dialog/dialog.js")
|
||||
@DoNotEmbed
|
||||
DataResource dialog();
|
||||
|
||||
@Source("search/searchcursor.js")
|
||||
@DoNotEmbed
|
||||
DataResource searchcursor();
|
||||
|
||||
@Source("search/search.js")
|
||||
@DoNotEmbed
|
||||
DataResource search();
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package net.codemirror.keymap;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.resources.client.ClientBundle;
|
||||
import com.google.gwt.resources.client.DataResource;
|
||||
import com.google.gwt.resources.client.DataResource.DoNotEmbed;
|
||||
|
||||
public interface Keymap extends ClientBundle {
|
||||
static final Keymap I = GWT.create(Keymap.class);
|
||||
|
||||
@Source("vim.js")
|
||||
@DoNotEmbed
|
||||
DataResource vim();
|
||||
}
|
@@ -23,10 +23,10 @@ import com.google.gwt.resources.client.ExternalTextResource;
|
||||
interface Lib extends ClientBundle {
|
||||
static final Lib I = GWT.create(Lib.class);
|
||||
|
||||
@Source("codemirror.css")
|
||||
@Source("cm3.css")
|
||||
ExternalTextResource css();
|
||||
|
||||
@Source("codemirror.js")
|
||||
@Source("cm3.js")
|
||||
@DoNotEmbed
|
||||
DataResource js();
|
||||
}
|
||||
|
@@ -14,7 +14,6 @@
|
||||
|
||||
package net.codemirror.lib;
|
||||
|
||||
import com.google.gerrit.client.rpc.CallbackGroup;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gwt.core.client.Callback;
|
||||
import com.google.gwt.core.client.ScriptInjector;
|
||||
@@ -27,9 +26,6 @@ import com.google.gwt.resources.client.TextResource;
|
||||
import com.google.gwt.safehtml.shared.SafeUri;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
import net.codemirror.addon.Addons;
|
||||
import net.codemirror.keymap.Keymap;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -42,32 +38,11 @@ class Loader {
|
||||
cb.onSuccess(null);
|
||||
} else {
|
||||
injectCss(Lib.I.css());
|
||||
injectCss(Addons.I.dialogCss());
|
||||
injectScript(Lib.I.js().getSafeUri(), new GerritCallback<Void>(){
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
CallbackGroup group = new CallbackGroup();
|
||||
injectScript(Keymap.I.vim().getSafeUri(),
|
||||
group.add(new AsyncCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
initDisableUnwantedKeys();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
}
|
||||
}));
|
||||
injectScript(Addons.I.dialog().getSafeUri(),
|
||||
group.add(CallbackGroup.<Void>emptyCallback()));
|
||||
injectScript(Addons.I.searchcursor().getSafeUri(),
|
||||
group.add(CallbackGroup.<Void>emptyCallback()));
|
||||
injectScript(Addons.I.search().getSafeUri(),
|
||||
group.add(CallbackGroup.<Void>emptyCallback()));
|
||||
injectScript(Addons.I.mark_selection().getSafeUri(),
|
||||
group.add(CallbackGroup.<Void>emptyCallback()));
|
||||
injectScript(Addons.I.trailingspace().getSafeUri(),
|
||||
group.addFinal(cb));
|
||||
initDisableUnwantedKeys();
|
||||
cb.onSuccess(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -1,9 +1,46 @@
|
||||
include_defs('//lib/maven.defs')
|
||||
include_defs('//lib/codemirror/cm3.defs')
|
||||
|
||||
VERSION = 'b05b96e030'
|
||||
SHA1 = '42c541dfdeb877ad726d265e7b1e7da0d429af84'
|
||||
URL = GERRIT + 'net/codemirror/codemirror-%s.zip' % VERSION
|
||||
|
||||
ZIP = 'codemirror-%s.zip' % VERSION
|
||||
TOP = 'codemirror-%s' % VERSION
|
||||
|
||||
genrule(
|
||||
name = 'css',
|
||||
cmd = ';'.join([
|
||||
':>$OUT',
|
||||
"echo '/** @license' >>$OUT",
|
||||
'unzip -p $SRCDIR/%s %s/LICENSE >>$OUT' % (ZIP, TOP),
|
||||
"echo '*/' >>$OUT",
|
||||
] +
|
||||
['unzip -p $SRCDIR/%s %s/%s >>$OUT' % (ZIP, TOP, n)
|
||||
for n in CM3_CSS]
|
||||
),
|
||||
srcs = [genfile(ZIP)],
|
||||
deps = [':download'],
|
||||
out = 'cm3.css',
|
||||
)
|
||||
|
||||
# TODO(sop) Minify with Closure JavaScript compiler.
|
||||
genrule(
|
||||
name = 'js',
|
||||
cmd = ';'.join([
|
||||
':>$OUT',
|
||||
"echo '/** @license' >>$OUT",
|
||||
'unzip -p $SRCDIR/%s %s/LICENSE >>$OUT' % (ZIP, TOP),
|
||||
"echo '*/' >>$OUT",
|
||||
] +
|
||||
['unzip -p $SRCDIR/%s %s/%s >>$OUT' % (ZIP, TOP, n)
|
||||
for n in CM3_JS]
|
||||
),
|
||||
srcs = [genfile(ZIP)],
|
||||
deps = [':download'],
|
||||
out = 'cm3.js',
|
||||
)
|
||||
|
||||
prebuilt_jar(
|
||||
name = 'codemirror',
|
||||
binary_jar = genfile('codemirror.jar'),
|
||||
@@ -14,20 +51,30 @@ prebuilt_jar(
|
||||
visibility = ['PUBLIC'],
|
||||
)
|
||||
|
||||
# TODO(sop) Repackage by license boundaries.
|
||||
# TODO(sop) Minify with Closure JS compiler.
|
||||
genrule(
|
||||
name = 'jar',
|
||||
cmd = ';'.join([
|
||||
'cd $TMP',
|
||||
'mkdir net META-INF',
|
||||
'unzip -d net $SRCS',
|
||||
'mv net/codemirror-%s net/codemirror' % VERSION,
|
||||
'echo "Manifest-Version: 1.0" >META-INF/MANIFEST.MF',
|
||||
'zip -r $OUT *'
|
||||
'unzip -q $SRCDIR/%s %s' % (
|
||||
ZIP,
|
||||
' '.join(['%s/mode/%s' % (TOP, n) for n in CM3_MODES])),
|
||||
'mkdir net',
|
||||
'mv %s net/codemirror' % TOP,
|
||||
'mkdir net/codemirror/lib',
|
||||
'mv $SRCDIR/cm3.css net/codemirror/lib',
|
||||
'mv $SRCDIR/cm3.js net/codemirror/lib',
|
||||
'zip -qr $OUT *'
|
||||
]),
|
||||
srcs = [genfile('codemirror-' + VERSION + '.zip')],
|
||||
deps = [':download'],
|
||||
srcs = [
|
||||
genfile(ZIP),
|
||||
genfile('cm3.css'),
|
||||
genfile('cm3.js'),
|
||||
],
|
||||
deps = [
|
||||
':download',
|
||||
':css',
|
||||
':js',
|
||||
],
|
||||
out = 'codemirror.jar',
|
||||
)
|
||||
|
||||
|
28
lib/codemirror/cm3.defs
Normal file
28
lib/codemirror/cm3.defs
Normal file
@@ -0,0 +1,28 @@
|
||||
CM3_CSS = [
|
||||
'lib/codemirror.css',
|
||||
'addon/dialog/dialog.css',
|
||||
]
|
||||
|
||||
CM3_JS = [
|
||||
'lib/codemirror.js',
|
||||
'keymap/vim.js',
|
||||
'addon/dialog/dialog.js',
|
||||
'addon/search/searchcursor.js',
|
||||
'addon/search/search.js',
|
||||
'addon/selection/mark-selection.js',
|
||||
'addon/edit/trailingspace.js',
|
||||
]
|
||||
|
||||
CM3_MODES = [
|
||||
'clike/clike.js',
|
||||
'css/css.js',
|
||||
'go/go.js',
|
||||
'htmlmixed/htmlmixed.js',
|
||||
'javascript/javascript.js',
|
||||
'properties/properties.js',
|
||||
'python/python.js',
|
||||
'shell/shell.js',
|
||||
'sql/sql.js',
|
||||
'velocity/velocity.js',
|
||||
'xml/xml.js',
|
||||
]
|
Reference in New Issue
Block a user