Skip to content

Commit

Permalink
GeoCSS code complete
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Apr 25, 2017
1 parent d317a77 commit 53d77e9
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,9 @@ public List<Exception> validate(Object input, Version version, EntityResolver en
return Arrays.asList(e);
}
}

@Override
public String getCodeMirrorEditMode() {
return "text/geocss";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ public class CodeMirrorEditor extends FormComponentPanel<String> {
public static final PackageResourceReference REFERENCE = new PackageResourceReference(
CodeMirrorEditor.class, "js/codemirror/js/codemirror.js");

public static final PackageResourceReference CSS_REFERENCE = new PackageResourceReference(
CodeMirrorEditor.class, "js/codemirror/css/codemirror.css");
public static final PackageResourceReference[] CSS_REFERENCE = new PackageResourceReference[] {
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/css/codemirror.css"),
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/css/show-hint.css")};


public static final PackageResourceReference[] MODES = new PackageResourceReference[] {
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/js/xml.js"),
Expand All @@ -55,7 +57,9 @@ public class CodeMirrorEditor extends FormComponentPanel<String> {
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/js/javascript.js"),
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/js/python.js"),
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/js/ruby.js"),
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/js/css.js")
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/js/css.js"),
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/js/show-hint.js"),
new PackageResourceReference(CodeMirrorEditor.class, "js/codemirror/js/geocss-hint.js")
};


Expand Down Expand Up @@ -249,7 +253,9 @@ class CodeMirrorBehavior extends Behavior {
public void renderHead(Component component, IHeaderResponse response) {
super.renderHead(component, response);
// Add CSS
response.render(CssHeaderItem.forReference(CSS_REFERENCE));
for(PackageResourceReference css : CSS_REFERENCE) {
response.render(CssHeaderItem.forReference(css));
}
// Add JS
response.render(JavaScriptHeaderItem.forReference(REFERENCE));
// Add Modes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var editor = CodeMirror.fromTextArea(textarea, {
mode: '$mode',
theme: 'default',
lineWrapping: true,
lineNumbers: true
lineNumbers: true,
extraKeys: {"Ctrl-Space": "autocomplete"}
});
editor.getWrapperElement().style.fontSize = "12px";
editor.refresh();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.CodeMirror-hints {
position: absolute;
z-index: 10;
overflow: hidden;
list-style: none;

margin: 0;
padding: 2px;

-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
border-radius: 3px;
border: 1px solid silver;

background: white;
font-size: 90%;
font-family: monospace;

max-height: 20em;
overflow-y: auto;
}

.CodeMirror-hint {
margin: 0;
padding: 0 4px;
border-radius: 2px;
max-width: 19em;
overflow: hidden;
white-space: pre;
color: black;
cursor: pointer;
}

li.CodeMirror-hint-active {
background: #08f;
color: white;
}
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,12 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
});

CodeMirror.defineMIME("text/x-less", {
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
mediaTypes: [],
mediaFeatures: [],
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
valueKeywords: [],
fontProperties: fontProperties,
allowNested: true,
tokenHooks: {
Expand Down Expand Up @@ -713,5 +713,71 @@ CodeMirror.defineMode("css", function(config, parserConfig) {
name: "css",
helperType: "less"
});

// Definition of GeoCSS

var geoPropertyKeywords_ = [ "fill","fill-geometry","fill-mime","fill-opacity","fill-rotation",
"fill-size","font-family","font-fill","font-size","font-style","font-weight","geometry","-gt-fill-label-obstacle",
"-gt-graphic-margin","-gt-label-all-group","-gt-label-allow-overruns","-gt-label-auto-wrap","-gt-label-conflict-resolution",
"-gt-label-fit-goodness","-gt-label-follow-line","-gt-label-force-ltr","-gt-label-group","-gt-label-max-angle-delta",
"-gt-label-max-displacement","-gt-label-min-group-distance","-gt-label-padding","-gt-label-priority",
"-gt-label-remove-overlaps","-gt-label-repeat","-gt-label-underline-text","-gt-mark-label-obstacle","-gt-random",
"-gt-random-rotation","-gt-random-seed","-gt-random-symbol-count","-gt-random-tile-size","-gt-shield-margin",
"-gt-shield-resize", "-gt-stroke-label-obstacle","halo-color",
"halo-opacity","halo-radius","label","label-anchor","label-geometry","label-offset","label-rotation","label-z-index",
"mark","mark-geometry","mark-mime","mark-rotation","mark-size" ,"raster-channels","raster-color-map",
"raster-color-map-type","raster-contrast-enhancement","raster-gamma","raster-geometry","raster-opacity",
"raster-z-index","rotation","shield","shield-mime","size","sort-by","sort-by-group","stroke","stroke-dasharray",
"stroke-dashoffset","stroke-geometry","stroke-linecap","stroke-linejoin","stroke-mime","stroke-offset",
"stroke-opacity","stroke-repeat","stroke-rotation","stroke-size","stroke-width","transform", "z-index" ],
geoPropertyKeywords = keySet(geoPropertyKeywords_);

var geoNonStandardPropertyKeywords_ = [ "-gt-fill-label-obstacle",
"-gt-graphic-margin","-gt-label-all-group","-gt-label-allow-overruns","-gt-label-auto-wrap","-gt-label-conflict-resolution",
"-gt-label-fit-goodness","-gt-label-follow-line","-gt-label-force-ltr","-gt-label-group","-gt-label-max-angle-delta",
"-gt-label-max-displacement","-gt-label-min-group-distance","-gt-label-padding","-gt-label-priority",
"-gt-label-remove-overlaps","-gt-label-repeat","-gt-label-underline-text","-gt-mark-label-obstacle","-gt-random",
"-gt-random-rotation","-gt-random-seed","-gt-random-symbol-count","-gt-random-tile-size","-gt-shield-margin",
"-gt-shield-resize", "-gt-stroke-label-obstacle" ],
geoNonStandardPropertyKeywords = keySet(geoNonStandardPropertyKeywords_);

var geoValueKeywords_ = [ "auto","bevel","color-map-entry(","false","free","grid","histogram","image/jpeg","image/png"
,"image/svg+xml","intervals","italic","miter","none","normal","normalize","oblique","proportional","ramp","repeat",
"round","stipple","stretch","symbol(","true","url(","values", "hsl(", "saturate(", "desaturate(", "darken(", "lighten(", "spin(",
"mix(", "tint(", "shade(", "grayscale(", "constrast(" ],
geoValueKeywords = keySet(geoValueKeywords_);

CodeMirror.defineMIME("text/geocss", {
mediaTypes: keySet([]),
mediaFeatures: keySet([]),
propertyKeywords: geoPropertyKeywords,
nonStandardPropertyKeywords: geoNonStandardPropertyKeywords,
colorKeywords: colorKeywords,
valueKeywords: geoValueKeywords,
fontProperties: keySet([]),
allowNested: true,
tokenHooks: {
"/": function(stream, state) {
if (stream.eat("/")) {
stream.skipToEnd();
return ["comment", "comment"];
} else if (stream.eat("*")) {
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
} else {
return ["operator", "operator"];
}
},
"@": function(stream) {
if (stream.match(/^(mode)\b/, false)) return false;
stream.eatWhile(/[\w\\\-]/);
if (stream.match(/^\s*:/, false))
return ["variable-2", "variable-definition"];
return ["variable-2", "variable"];
}
},
name: "css",
helperType: "geocss"
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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"), require("../../mode/css/css"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../../mode/css/css"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

var pseudoClasses = {mark: 1, shield: 1, stroke: 1, fill: 1, symbol: 1,
"nth-mark(n)": 1, "nth-shield(n)": 1, "nth-fill(n)": 1,
"nth-symbol(n)": 1};

CodeMirror.registerHelper("hint", "geocss", function(cm) {
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
if (inner.mode.name != "css") return;

var start = token.start, end = cur.ch, word = token.string.slice(0, end - start);
if (/[^\w$_-]/.test(word)) {
word = ""; start = end = cur.ch;
}

var spec = CodeMirror.resolveMode("text/geocss");

var result = [];
function add(keywords) {
for (var name in keywords)
if (!word || name.lastIndexOf(word, 0) == 0)
result.push(name);
}

var st = inner.state.state;
if (st == "pseudo" || token.type == "variable-3") {
add(pseudoClasses);
} else if (st == "block" || st == "maybeprop") {
add(spec.propertyKeywords);
} else if (st == "prop" || st == "parens" || st == "at" || st == "params") {
add(spec.valueKeywords);
add(spec.colorKeywords);
}

if (result.length) return {
list: result,
from: CodeMirror.Pos(cur.line, start),
to: CodeMirror.Pos(cur.line, end)
};
});
});

0 comments on commit 53d77e9

Please sign in to comment.