forked from NYANDEV/forgejo
* Cleaning up public/ and documenting js/css libs. This commit mostly addresses #1484 by moving vendor'ed plugins into a vendor/ directory and documenting their upstream source and license in vendor/librejs.html. This also proves gitea is using only open source js/css libraries which helps toward reaching #1524. * Removing unused css file. The version of this file in use is located at: vendor/plugins/highlight/github.css * Cleaned up librejs.html and added javascript header A SafeJS function was added to templates/helper.go to allow keeping comments inside of javascript. A javascript comment was added in the header of templates/base/head.tmpl to mark all non-inline source as free. The librejs.html file was updated to meet the current librejs spec. I have now verified that the librejs plugin detects most of the scripts included in gitea and suspect the non-free detections are the result of a bug in the plugin. I believe this commit is enough to meet the C0.0 requirement of #1534. * Updating SafeJS function per lint suggestion * Added VERSIONS file, per request
This commit is contained in:
parent
64b7068846
commit
a915a09e4f
1339 changed files with 813 additions and 126 deletions
230
public/vendor/plugins/codemirror/mode/groovy/groovy.js
vendored
Normal file
230
public/vendor/plugins/codemirror/mode/groovy/groovy.js
vendored
Normal file
|
@ -0,0 +1,230 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(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";
|
||||
|
||||
CodeMirror.defineMode("groovy", function(config) {
|
||||
function words(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
var keywords = words(
|
||||
"abstract as assert boolean break byte case catch char class const continue def default " +
|
||||
"do double else enum extends final finally float for goto if implements import in " +
|
||||
"instanceof int interface long native new package private protected public return " +
|
||||
"short static strictfp super switch synchronized threadsafe throw throws transient " +
|
||||
"try void volatile while");
|
||||
var blockKeywords = words("catch class do else finally for if switch try while enum interface def");
|
||||
var standaloneKeywords = words("return break continue");
|
||||
var atoms = words("null true false this");
|
||||
|
||||
var curPunc;
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
if (ch == '"' || ch == "'") {
|
||||
return startString(ch, stream, state);
|
||||
}
|
||||
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
||||
curPunc = ch;
|
||||
return null;
|
||||
}
|
||||
if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
if (stream.eat(/eE/)) { stream.eat(/\+\-/); stream.eatWhile(/\d/); }
|
||||
return "number";
|
||||
}
|
||||
if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
state.tokenize.push(tokenComment);
|
||||
return tokenComment(stream, state);
|
||||
}
|
||||
if (stream.eat("/")) {
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
if (expectExpression(state.lastToken, false)) {
|
||||
return startString(ch, stream, state);
|
||||
}
|
||||
}
|
||||
if (ch == "-" && stream.eat(">")) {
|
||||
curPunc = "->";
|
||||
return null;
|
||||
}
|
||||
if (/[+\-*&%=<>!?|\/~]/.test(ch)) {
|
||||
stream.eatWhile(/[+\-*&%=<>|~]/);
|
||||
return "operator";
|
||||
}
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
if (ch == "@") { stream.eatWhile(/[\w\$_\.]/); return "meta"; }
|
||||
if (state.lastToken == ".") return "property";
|
||||
if (stream.eat(":")) { curPunc = "proplabel"; return "property"; }
|
||||
var cur = stream.current();
|
||||
if (atoms.propertyIsEnumerable(cur)) { return "atom"; }
|
||||
if (keywords.propertyIsEnumerable(cur)) {
|
||||
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
||||
else if (standaloneKeywords.propertyIsEnumerable(cur)) curPunc = "standalone";
|
||||
return "keyword";
|
||||
}
|
||||
return "variable";
|
||||
}
|
||||
tokenBase.isBase = true;
|
||||
|
||||
function startString(quote, stream, state) {
|
||||
var tripleQuoted = false;
|
||||
if (quote != "/" && stream.eat(quote)) {
|
||||
if (stream.eat(quote)) tripleQuoted = true;
|
||||
else return "string";
|
||||
}
|
||||
function t(stream, state) {
|
||||
var escaped = false, next, end = !tripleQuoted;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {
|
||||
if (!tripleQuoted) { break; }
|
||||
if (stream.match(quote + quote)) { end = true; break; }
|
||||
}
|
||||
if (quote == '"' && next == "$" && !escaped && stream.eat("{")) {
|
||||
state.tokenize.push(tokenBaseUntilBrace());
|
||||
return "string";
|
||||
}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end) state.tokenize.pop();
|
||||
return "string";
|
||||
}
|
||||
state.tokenize.push(t);
|
||||
return t(stream, state);
|
||||
}
|
||||
|
||||
function tokenBaseUntilBrace() {
|
||||
var depth = 1;
|
||||
function t(stream, state) {
|
||||
if (stream.peek() == "}") {
|
||||
depth--;
|
||||
if (depth == 0) {
|
||||
state.tokenize.pop();
|
||||
return state.tokenize[state.tokenize.length-1](stream, state);
|
||||
}
|
||||
} else if (stream.peek() == "{") {
|
||||
depth++;
|
||||
}
|
||||
return tokenBase(stream, state);
|
||||
}
|
||||
t.isBase = true;
|
||||
return t;
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var maybeEnd = false, ch;
|
||||
while (ch = stream.next()) {
|
||||
if (ch == "/" && maybeEnd) {
|
||||
state.tokenize.pop();
|
||||
break;
|
||||
}
|
||||
maybeEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function expectExpression(last, newline) {
|
||||
return !last || last == "operator" || last == "->" || /[\.\[\{\(,;:]/.test(last) ||
|
||||
last == "newstatement" || last == "keyword" || last == "proplabel" ||
|
||||
(last == "standalone" && !newline);
|
||||
}
|
||||
|
||||
function Context(indented, column, type, align, prev) {
|
||||
this.indented = indented;
|
||||
this.column = column;
|
||||
this.type = type;
|
||||
this.align = align;
|
||||
this.prev = prev;
|
||||
}
|
||||
function pushContext(state, col, type) {
|
||||
return state.context = new Context(state.indented, col, type, null, state.context);
|
||||
}
|
||||
function popContext(state) {
|
||||
var t = state.context.type;
|
||||
if (t == ")" || t == "]" || t == "}")
|
||||
state.indented = state.context.indented;
|
||||
return state.context = state.context.prev;
|
||||
}
|
||||
|
||||
// Interface
|
||||
|
||||
return {
|
||||
startState: function(basecolumn) {
|
||||
return {
|
||||
tokenize: [tokenBase],
|
||||
context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false),
|
||||
indented: 0,
|
||||
startOfLine: true,
|
||||
lastToken: null
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var ctx = state.context;
|
||||
if (stream.sol()) {
|
||||
if (ctx.align == null) ctx.align = false;
|
||||
state.indented = stream.indentation();
|
||||
state.startOfLine = true;
|
||||
// Automatic semicolon insertion
|
||||
if (ctx.type == "statement" && !expectExpression(state.lastToken, true)) {
|
||||
popContext(state); ctx = state.context;
|
||||
}
|
||||
}
|
||||
if (stream.eatSpace()) return null;
|
||||
curPunc = null;
|
||||
var style = state.tokenize[state.tokenize.length-1](stream, state);
|
||||
if (style == "comment") return style;
|
||||
if (ctx.align == null) ctx.align = true;
|
||||
|
||||
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
|
||||
// Handle indentation for {x -> \n ... }
|
||||
else if (curPunc == "->" && ctx.type == "statement" && ctx.prev.type == "}") {
|
||||
popContext(state);
|
||||
state.context.align = false;
|
||||
}
|
||||
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
||||
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
||||
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
||||
else if (curPunc == "}") {
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
if (ctx.type == "}") ctx = popContext(state);
|
||||
while (ctx.type == "statement") ctx = popContext(state);
|
||||
}
|
||||
else if (curPunc == ctx.type) popContext(state);
|
||||
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
|
||||
pushContext(state, stream.column(), "statement");
|
||||
state.startOfLine = false;
|
||||
state.lastToken = curPunc || style;
|
||||
return style;
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
if (!state.tokenize[state.tokenize.length-1].isBase) return 0;
|
||||
var firstChar = textAfter && textAfter.charAt(0), ctx = state.context;
|
||||
if (ctx.type == "statement" && !expectExpression(state.lastToken, true)) ctx = ctx.prev;
|
||||
var closing = firstChar == ctx.type;
|
||||
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : config.indentUnit);
|
||||
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
||||
else return ctx.indented + (closing ? 0 : config.indentUnit);
|
||||
},
|
||||
|
||||
electricChars: "{}",
|
||||
closeBrackets: {triples: "'\""},
|
||||
fold: "brace"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-groovy", "groovy");
|
||||
|
||||
});
|
84
public/vendor/plugins/codemirror/mode/groovy/index.html
vendored
Normal file
84
public/vendor/plugins/codemirror/mode/groovy/index.html
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Groovy mode</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="../../addon/edit/matchbrackets.js"></script>
|
||||
<script src="groovy.js"></script>
|
||||
<style>.CodeMirror {border-top: 1px solid #500; border-bottom: 1px solid #500;}</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../../index.html">Home</a>
|
||||
<li><a href="../../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="../index.html">Language modes</a>
|
||||
<li><a class=active href="#">Groovy</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Groovy mode</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
//Pattern for groovy script
|
||||
def p = ~/.*\.groovy/
|
||||
new File( 'd:\\scripts' ).eachFileMatch(p) {f ->
|
||||
// imports list
|
||||
def imports = []
|
||||
f.eachLine {
|
||||
// condition to detect an import instruction
|
||||
ln -> if ( ln =~ '^import .*' ) {
|
||||
imports << "${ln - 'import '}"
|
||||
}
|
||||
}
|
||||
// print thmen
|
||||
if ( ! imports.empty ) {
|
||||
println f
|
||||
imports.each{ println " $it" }
|
||||
}
|
||||
}
|
||||
|
||||
/* Coin changer demo code from http://groovy.codehaus.org */
|
||||
|
||||
enum UsCoin {
|
||||
quarter(25), dime(10), nickel(5), penny(1)
|
||||
UsCoin(v) { value = v }
|
||||
final value
|
||||
}
|
||||
|
||||
enum OzzieCoin {
|
||||
fifty(50), twenty(20), ten(10), five(5)
|
||||
OzzieCoin(v) { value = v }
|
||||
final value
|
||||
}
|
||||
|
||||
def plural(word, count) {
|
||||
if (count == 1) return word
|
||||
word[-1] == 'y' ? word[0..-2] + "ies" : word + "s"
|
||||
}
|
||||
|
||||
def change(currency, amount) {
|
||||
currency.values().inject([]){ list, coin ->
|
||||
int count = amount / coin.value
|
||||
amount = amount % coin.value
|
||||
list += "$count ${plural(coin.toString(), count)}"
|
||||
}
|
||||
}
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
mode: "text/x-groovy"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p><strong>MIME types defined:</strong> <code>text/x-groovy</code></p>
|
||||
</article>
|
Loading…
Add table
Add a link
Reference in a new issue