From 46a52bed8bb500ab9bbf96d41463042e91e73908 Mon Sep 17 00:00:00 2001 From: www-data Date: Wed, 18 Feb 2015 18:38:33 +0100 Subject: [PATCH] Added the 2 missing files. This is probably consequences of codemirror update. --- .../codemirror/addon/hint/python-hint.js | 99 +++++++++++++++++++ .../admin/static/codemirror/theme/web2py.css | 36 +++++++ 2 files changed, 135 insertions(+) create mode 100644 applications/admin/static/codemirror/addon/hint/python-hint.js create mode 100644 applications/admin/static/codemirror/theme/web2py.css diff --git a/applications/admin/static/codemirror/addon/hint/python-hint.js b/applications/admin/static/codemirror/addon/hint/python-hint.js new file mode 100644 index 00000000..eebfcc76 --- /dev/null +++ b/applications/admin/static/codemirror/addon/hint/python-hint.js @@ -0,0 +1,99 @@ +(function(mod) { + if (typeof exports == "object" && typeof module == "object") // CommonJS + mod(require("../../lib/codemirror")); + else if (typeof define == "function" && define.amd) // AMD + define(["../../lib/codemirror"], mod); + else // Plain browser env + mod(CodeMirror); +})(function(CodeMirror) { + "use strict"; + + function forEach(arr, f) { + for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]); + } + + function arrayContains(arr, item) { + if (!Array.prototype.indexOf) { + var i = arr.length; + while (i--) { + if (arr[i] === item) { + return true; + } + } + return false; + } + return arr.indexOf(item) != -1; + } + + function scriptHint(editor, _keywords, getToken) { + // Find the token at the cursor + var cur = editor.getCursor(), token = getToken(editor, cur), tprop = token; + // If it's not a 'word-style' token, ignore the token. + + if (!/^[\w$_]*$/.test(token.string)) { + token = tprop = {start: cur.ch, end: cur.ch, string: "", state: token.state, + className: token.string == ":" ? "python-type" : null}; + } + + if (!context) var context = []; + context.push(tprop); + + var completionList = getCompletions(token, context); + completionList = completionList.sort(); + + return {list: completionList, + from: CodeMirror.Pos(cur.line, token.start), + to: CodeMirror.Pos(cur.line, token.end)}; + } + + function pythonHint(editor) { + return scriptHint(editor, pythonKeywordsU, function (e, cur) {return e.getTokenAt(cur);}); + } + CodeMirror.registerHelper("hint", "python", pythonHint); + + var pythonKeywords = "and del from not while as elif global or with assert else if pass yield" ++ "break except import print class exec in raise continue finally is return def for lambda try"; + var pythonKeywordsL = pythonKeywords.split(" "); + var pythonKeywordsU = pythonKeywords.toUpperCase().split(" "); + + var pythonBuiltins = "abs divmod input open staticmethod all enumerate int ord str " ++ "any eval isinstance pow sum basestring execfile issubclass print super" ++ "bin file iter property tuple bool filter len range type" ++ "bytearray float list raw_input unichr callable format locals reduce unicode" ++ "chr frozenset long reload vars classmethod getattr map repr xrange" ++ "cmp globals max reversed zip compile hasattr memoryview round __import__" ++ "complex hash min set apply delattr help next setattr buffer" ++ "dict hex object slice coerce dir id oct sorted intern "; + var pythonBuiltinsL = pythonBuiltins.split(" ").join("() ").split(" "); + var pythonBuiltinsU = pythonBuiltins.toUpperCase().split(" ").join("() ").split(" "); + + function getCompletions(token, context) { + var found = [], start = token.string; + function maybeAdd(str) { + if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str); + } + + function gatherCompletions(_obj) { + forEach(pythonBuiltinsL, maybeAdd); + forEach(pythonBuiltinsU, maybeAdd); + forEach(pythonKeywordsL, maybeAdd); + forEach(pythonKeywordsU, maybeAdd); + } + + if (context) { + // If this is a property, see if it belongs to some object we can + // find in the current environment. + var obj = context.pop(), base; + + if (obj.type == "variable") + base = obj.string; + else if(obj.type == "variable-3") + base = ":" + obj.string; + + while (base != null && context.length) + base = base[context.pop().string]; + if (base != null) gatherCompletions(base); + } + return found; + } +}); diff --git a/applications/admin/static/codemirror/theme/web2py.css b/applications/admin/static/codemirror/theme/web2py.css new file mode 100644 index 00000000..62c3003d --- /dev/null +++ b/applications/admin/static/codemirror/theme/web2py.css @@ -0,0 +1,36 @@ +.cm-s-web2py span.cm-meta {color: #FF1717;} +.cm-s-web2py span.cm-keyword { line-height: 1em; font-weight: bold; color: #7F0055; } +.cm-s-web2py span.cm-atom {color: #219;} +.cm-s-web2py span.cm-number {color: #164;} +.cm-s-web2py span.cm-def {color: #00f;} +.cm-s-web2py span.cm-variable {color: black;} +.cm-s-web2py span.cm-variable-2 {color: #0000C0;} +.cm-s-web2py span.cm-variable-3 {color: #0000C0;} +.cm-s-web2py span.cm-property {color: black;} +.cm-s-web2py span.cm-operator {color: black;} +.cm-s-web2py span.cm-comment {color: #3F7F5F;} +.cm-s-web2py span.cm-string {color: #2A00FF;} +.cm-s-web2py span.cm-string-2 {color: #f50;} +.cm-s-web2py span.cm-error {color: #f00;} +.cm-s-web2py span.cm-qualifier {color: #555;} +.cm-s-web2py span.cm-builtin {color: #30a;} +.cm-s-web2py span.cm-bracket {color: #cc7;} +.cm-s-web2py span.cm-tag {color: #170;} +.cm-s-web2py span.cm-attribute {color: #00c;} +.cm-s-web2py span.cm-link {color: #219;} + +.cm-s-web2py .CodeMirror-matchingbracket { + border:1px solid grey; + color:black !important;; +} + +/* Editor styling */ + +.cm-s-web2py { + line-height: 1.40em; + font-family: Monaco, Menlo,"Andale Mono","lucida console","Courier New",monospace !important; + background: white; +} + + +.CodeMirror-activeline-background {background: #e8f2ff !important;}