Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix visualization error #260

Merged
merged 2 commits into from
Aug 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions app/javascript/packs/codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import "lodash/lodash";
// See: http://codemirror.net/doc/manual.html#modeapi
// and sample mode files: https://github.com/codemirror/CodeMirror/tree/master/mode

CodeMirror.defineMode("fluentd", function(){
CodeMirror.defineMode("fluentd", function() {
return {
startState: function(aa){
startState: function(aa) {
return { "context" : null };
},
token: function(stream, state){
if(stream.eatWhile(/[ \t]/)){
token: function(stream, state) {
if (stream.eatWhile(/[ \t]/)) {
// ignore indenting spaces
stream.skipTo(stream.peek());
return;
}
if(stream.eol()){
if (stream.eol()) {
// reached end of line
return;
}

switch(stream.peek()){
switch (stream.peek()) {
case "#":
stream.skipToEnd();
return "comment";
Expand All @@ -35,7 +35,7 @@ CodeMirror.defineMode("fluentd", function(){
state.context = "inner-definition";
return "keyword";
default:
switch(state.context){
switch (state.context) {
case "inner-bracket":
stream.eat(/[^#<>]+/);
return "keyword";
Expand All @@ -44,7 +44,15 @@ CodeMirror.defineMode("fluentd", function(){
state.context = "inner-definition-keyword-appeared";
return "variable";
case "inner-definition-keyword-appeared":
stream.eatWhile(/[^#]/);
let eatBuiltin = function(stream, state) {
stream.eatWhile(/[^#]/);
if (stream.current().match(/\\$/)) {
stream.next() && eatBuiltin(stream, state);
} else {
return;
}
};
eat(stream, state);
state.context = "inner-definition";
return "builtin";
default:
Expand All @@ -66,18 +74,18 @@ function codemirrorify(el) {
}

$(function(){
$(".js-fluentd-config-editor").each(function(_, el){
$(".js-fluentd-config-editor").each(function(_, el) {
codemirrorify(el);
});
});

Vue.directive("config-editor", {
bind: function(el, binding, vnode, oldVnode){
bind: function(el, binding, vnode, oldVnode) {
// NOTE: needed delay for waiting CodeMirror setup
_.delay(function(textarea){
_.delay(function(textarea) {
let cm = codemirrorify(textarea);
// textarea.codemirror = cm; // for test, but doesn't work for now (working on Chrome, but Poltergeist not)
cm.on("change", function(code_mirror){
cm.on("change", function(code_mirror) {
// bridge Vue - CodeMirror world
el.dataset.content = code_mirror.getValue();
});
Expand Down