reorganize build and demo
Conflicts: Makefile.dryice.js
This commit is contained in:
parent
0f0d12a709
commit
34f3cac4a8
6 changed files with 486 additions and 352 deletions
|
|
@ -38,6 +38,8 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
var fs = require("fs");
|
||||
if (!fs.existsSync)
|
||||
fs.existsSync = require("path").existsSync;
|
||||
var copy = require('dryice').copy;
|
||||
|
||||
var ACE_HOME = __dirname;
|
||||
|
|
@ -47,10 +49,9 @@ function main(args) {
|
|||
if (args.length == 3) {
|
||||
target = args[2];
|
||||
// Check if 'target' contains some allowed value.
|
||||
if (target != "normal" && target != "bm" && target != "demo") {
|
||||
target = null;
|
||||
if (!/^(normal|bm|demo|minimal)$/.test(target))
|
||||
target = "help";
|
||||
}
|
||||
}
|
||||
|
||||
if (target == "help") {
|
||||
console.log("--- Ace Dryice Build Tool ---");
|
||||
|
|
@ -107,7 +108,7 @@ function bookmarklet(aceProject) {
|
|||
exportModule: "ace/ext/textarea",
|
||||
compress: false,
|
||||
noconflict: true,
|
||||
suffix: ".js",
|
||||
suffix: "",
|
||||
name: "ace-bookmarklet",
|
||||
workers: [],
|
||||
keybindings: []
|
||||
|
|
@ -121,13 +122,13 @@ function ace(aceProject) {
|
|||
buildAce(aceProject, {
|
||||
compress: false,
|
||||
noconflict: false,
|
||||
suffix: "-uncompressed",
|
||||
suffix: "",
|
||||
name: "ace"
|
||||
});
|
||||
buildAce(aceProject, {
|
||||
compress: false,
|
||||
noconflict: true,
|
||||
suffix: "-uncompressed-noconflict",
|
||||
suffix: "-noconflict",
|
||||
name: "ace",
|
||||
workers: []
|
||||
});
|
||||
|
|
@ -136,14 +137,14 @@ function ace(aceProject) {
|
|||
buildAce(aceProject, {
|
||||
compress: true,
|
||||
noconflict: false,
|
||||
suffix: "",
|
||||
suffix: "-min",
|
||||
name: "ace",
|
||||
workers: []
|
||||
});
|
||||
buildAce(aceProject, {
|
||||
compress: true,
|
||||
noconflict: true,
|
||||
suffix: "-noconflict",
|
||||
suffix: "-min-noconflict",
|
||||
name: "ace",
|
||||
workers: []
|
||||
});
|
||||
|
|
@ -179,33 +180,65 @@ function demo(aceProject) {
|
|||
ref = "";
|
||||
version = "";
|
||||
}
|
||||
|
||||
copy({
|
||||
source: "kitchen-sink.html",
|
||||
dest: "build/kitchen-sink.html",
|
||||
filter: [ function(data) {
|
||||
var changeComments = function(data) {
|
||||
return (data
|
||||
.replace("DEVEL-->", "")
|
||||
.replace("<!--DEVEL", "")
|
||||
.replace("PACKAGE-->", "")
|
||||
.replace("<!--PACKAGE", "")
|
||||
.replace("DEVEL*/", "")
|
||||
.replace("/*DEVEL", "")
|
||||
.replace("PACKAGE*/", "")
|
||||
.replace("/*PACKAGE", "")
|
||||
.replace("%version%", version)
|
||||
.replace("%commit%", ref)
|
||||
);
|
||||
}
|
||||
|
||||
copy({
|
||||
source: "kitchen-sink.html",
|
||||
dest: "build/kitchen-sink.html",
|
||||
filter: [changeComments, function(data) {
|
||||
return data.replace(/"(demo|build)\//g, "\"");
|
||||
}]
|
||||
});
|
||||
|
||||
buildAce(aceProject, {
|
||||
targetDir: "build/demo/kitchen-sink",
|
||||
ns: "ace",
|
||||
requires: "kitchen-sink/demo",
|
||||
compress: false,
|
||||
noconflict: false,
|
||||
compat: false,
|
||||
name: "kitchen-sink",
|
||||
suffix: "",
|
||||
keybindings: []
|
||||
copy({
|
||||
source: "demo/kitchen-sink/styles.css",
|
||||
dest: "build/kitchen-sink/styles.css",
|
||||
filter: [ changeComments ]
|
||||
});
|
||||
|
||||
fs.readdirSync("demo/kitchen-sink/docs/").forEach(function(x) {
|
||||
copy({
|
||||
source: "demo/kitchen-sink/docs/" + x,
|
||||
dest: "build/kitchen-sink/docs/" + x
|
||||
});
|
||||
});
|
||||
|
||||
var demo = copy.createDataObject();
|
||||
copy({
|
||||
source: "demo/kitchen-sink/demo.js",
|
||||
dest: demo,
|
||||
filter: [changeComments, function(data) {
|
||||
return data.replace(/"(demo|build)\//g, "\"");
|
||||
}, function(data) {
|
||||
return data.replace("define(", "define('kitchen-sink/demo',");
|
||||
}]
|
||||
});
|
||||
copy({
|
||||
source: "lib/ace/split.js",
|
||||
dest: demo,
|
||||
filter: [changeComments, function(data) {
|
||||
return data.replace("define(", "define('ace/split',");
|
||||
}]
|
||||
});
|
||||
copy({
|
||||
source: demo,
|
||||
dest: "build/kitchen-sink/demo.js",
|
||||
});
|
||||
|
||||
copyFileSync("demo/kitchen-sink/logo.png", "build/kitchen-sink/logo.png");
|
||||
}
|
||||
|
||||
function buildAce(aceProject, options) {
|
||||
|
|
@ -219,21 +252,13 @@ function buildAce(aceProject, options) {
|
|||
noconflict: false,
|
||||
suffix: "",
|
||||
name: "ace",
|
||||
modes: [
|
||||
"css", "html", "javascript", "php", "coldfusion", "python", "lua", "xml", "ruby", "java", "c_cpp",
|
||||
"coffee", "perl", "csharp", "haxe", "liquid", "svg", "clojure", "scss", "json", "groovy",
|
||||
"ocaml", "scala", "textile", "scad", "markdown", "latex", "powershell", "sql",
|
||||
"text", "pgsql", "sh", "xquery", "less", "golang", "c9search", "yaml"
|
||||
],
|
||||
themes: [
|
||||
"chrome", "clouds", "clouds_midnight", "cobalt", "crimson_editor", "dawn",
|
||||
"dreamweaver", "eclipse",
|
||||
"idle_fingers", "kr_theme", "merbivore", "merbivore_soft",
|
||||
"mono_industrial", "monokai", "pastel_on_dark", "solarized_dark",
|
||||
"solarized_light", "textmate", "tomorrow", "tomorrow_night",
|
||||
"tomorrow_night_blue", "tomorrow_night_bright", "tomorrow_night_eighties",
|
||||
"twilight", "vibrant_ink"
|
||||
],
|
||||
modes: fs.readdirSync("lib/ace/mode").map(function(x) {
|
||||
if (x.slice(-3) == ".js" && !/_highlight_rules|_test|_worker|xml_util|_outdent|behaviour/.test(x))
|
||||
return x.slice(0, -3);
|
||||
}).filter(function(x){return !!x}),
|
||||
themes: fs.readdirSync("lib/ace/theme").map(function(x){
|
||||
return x.slice(-3) == ".js" && x.slice(0, -3)
|
||||
}).filter(function(x){return !!x}),
|
||||
workers: ["javascript", "coffee", "css", "json", "xquery"],
|
||||
keybindings: ["vim", "emacs"]
|
||||
};
|
||||
|
|
@ -278,12 +303,10 @@ function buildAce(aceProject, options) {
|
|||
dest: ace
|
||||
});
|
||||
copy({
|
||||
source: [
|
||||
{
|
||||
source: [{
|
||||
project: project,
|
||||
require: options.requires
|
||||
}
|
||||
],
|
||||
}],
|
||||
filter: [ copy.filter.moduleDefines ],
|
||||
dest: ace
|
||||
});
|
||||
|
|
@ -300,12 +323,10 @@ function buildAce(aceProject, options) {
|
|||
options.modes.forEach(function(mode) {
|
||||
console.log("mode " + mode);
|
||||
copy({
|
||||
source: [
|
||||
{
|
||||
source: [{
|
||||
project: cloneProject(project),
|
||||
require: [ 'ace/mode/' + mode ]
|
||||
}
|
||||
],
|
||||
}],
|
||||
filter: filters,
|
||||
dest: targetDir + suffix + "/mode-" + mode + ".js"
|
||||
});
|
||||
|
|
@ -380,12 +401,10 @@ function buildAce(aceProject, options) {
|
|||
project.assumeAllFilesLoaded();
|
||||
options.keybindings.forEach(function(keybinding) {
|
||||
copy({
|
||||
source: [
|
||||
{
|
||||
source: [{
|
||||
project: cloneProject(project),
|
||||
require: [ 'ace/keyboard/' + keybinding ]
|
||||
}
|
||||
],
|
||||
}],
|
||||
filter: filters,
|
||||
dest: targetDir + suffix + "/keybinding-" + keybinding + ".js"
|
||||
});
|
||||
|
|
@ -410,6 +429,27 @@ function cloneProject(project) {
|
|||
|
||||
return clone;
|
||||
}
|
||||
function copyFileSync(srcFile, destFile) {
|
||||
var BUF_LENGTH = 64*1024,
|
||||
buf = new Buffer(BUF_LENGTH),
|
||||
bytesRead = BUF_LENGTH,
|
||||
pos = 0,
|
||||
fdr = null,
|
||||
fdw = null;
|
||||
|
||||
|
||||
fdr = fs.openSync(srcFile, 'r');
|
||||
fdw = fs.openSync(destFile, 'w');
|
||||
|
||||
while (bytesRead === BUF_LENGTH) {
|
||||
bytesRead = fs.readSync(fdr, buf, 0, BUF_LENGTH, pos);
|
||||
fs.writeSync(fdw, buf, 0, bytesRead);
|
||||
pos += bytesRead;
|
||||
}
|
||||
|
||||
fs.closeSync(fdr);
|
||||
fs.closeSync(fdw);
|
||||
}
|
||||
|
||||
function quoteString(str) {
|
||||
return '"' + str.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"';
|
||||
|
|
@ -438,7 +478,7 @@ function exportAce(ns, module, requireBase) {
|
|||
var template = function() {
|
||||
(function() {
|
||||
REQUIRE_NS.require(["MODULE"], function(a) {
|
||||
a.config.init();
|
||||
a && a.config.init();
|
||||
if (!window.NS)
|
||||
window.NS = {};
|
||||
for (var key in a) if (a.hasOwnProperty(key))
|
||||
|
|
|
|||
|
|
@ -28,13 +28,11 @@
|
|||
}
|
||||
}</pre>
|
||||
|
||||
<script src="src/ace-uncompressed-noconflict.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
var editor = ace.edit("editor");
|
||||
editor.setTheme("ace/theme/twilight");
|
||||
editor.getSession().setMode("ace/mode/javascript");
|
||||
};
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -39,12 +39,15 @@
|
|||
|
||||
|
||||
define(function(require, exports, module) {
|
||||
"use strict";
|
||||
"never use strict";
|
||||
|
||||
require("ace/lib/fixoldbrowsers");
|
||||
require("ace/config").init();
|
||||
var env = {};
|
||||
|
||||
var dom = require("ace/lib/dom");
|
||||
var net = require("ace/lib/net");
|
||||
|
||||
var event = require("ace/lib/event");
|
||||
var theme = require("ace/theme/textmate");
|
||||
var EditSession = require("ace/edit_session").EditSession;
|
||||
|
|
@ -54,25 +57,25 @@ var vim = require("ace/keyboard/vim").handler;
|
|||
var emacs = require("ace/keyboard/emacs").handler;
|
||||
var HashHandler = require("ace/keyboard/hash_handler").HashHandler;
|
||||
|
||||
var modesByName;
|
||||
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
|
||||
var Editor = require("ace/editor").Editor;
|
||||
var MultiSelect = require("ace/multi_select").MultiSelect;
|
||||
|
||||
// workers do not work for file:
|
||||
if (location.protocol == "file:")
|
||||
EditSession.prototype.$useWorker = false;
|
||||
|
||||
var Doc = function(name, desc, file) {
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.doc = new EditSession(file);
|
||||
this.doc.modeName = name;
|
||||
this.doc.setUndoManager(new UndoManager());
|
||||
};
|
||||
|
||||
var WrappedDoc = function(name, desc, file) {
|
||||
Doc.apply(this, arguments);
|
||||
|
||||
this.doc.setUseWrapMode(true);
|
||||
this.doc.setWrapLimitRange(80, 80);
|
||||
/************** modes ***********************/
|
||||
var modesByName;
|
||||
function getModeFromPath(path) {
|
||||
var mode = modesByName.text;
|
||||
for (var i = 0; i < modes.length; i++) {
|
||||
if (modes[i].supportsFile(path)) {
|
||||
mode = modes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return mode;
|
||||
};
|
||||
|
||||
var Mode = function(name, desc, extensions) {
|
||||
|
|
@ -130,158 +133,220 @@ modes.forEach(function(m) {
|
|||
modesByName[m.name] = m;
|
||||
});
|
||||
|
||||
var loreIpsum = require("ace/requirejs/text!./docs/plaintext.txt");
|
||||
for (var i = 0; i < 5; i++) {
|
||||
loreIpsum += loreIpsum;
|
||||
/*********** demo documents ***************************/
|
||||
var fileCache = {};
|
||||
|
||||
function initDoc(file, path, doc) {
|
||||
if (doc.prepare)
|
||||
file = doc.prepare(file);
|
||||
|
||||
var session = new EditSession(file);
|
||||
session.setUndoManager(new UndoManager());
|
||||
doc.session = session;
|
||||
doc.path = path;
|
||||
if (doc.wrapped) {
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(80, 80);
|
||||
}
|
||||
var mode = getModeFromPath(path)
|
||||
session.modeName = mode.name;
|
||||
session.setMode(mode.mode);
|
||||
}
|
||||
|
||||
var docs = [
|
||||
new Doc(
|
||||
"javascript", "JavaScript",
|
||||
require("ace/requirejs/text!./docs/javascript.js")
|
||||
),
|
||||
new WrappedDoc("text", "Plain Text", loreIpsum),
|
||||
new Doc(
|
||||
"coffee", "Coffeescript",
|
||||
require("ace/requirejs/text!./docs/coffeescript.coffee")
|
||||
),
|
||||
new Doc(
|
||||
"json", "JSON",
|
||||
require("ace/requirejs/text!./docs/json.json")
|
||||
),
|
||||
new Doc(
|
||||
"css", "CSS",
|
||||
require("ace/requirejs/text!./docs/css.css")
|
||||
),
|
||||
new Doc(
|
||||
"scss", "SCSS",
|
||||
require("ace/requirejs/text!./docs/scss.scss")
|
||||
),
|
||||
new Doc(
|
||||
"less", "LESS",
|
||||
require("ace/requirejs/text!./docs/less.less")
|
||||
),
|
||||
new Doc(
|
||||
"html", "HTML",
|
||||
require("ace/requirejs/text!./docs/html.html")
|
||||
),
|
||||
new Doc(
|
||||
"xml", "XML",
|
||||
require("ace/requirejs/text!./docs/xml.xml")
|
||||
),
|
||||
new Doc(
|
||||
"yaml", "YAML",
|
||||
require("ace/requirejs/text!./docs/yaml.yaml")
|
||||
),
|
||||
new Doc(
|
||||
"svg", "SVG",
|
||||
require("ace/requirejs/text!./docs/svg.svg")
|
||||
),
|
||||
new Doc(
|
||||
"php", "PHP",
|
||||
require("ace/requirejs/text!./docs/php.php")
|
||||
),
|
||||
new Doc(
|
||||
"coldfusion", "ColdFusion",
|
||||
require("ace/requirejs/text!./docs/coldfusion.cfm")
|
||||
),
|
||||
new Doc(
|
||||
"python", "Python",
|
||||
require("ace/requirejs/text!./docs/python.py")
|
||||
),
|
||||
new Doc(
|
||||
"ruby", "Ruby",
|
||||
require("ace/requirejs/text!./docs/ruby.rb")
|
||||
),
|
||||
new Doc(
|
||||
"perl", "Perl",
|
||||
require("ace/requirejs/text!./docs/perl.pl")
|
||||
),
|
||||
new Doc(
|
||||
"ocaml", "OCaml",
|
||||
require("ace/requirejs/text!./docs/ocaml.ml")
|
||||
),
|
||||
new Doc(
|
||||
"lua", "Lua",
|
||||
require("ace/requirejs/text!./docs/lua.lua")
|
||||
),
|
||||
new Doc(
|
||||
"liquid", "Liquid",
|
||||
require("ace/requirejs/text!./docs/liquid.liquid")
|
||||
),
|
||||
new Doc(
|
||||
"java", "Java",
|
||||
require("ace/requirejs/text!./docs/java.java")
|
||||
),
|
||||
new Doc(
|
||||
"clojure", "Clojure",
|
||||
require("ace/requirejs/text!./docs/clojure.clj")
|
||||
),
|
||||
new Doc(
|
||||
"groovy", "Groovy",
|
||||
require("ace/requirejs/text!./docs/groovy.groovy")
|
||||
),
|
||||
new Doc(
|
||||
"scala", "Scala",
|
||||
require("ace/requirejs/text!./docs/scala.scala")
|
||||
),
|
||||
new Doc(
|
||||
"scad", "OpenSCAD",
|
||||
require("ace/requirejs/text!./docs/OpenSCAD.scad")
|
||||
),
|
||||
new Doc(
|
||||
"csharp", "C#",
|
||||
require("ace/requirejs/text!./docs/csharp.cs")
|
||||
),
|
||||
new Doc(
|
||||
"powershell", "Powershell",
|
||||
require("ace/requirejs/text!./docs/powershell.ps1")
|
||||
),
|
||||
new Doc(
|
||||
"c_cpp", "C/C++",
|
||||
require("ace/requirejs/text!./docs/cpp.cpp")
|
||||
),
|
||||
new Doc(
|
||||
"haxe", "haXe",
|
||||
require("ace/requirejs/text!./docs/Haxe.hx")
|
||||
),
|
||||
new Doc(
|
||||
"sh", "SH",
|
||||
require("ace/requirejs/text!./docs/sh.sh")
|
||||
),
|
||||
new Doc(
|
||||
"xquery", "XQuery",
|
||||
require("ace/requirejs/text!./docs/xquery.xq")
|
||||
),
|
||||
new WrappedDoc(
|
||||
"markdown", "Markdown",
|
||||
require("ace/requirejs/text!./docs/markdown.md")
|
||||
),
|
||||
new WrappedDoc(
|
||||
"textile", "Textile",
|
||||
require("ace/requirejs/text!./docs/textile.textile")
|
||||
),
|
||||
new WrappedDoc(
|
||||
"latex", "LaTeX",
|
||||
require("ace/requirejs/text!./docs/latex.tex")
|
||||
),
|
||||
new WrappedDoc(
|
||||
"sql", "SQL",
|
||||
require("ace/requirejs/text!./docs/sql.sql")
|
||||
),
|
||||
new WrappedDoc(
|
||||
"pgsql", "pgSQL",
|
||||
require("ace/requirejs/text!./docs/pgsql.pgsql")
|
||||
),
|
||||
new Doc(
|
||||
"golang", "Go",
|
||||
require("ace/requirejs/text!./docs/golang.go")
|
||||
)
|
||||
];
|
||||
|
||||
var docsByName = {};
|
||||
docs.forEach(function(d) {
|
||||
docsByName[d.name] = d;
|
||||
function makeHuge(txt) {
|
||||
for (var i = 0; i < 5; i++)
|
||||
txt += txt;
|
||||
return txt
|
||||
}
|
||||
|
||||
var docs = {
|
||||
"docs/javascript.js": "JavaScript",
|
||||
"docs/plaintext.txt": {name: "Plain Text", prepare: makeHuge, wrapped: true},
|
||||
"docs/coffeescript.coffee": "Coffeescript",
|
||||
"docs/json.json": "JSON",
|
||||
"docs/css.css": "CSS",
|
||||
"docs/scss.scss": "SCSS",
|
||||
"docs/less.less": "LESS",
|
||||
"docs/html.html": "HTML",
|
||||
"docs/xml.xml": "XML",
|
||||
"docs/yaml.yaml": "YAML",
|
||||
"docs/svg.svg": "SVG",
|
||||
"docs/php.php": "PHP",
|
||||
"docs/coldfusion.cfm": "ColdFusion",
|
||||
"docs/python.py": "Python",
|
||||
"docs/ruby.rb": "Ruby",
|
||||
"docs/perl.pl": "Perl",
|
||||
"docs/ocaml.ml": "OCaml",
|
||||
"docs/OpenSCAD.scad": "OpenSCAD",
|
||||
"docs/lua.lua": "Lua",
|
||||
"docs/liquid.liquid": "Liquid",
|
||||
"docs/java.java": "Java",
|
||||
"docs/clojure.clj": "Clojure",
|
||||
"docs/groovy.groovy": "Groovy",
|
||||
"docs/scala.scala": "Scala",
|
||||
"docs/csharp.cs": "C#",
|
||||
"docs/powershell.ps1": "Powershell",
|
||||
"docs/cpp.cpp": "C/C++",
|
||||
"docs/Haxe.hx": "haXe",
|
||||
"docs/sh.sh": "SH",
|
||||
"docs/xquery.xq": "XQuery",
|
||||
"docs/markdown.md": {name: "Markdown", wrapped: true},
|
||||
"docs/textile.textile": {name: "Textile", wrapped: true},
|
||||
"docs/latex.tex": {name: "LaTeX", wrapped: true},
|
||||
"docs/sql.sql": {name: "SQL", wrapped: true},
|
||||
"docs/pgsql.pgsql": {name: "pgSQL", wrapped: true},
|
||||
"docs/golang.go": "Go"
|
||||
}
|
||||
|
||||
var ownSource = {
|
||||
/* filled from require*/
|
||||
};
|
||||
|
||||
var hugeDocs = {
|
||||
"build/src/ace.js": "",
|
||||
"build/src-min/ace.js": ""
|
||||
};
|
||||
|
||||
if (window.require && window.require.s) try {
|
||||
for (var path in window.require.s.contexts._.loaded) {
|
||||
if (path.indexOf("!") != -1)
|
||||
path = path.split("!").pop();
|
||||
else
|
||||
path = path + ".js";
|
||||
ownSource[path] = ""
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
function prepareDocList(docs) {
|
||||
var list = []
|
||||
for (var path in docs) {
|
||||
var doc = docs[path];
|
||||
if (typeof doc != "object")
|
||||
doc = {name: doc || path};
|
||||
|
||||
doc.path = path;
|
||||
doc.desc = doc.name.replace(/^(ace|docs|demo|build)\//, "");
|
||||
if (doc.desc.length > 18)
|
||||
doc.desc = doc.desc.slice(0, 7) + ".." + doc.desc.slice(-9)
|
||||
|
||||
fileCache[doc.name] = doc;
|
||||
list.push(doc);
|
||||
};
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
docs = prepareDocList(docs);
|
||||
ownSource = prepareDocList(ownSource);
|
||||
hugeDocs = prepareDocList(hugeDocs);
|
||||
|
||||
/*********** create editor ***************************/
|
||||
var container = document.getElementById("editor");
|
||||
|
||||
// Splitting.
|
||||
var Split = require("ace/split").Split;
|
||||
var split = new Split(container, theme, 1);
|
||||
env.editor = split.getEditor(0);
|
||||
split.on("focus", function(editor) {
|
||||
env.editor = editor;
|
||||
updateUIEditorOptions();
|
||||
});
|
||||
env.split = split;
|
||||
window.env = env;
|
||||
window.editor = window.ace = env.editor;
|
||||
env.editor.setAnimatedScroll(true);
|
||||
|
||||
var consoleHight = 20;
|
||||
function onResize() {
|
||||
var left = env.split.$container.offsetLeft;
|
||||
var width = document.documentElement.clientWidth - left;
|
||||
container.style.width = width + "px";
|
||||
container.style.height = document.documentElement.clientHeight - consoleHight + "px";
|
||||
env.split.resize();
|
||||
|
||||
consoleEl.style.width = width + "px";
|
||||
cmdLine.resize()
|
||||
}
|
||||
|
||||
var consoleEl = dom.createElement("div");
|
||||
container.parentNode.appendChild(consoleEl);
|
||||
consoleEl.style.position="fixed"
|
||||
consoleEl.style.bottom = "1px"
|
||||
consoleEl.style.right = 0
|
||||
consoleEl.style.background = "white"
|
||||
consoleEl.style.border = "1px solid #baf"
|
||||
consoleEl.style.zIndex = "100"
|
||||
var cmdLine = new singleLineEditor(consoleEl);
|
||||
cmdLine.editor = env.editor;
|
||||
env.editor.cmdLine = cmdLine;
|
||||
|
||||
env.editor.commands.addCommands([{
|
||||
name: "gotoline",
|
||||
bindKey: {win: "Ctrl-L", mac: "Command-L"},
|
||||
exec: function(editor, line) {
|
||||
if (typeof needle == "object") {
|
||||
var arg = this.name + " " + editor.getCursorPosition().row;
|
||||
editor.cmdLine.setValue(arg, 1)
|
||||
editor.cmdLine.focus()
|
||||
return
|
||||
}
|
||||
line = parseInt(line, 10);
|
||||
if (!isNaN(line))
|
||||
editor.gotoLine(line);
|
||||
},
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "find",
|
||||
bindKey: {win: "Ctrl-F", mac: "Command-F"},
|
||||
exec: function(editor, needle) {
|
||||
if (typeof needle == "object") {
|
||||
var arg = this.name + " " + editor.getCopyText()
|
||||
editor.cmdLine.setValue(arg, 1)
|
||||
editor.cmdLine.focus()
|
||||
return
|
||||
}
|
||||
editor.find(needle);
|
||||
},
|
||||
readOnly: true
|
||||
}, {
|
||||
name: "focusCommandLine",
|
||||
bindKey: "shift-esc",
|
||||
exec: function(editor, needle) { editor.cmdLine.focus(); },
|
||||
readOnly: true
|
||||
}])
|
||||
|
||||
cmdLine.commands.bindKeys({
|
||||
"Shift-Return|Ctrl-Return|Alt-Return": function(cmdLine) { cmdLine.insert("\n")},
|
||||
"Esc|Shift-Esc": function(cmdLine){ cmdLine.editor.focus(); },
|
||||
"Return": function(cmdLine){
|
||||
var command = cmdLine.getValue().split(/\s+/);
|
||||
var editor = cmdLine.editor;
|
||||
editor.commands.exec(command[0], editor, command[1]);
|
||||
editor.focus();
|
||||
},
|
||||
})
|
||||
|
||||
cmdLine.commands.removeCommands(["find", "goToLine", "findAll", "replace", "replaceAll"])
|
||||
|
||||
window.onresize = onResize;
|
||||
onResize();
|
||||
|
||||
/**
|
||||
* This demonstrates how you can define commands and bind shortcuts to them.
|
||||
*/
|
||||
|
||||
var commands = env.editor.commands;
|
||||
commands.addCommand({
|
||||
name: "save",
|
||||
bindKey: {win: "Ctrl-S", mac: "Command-S"},
|
||||
exec: function() {alert("Fake Save File");}
|
||||
});
|
||||
|
||||
commands.addCommand({
|
||||
name: "print",
|
||||
bindKey: {win: "Ctrl-P", mac: "Command-P"},
|
||||
exec: function(editor) {editor.session.setValue("please,\ndo not waste paper\n");}
|
||||
});
|
||||
|
||||
var keybindings = {
|
||||
|
|
@ -299,21 +364,9 @@ var keybindings = {
|
|||
})
|
||||
};
|
||||
|
||||
var container = document.getElementById("editor");
|
||||
|
||||
// Splitting.
|
||||
var Split = require("ace/split").Split;
|
||||
var split = new Split(container, theme, 1);
|
||||
env.editor = split.getEditor(0);
|
||||
split.on("focus", function(editor) {
|
||||
env.editor = editor;
|
||||
updateUIEditorOptions();
|
||||
});
|
||||
env.split = split;
|
||||
window.env = env;
|
||||
window.editor = window.ace = env.editor;
|
||||
env.editor.setAnimatedScroll(true);
|
||||
|
||||
/*********** options pane ***************************/
|
||||
var docEl = document.getElementById("doc");
|
||||
var modeEl = document.getElementById("mode");
|
||||
var wrapModeEl = document.getElementById("soft_wrap");
|
||||
|
|
@ -330,39 +383,54 @@ var animateScrollEl = document.getElementById("animate_scroll");
|
|||
var softTabEl = document.getElementById("soft_tab");
|
||||
var behavioursEl = document.getElementById("enable_behaviours");
|
||||
|
||||
docs.forEach(function(doc) {
|
||||
var option = document.createElement("option");
|
||||
option.setAttribute("value", doc.name);
|
||||
option.innerHTML = doc.desc;
|
||||
docEl.appendChild(option);
|
||||
});
|
||||
var group = document.createElement("optgroup");
|
||||
group.setAttribute("label", "Mode Examples");
|
||||
fillDropdown(docs, group);
|
||||
docEl.appendChild(group);
|
||||
var group = document.createElement("optgroup");
|
||||
group.setAttribute("label", "Huge documents");
|
||||
fillDropdown(hugeDocs, group);
|
||||
docEl.appendChild(group);
|
||||
var group = document.createElement("optgroup");
|
||||
group.setAttribute("label", "own source");
|
||||
fillDropdown(ownSource, group);
|
||||
docEl.appendChild(group);
|
||||
|
||||
modes.forEach(function(mode) {
|
||||
var option = document.createElement("option");
|
||||
option.setAttribute("value", mode.name);
|
||||
option.innerHTML = mode.desc;
|
||||
modeEl.appendChild(option);
|
||||
});
|
||||
|
||||
fillDropdown(modes, modeEl);
|
||||
|
||||
bindDropdown("mode", function(value) {
|
||||
env.editor.getSession().setMode(modesByName[value].mode || modesByName.text.mode);
|
||||
env.editor.getSession().modeName = value;
|
||||
});
|
||||
|
||||
bindDropdown("doc", function(value) {
|
||||
var doc = docsByName[value].doc;
|
||||
bindDropdown("doc", function(name) {
|
||||
var doc = fileCache[name];
|
||||
if (!doc)
|
||||
return;
|
||||
|
||||
if (!docsByName[value].initialized) {
|
||||
docsByName[value].initialized = true;
|
||||
doc.setMode(modesByName[docsByName[value].name].mode);
|
||||
if (doc.session)
|
||||
return setSession(doc.session)
|
||||
|
||||
//@todo do something while waiting
|
||||
// env.editor.setSession(emptySession || (emptySession = new EditSession("")))
|
||||
var path = doc.path;
|
||||
var parts = path.split("/");
|
||||
if (parts[0] == "docs")
|
||||
path = "demo/kitchen-sink/" + path;
|
||||
else if (parts[0] == "ace")
|
||||
path = "lib/" + path;
|
||||
|
||||
net.get(path, function(x) {
|
||||
initDoc(x, path, doc);
|
||||
setSession(doc.session)
|
||||
})
|
||||
|
||||
function setSession(session) {
|
||||
var session = env.split.setSession(session);
|
||||
updateUIEditorOptions();
|
||||
env.editor.focus();
|
||||
}
|
||||
|
||||
var session = env.split.setSession(doc);
|
||||
session.name = doc.name;
|
||||
|
||||
updateUIEditorOptions();
|
||||
|
||||
env.editor.focus();
|
||||
});
|
||||
|
||||
function updateUIEditorOptions() {
|
||||
|
|
@ -389,19 +457,19 @@ function updateUIEditorOptions() {
|
|||
}
|
||||
|
||||
function saveOption(el, val) {
|
||||
if (!el.onchange || el.onclick)
|
||||
if (!el.onchange && !el.onclick)
|
||||
return;
|
||||
|
||||
|
||||
if ("checked" in el) {
|
||||
if (val !== undefined)
|
||||
el.checked = val;
|
||||
|
||||
|
||||
localStorage && localStorage.setItem(el.id, el.checked ? 1 : 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (val !== undefined)
|
||||
el.value = val;
|
||||
|
||||
|
||||
localStorage && localStorage.setItem(el.id, el.value);
|
||||
}
|
||||
}
|
||||
|
|
@ -565,17 +633,17 @@ function bindDropdown(id, callback) {
|
|||
onChange();
|
||||
}
|
||||
|
||||
function onResize() {
|
||||
var left = env.split.$container.offsetLeft;
|
||||
var width = document.documentElement.clientWidth - left;
|
||||
container.style.width = width + "px";
|
||||
container.style.height = document.documentElement.clientHeight + "px";
|
||||
env.split.resize();
|
||||
function fillDropdown(list, el) {
|
||||
list.forEach(function(item) {
|
||||
var option = document.createElement("option");
|
||||
option.setAttribute("value", item.name);
|
||||
option.innerHTML = item.desc;
|
||||
el.appendChild(option);
|
||||
});
|
||||
}
|
||||
|
||||
window.onresize = onResize;
|
||||
env.editor.renderer.onResize(true);
|
||||
|
||||
/************** dragover ***************************/
|
||||
event.addListener(container, "dragover", function(e) {
|
||||
return event.preventDefault(e);
|
||||
});
|
||||
|
|
@ -591,21 +659,12 @@ event.addListener(container, "drop", function(e) {
|
|||
if (window.FileReader) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function() {
|
||||
env.editor.getSelection().selectAll();
|
||||
|
||||
var mode = modesByName.text;
|
||||
for (var i = 0; i < modes.length; i++) {
|
||||
if (modes[i].supportsFile(file.name)) {
|
||||
mode = modes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
env.editor.onTextInput(reader.result);
|
||||
var mode = getModeFromPath(file.name);
|
||||
|
||||
env.editor.session.doc.setValue(reader.result);
|
||||
modeEl.value = mode.name;
|
||||
env.editor.getSession().setMode(mode.mode);
|
||||
env.editor.getSession().modeName = mode.name;
|
||||
env.editor.session.setMode(mode.mode);
|
||||
env.editor.session.modeName = mode.name;
|
||||
};
|
||||
reader.readAsText(file);
|
||||
}
|
||||
|
|
@ -613,45 +672,72 @@ event.addListener(container, "drop", function(e) {
|
|||
return event.preventDefault(e);
|
||||
});
|
||||
|
||||
/**
|
||||
* This demonstrates how you can define commands and bind shortcuts to them.
|
||||
*/
|
||||
|
||||
// Fake-Save, works from the editor and the command line.
|
||||
var commands = env.editor.commands;
|
||||
|
||||
commands.addCommand({
|
||||
name: "save",
|
||||
bindKey: {
|
||||
win: "Ctrl-S",
|
||||
mac: "Command-S",
|
||||
sender: "editor"
|
||||
},
|
||||
exec: function() {
|
||||
alert("Fake Save File");
|
||||
}
|
||||
});
|
||||
|
||||
// Fake-Print with custom lookup-sender-match function.
|
||||
commands.addCommand({
|
||||
name: "print",
|
||||
bindKey: {
|
||||
win: "Ctrl-P",
|
||||
mac: "Command-P",
|
||||
sender: function(env, sender, hashId, keyString) {
|
||||
if (sender == "editor") {
|
||||
return true;
|
||||
} else {
|
||||
alert("Sorry, can only print from the editor");
|
||||
}
|
||||
}
|
||||
},
|
||||
exec: function() {
|
||||
alert("Fake Print File");
|
||||
}
|
||||
});
|
||||
|
||||
// add multiple cursor support to editor
|
||||
require("ace/multi_select").MultiSelect(env.editor);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* var Editor = require("ace/editor").Editor;
|
||||
var UndoManager = require("ace/undomanager").UndoManager;
|
||||
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
|
||||
var MultiSelect = require("ace/multi_select").MultiSelect; */
|
||||
|
||||
function singleLineEditor(el) {
|
||||
var renderer = new Renderer(el);
|
||||
renderer.scrollBar.element.style.display = "none";
|
||||
renderer.scrollBar.width = 0;
|
||||
renderer.content.style.height = "auto";
|
||||
|
||||
renderer.screenToTextCoordinates = function(x, y) {
|
||||
var pos = this.pixelToScreenCoordinates(x, y);
|
||||
return this.session.screenToDocumentPosition(
|
||||
Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)),
|
||||
Math.max(pos.column, 0)
|
||||
);
|
||||
};
|
||||
// todo size change event
|
||||
renderer.$computeLayerConfig = function() {
|
||||
var longestLine = this.$getLongestLine();
|
||||
var firstRow = 0;
|
||||
var lastRow = this.session.getLength();
|
||||
var height = this.session.getScreenLength() * this.lineHeight;
|
||||
|
||||
this.scrollTop = 0;
|
||||
var config = this.layerConfig;
|
||||
config.width = longestLine;
|
||||
config.padding = this.$padding;
|
||||
config.firstRow = 0;
|
||||
config.firstRowScreen = 0;
|
||||
config.lastRow = lastRow;
|
||||
config.lineHeight = this.lineHeight;
|
||||
config.characterWidth = this.characterWidth;
|
||||
config.minHeight = height;
|
||||
config.maxHeight = height;
|
||||
config.offset = 0;
|
||||
config.height = height;
|
||||
|
||||
this.$gutterLayer.element.style.marginTop = 0 + "px";
|
||||
this.content.style.marginTop = 0 + "px";
|
||||
this.content.style.width = longestLine + 2 * this.$padding + "px";
|
||||
this.content.style.height = height + "px";
|
||||
this.scroller.style.height = height + "px";
|
||||
this.container.style.height = height + "px";
|
||||
};
|
||||
renderer.isScrollableBy=function(){return false};
|
||||
|
||||
var editor = new Editor(renderer);
|
||||
new MultiSelect(editor);
|
||||
editor.session.setUndoManager(new UndoManager());
|
||||
|
||||
editor.setHighlightActiveLine(false);
|
||||
editor.setShowPrintMargin(false);
|
||||
editor.renderer.setShowGutter(false);
|
||||
editor.renderer.setHighlightGutterLine(false);
|
||||
return editor;
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
/*PACKAGE
|
||||
@import url(//fonts.googleapis.com/css?family=Droid+Sans+Mono);
|
||||
PACKAGE*/
|
||||
|
||||
html {
|
||||
height: 100%;
|
||||
|
|
@ -26,7 +28,7 @@ body {
|
|||
#editor {
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
left: 300px;
|
||||
left: 280px;
|
||||
bottom: 0px;
|
||||
right: 0px;
|
||||
background: white;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Ace Kitchen Sink</title>
|
||||
<meta name="author" content="Fabian Jakobs">
|
||||
<link rel="stylesheet" href="demo/kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
|
||||
<!--
|
||||
|
||||
Ace
|
||||
|
|
@ -104,6 +103,33 @@
|
|||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td >
|
||||
<label for="keybinding">Key Binding</label>
|
||||
</td><td>
|
||||
<select id="keybinding" size="1">
|
||||
<option value="ace">Ace</option>
|
||||
<option value="vim">Vim</option>
|
||||
<option value="emacs">Emacs</option>
|
||||
<option value="custom">Custom</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td >
|
||||
<label for="soft_wrap">Soft Wrap</label>
|
||||
</td><td>
|
||||
<select id="soft_wrap" size="1">
|
||||
<option value="off">Off</option>
|
||||
<option value="40">40 Chars</option>
|
||||
<option value="80">80 Chars</option>
|
||||
<option value="free">Free</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr><td colspan="2">
|
||||
<table id="more-controls">
|
||||
<tr>
|
||||
<td>
|
||||
<label for="select_style">Full Line Selection</label>
|
||||
|
|
@ -139,30 +165,6 @@
|
|||
<input type="checkbox" name="animate_scroll" id="animate_scroll">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td >
|
||||
<label for="keybinding">Key Binding</label>
|
||||
</td><td>
|
||||
<select id="keybinding" size="1">
|
||||
<option value="ace">Ace</option>
|
||||
<option value="vim">Vim</option>
|
||||
<option value="emacs">Emacs</option>
|
||||
<option value="custom">Custom</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td >
|
||||
<label for="soft_wrap">Soft Wrap</label>
|
||||
</td><td>
|
||||
<select id="soft_wrap" size="1">
|
||||
<option value="off">Off</option>
|
||||
<option value="40">40 Chars</option>
|
||||
<option value="80">80 Chars</option>
|
||||
<option value="free">Free</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td >
|
||||
<label for="show_gutter">Show Gutter</label>
|
||||
|
|
@ -208,12 +210,14 @@
|
|||
<input type="checkbox" id="fade_fold_widgets" checked>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div id="editor">
|
||||
</div>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div id="editor"></div>
|
||||
|
||||
<!-- DEVEL-->
|
||||
<link rel="stylesheet" href="demo/kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
|
||||
<script type="text/javascript">
|
||||
var require = {
|
||||
baseUrl: window.location.protocol + "//" + window.location.host + window.location.pathname.split("/").slice(0, -1).join("/"),
|
||||
|
|
@ -227,11 +231,15 @@
|
|||
<!--DEVEL -->
|
||||
|
||||
<!--PACKAGE
|
||||
<script src="demo/kitchen-sink/kitchen-sink.js" data-ace-base="demo/kitchen-sink" type="text/javascript" charset="utf-8"></script>
|
||||
<link rel="stylesheet" href="kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
|
||||
<script src="src/ace.js" data-ace-base="src" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/keybinding-vim.js"></script>
|
||||
<script src="src/keybinding-emacs.js"></script>
|
||||
<script src="kitchen-sink/demo.js"></script>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
require("kitchen-sink/demo");
|
||||
</script>
|
||||
<!--PACKAGE-->
|
||||
PACKAGE-->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
"jsdom": "0.2.x",
|
||||
"amd-loader": "~0.0.4",
|
||||
"plist": "",
|
||||
"dryice": "0.4.2",
|
||||
"dryice": "",
|
||||
"panino" : "~1.0.15"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue