mirror of
https://github.com/go-gitea/gitea
synced 2025-07-19 16:58:37 +00:00
* 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:
committed by
Kim "BKC" Carlbäcker
parent
64b7068846
commit
a915a09e4f
53
public/vendor/plugins/codemirror/mode/pig/index.html
vendored
Normal file
53
public/vendor/plugins/codemirror/mode/pig/index.html
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
<!doctype html>
|
||||
<title>CodeMirror: Pig Latin 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="pig.js"></script>
|
||||
<style>.CodeMirror {border: 2px inset #dee;}</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="#">Pig Latin</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Pig Latin mode</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
-- Apache Pig (Pig Latin Language) Demo
|
||||
/*
|
||||
This is a multiline comment.
|
||||
*/
|
||||
a = LOAD "\path\to\input" USING PigStorage('\t') AS (x:long, y:chararray, z:bytearray);
|
||||
b = GROUP a BY (x,y,3+4);
|
||||
c = FOREACH b GENERATE flatten(group) as (x,y), SUM(group.$2) as z;
|
||||
STORE c INTO "\path\to\output";
|
||||
|
||||
--
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
indentUnit: 4,
|
||||
mode: "text/x-pig"
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>
|
||||
Simple mode that handles Pig Latin language.
|
||||
</p>
|
||||
|
||||
<p><strong>MIME type defined:</strong> <code>text/x-pig</code>
|
||||
(PIG code)
|
||||
</article>
|
178
public/vendor/plugins/codemirror/mode/pig/pig.js
vendored
Normal file
178
public/vendor/plugins/codemirror/mode/pig/pig.js
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
/*
|
||||
* Pig Latin Mode for CodeMirror 2
|
||||
* @author Prasanth Jayachandran
|
||||
* @link https://github.com/prasanthj/pig-codemirror-2
|
||||
* This implementation is adapted from PL/SQL mode in CodeMirror 2.
|
||||
*/
|
||||
(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("pig", function(_config, parserConfig) {
|
||||
var keywords = parserConfig.keywords,
|
||||
builtins = parserConfig.builtins,
|
||||
types = parserConfig.types,
|
||||
multiLineStrings = parserConfig.multiLineStrings;
|
||||
|
||||
var isOperatorChar = /[*+\-%<>=&?:\/!|]/;
|
||||
|
||||
function chain(stream, state, f) {
|
||||
state.tokenize = f;
|
||||
return f(stream, state);
|
||||
}
|
||||
|
||||
function tokenComment(stream, state) {
|
||||
var isEnd = false;
|
||||
var ch;
|
||||
while(ch = stream.next()) {
|
||||
if(ch == "/" && isEnd) {
|
||||
state.tokenize = tokenBase;
|
||||
break;
|
||||
}
|
||||
isEnd = (ch == "*");
|
||||
}
|
||||
return "comment";
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var escaped = false, next, end = false;
|
||||
while((next = stream.next()) != null) {
|
||||
if (next == quote && !escaped) {
|
||||
end = true; break;
|
||||
}
|
||||
escaped = !escaped && next == "\\";
|
||||
}
|
||||
if (end || !(escaped || multiLineStrings))
|
||||
state.tokenize = tokenBase;
|
||||
return "error";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
var ch = stream.next();
|
||||
|
||||
// is a start of string?
|
||||
if (ch == '"' || ch == "'")
|
||||
return chain(stream, state, tokenString(ch));
|
||||
// is it one of the special chars
|
||||
else if(/[\[\]{}\(\),;\.]/.test(ch))
|
||||
return null;
|
||||
// is it a number?
|
||||
else if(/\d/.test(ch)) {
|
||||
stream.eatWhile(/[\w\.]/);
|
||||
return "number";
|
||||
}
|
||||
// multi line comment or operator
|
||||
else if (ch == "/") {
|
||||
if (stream.eat("*")) {
|
||||
return chain(stream, state, tokenComment);
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return "operator";
|
||||
}
|
||||
}
|
||||
// single line comment or operator
|
||||
else if (ch=="-") {
|
||||
if(stream.eat("-")){
|
||||
stream.skipToEnd();
|
||||
return "comment";
|
||||
}
|
||||
else {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return "operator";
|
||||
}
|
||||
}
|
||||
// is it an operator
|
||||
else if (isOperatorChar.test(ch)) {
|
||||
stream.eatWhile(isOperatorChar);
|
||||
return "operator";
|
||||
}
|
||||
else {
|
||||
// get the while word
|
||||
stream.eatWhile(/[\w\$_]/);
|
||||
// is it one of the listed keywords?
|
||||
if (keywords && keywords.propertyIsEnumerable(stream.current().toUpperCase())) {
|
||||
//keywords can be used as variables like flatten(group), group.$0 etc..
|
||||
if (!stream.eat(")") && !stream.eat("."))
|
||||
return "keyword";
|
||||
}
|
||||
// is it one of the builtin functions?
|
||||
if (builtins && builtins.propertyIsEnumerable(stream.current().toUpperCase()))
|
||||
return "variable-2";
|
||||
// is it one of the listed types?
|
||||
if (types && types.propertyIsEnumerable(stream.current().toUpperCase()))
|
||||
return "variable-3";
|
||||
// default is a 'variable'
|
||||
return "variable";
|
||||
}
|
||||
}
|
||||
|
||||
// Interface
|
||||
return {
|
||||
startState: function() {
|
||||
return {
|
||||
tokenize: tokenBase,
|
||||
startOfLine: true
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
if(stream.eatSpace()) return null;
|
||||
var style = state.tokenize(stream, state);
|
||||
return style;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
(function() {
|
||||
function keywords(str) {
|
||||
var obj = {}, words = str.split(" ");
|
||||
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
||||
return obj;
|
||||
}
|
||||
|
||||
// builtin funcs taken from trunk revision 1303237
|
||||
var pBuiltins = "ABS ACOS ARITY ASIN ATAN AVG BAGSIZE BINSTORAGE BLOOM BUILDBLOOM CBRT CEIL "
|
||||
+ "CONCAT COR COS COSH COUNT COUNT_STAR COV CONSTANTSIZE CUBEDIMENSIONS DIFF DISTINCT DOUBLEABS "
|
||||
+ "DOUBLEAVG DOUBLEBASE DOUBLEMAX DOUBLEMIN DOUBLEROUND DOUBLESUM EXP FLOOR FLOATABS FLOATAVG "
|
||||
+ "FLOATMAX FLOATMIN FLOATROUND FLOATSUM GENERICINVOKER INDEXOF INTABS INTAVG INTMAX INTMIN "
|
||||
+ "INTSUM INVOKEFORDOUBLE INVOKEFORFLOAT INVOKEFORINT INVOKEFORLONG INVOKEFORSTRING INVOKER "
|
||||
+ "ISEMPTY JSONLOADER JSONMETADATA JSONSTORAGE LAST_INDEX_OF LCFIRST LOG LOG10 LOWER LONGABS "
|
||||
+ "LONGAVG LONGMAX LONGMIN LONGSUM MAX MIN MAPSIZE MONITOREDUDF NONDETERMINISTIC OUTPUTSCHEMA "
|
||||
+ "PIGSTORAGE PIGSTREAMING RANDOM REGEX_EXTRACT REGEX_EXTRACT_ALL REPLACE ROUND SIN SINH SIZE "
|
||||
+ "SQRT STRSPLIT SUBSTRING SUM STRINGCONCAT STRINGMAX STRINGMIN STRINGSIZE TAN TANH TOBAG "
|
||||
+ "TOKENIZE TOMAP TOP TOTUPLE TRIM TEXTLOADER TUPLESIZE UCFIRST UPPER UTF8STORAGECONVERTER ";
|
||||
|
||||
// taken from QueryLexer.g
|
||||
var pKeywords = "VOID IMPORT RETURNS DEFINE LOAD FILTER FOREACH ORDER CUBE DISTINCT COGROUP "
|
||||
+ "JOIN CROSS UNION SPLIT INTO IF OTHERWISE ALL AS BY USING INNER OUTER ONSCHEMA PARALLEL "
|
||||
+ "PARTITION GROUP AND OR NOT GENERATE FLATTEN ASC DESC IS STREAM THROUGH STORE MAPREDUCE "
|
||||
+ "SHIP CACHE INPUT OUTPUT STDERROR STDIN STDOUT LIMIT SAMPLE LEFT RIGHT FULL EQ GT LT GTE LTE "
|
||||
+ "NEQ MATCHES TRUE FALSE DUMP";
|
||||
|
||||
// data types
|
||||
var pTypes = "BOOLEAN INT LONG FLOAT DOUBLE CHARARRAY BYTEARRAY BAG TUPLE MAP ";
|
||||
|
||||
CodeMirror.defineMIME("text/x-pig", {
|
||||
name: "pig",
|
||||
builtins: keywords(pBuiltins),
|
||||
keywords: keywords(pKeywords),
|
||||
types: keywords(pTypes)
|
||||
});
|
||||
|
||||
CodeMirror.registerHelper("hintWords", "pig", (pBuiltins + pTypes + pKeywords).split(" "));
|
||||
}());
|
||||
|
||||
});
|
Reference in New Issue
Block a user