Permalink
Browse files

Add JSON parsing, validation, and special mongo objects.

  • Loading branch information...
1 parent 34bab25 commit 625ac4e92c4bbd577efb7d65155f0afa86946c90 @bobthecow bobthecow committed Aug 28, 2012
View
@@ -16,3 +16,6 @@
[submodule "vendor/apprise-bootstrap"]
path = vendor/apprise-bootstrap
url = https://github.com/bobthecow/apprise-bootstrap.git
+[submodule "vendor/esprima"]
+ path = vendor/esprima
+ url = https://github.com/ariya/esprima.git
View
@@ -104,6 +104,7 @@ script_files = FileList[
'vendor/bootstrap/js/bootstrap-tooltip.js',
'vendor/bootstrap/js/bootstrap-popover.js',
'vendor/bootstrap/js/bootstrap-modal.js',
+ 'vendor/esprima/esprima.js',
'vendor/hotkeys/jquery.hotkeys.js',
'vendor/hogan/lib/template.js',
@@ -114,6 +115,7 @@ script_files = FileList[
'src/js/genghis/bootstrap.js',
tmp_dir+'templates.js',
'src/js/genghis/util.js',
+ 'src/js/genghis/json.js',
'src/js/genghis/base/**/*',
'src/js/genghis/models/**/*',
'src/js/genghis/collections/**/*',
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -28,3 +28,34 @@
.CodeMirror-focused div.CodeMirror-selected {
background: desaturate(lighten(@linkColor, 45%), 35%);
}
+
+.CodeMirror {
+ .line-error:before {
+ content: '!';
+ display: inline-block;
+
+ color: @white;
+ font-weight: bold;
+ text-shadow: 0 -1px 0 rgba(0,0,0,.25);
+ background-color: @errorText;
+ text-align: center;
+
+ margin-right: 3px;
+
+ font-size: 12px;
+ line-height: 12px;
+ width: 12px;
+ .border-radius(6px);
+ }
+}
+
+.CodeMirror-scroll {
+ background-color: white;
+ .border-radius(4px);
+ .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075)");
+}
+
+.CodeMirror-gutter {
+ .border-top-left-radius(4px);
+ .border-bottom-left-radius(4px);
+}
View
@@ -393,17 +393,6 @@ section#document {
}
}
-.CodeMirror-scroll {
- background-color: white;
- .border-radius(4px);
- .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075)");
-}
-
-.CodeMirror-gutter {
- .border-top-left-radius(4px);
- .border-bottom-left-radius(4px);
-}
-
#keyboard-shortcuts {
.modal-body {
ul {
@@ -0,0 +1,42 @@
+Genghis.Base.DocumentView = Backbone.View.extend({
+ errorMarkers: [],
+ clearErrors: function() {
+ var editor = this.editor;
+ this.getErrorBlock().html('');
+ _.each(this.errorMarkers, function(marker) {
+ editor.clearMarker(marker);
+ });
+ this.errorMarkers = [];
+ },
+ getEditorValue: function() {
+ this.clearErrors();
+
+ var errorBlock = this.getErrorBlock();
+ var editor = this.editor;
+ var markers = this.errorMarkers;
+
+ try {
+ return Genghis.JSON.parse(editor.getValue());
+ } catch (e) {
+ _.each(e.errors || [e], function(error) {
+ var message = error.message;
+
+ if (error.lineNumber && !(/Line \d+/i.test(message))) {
+ message = 'Line ' + error.lineNumber + ': ' + error.message;
+ }
+
+ var alertView = new Genghis.Views.Alert({
+ model: new Genghis.Models.Alert({level: 'error', msg: message, block: true})
+ });
+
+ errorBlock.append(alertView.render().el);
+
+ if (error.lineNumber) {
+ markers.push(editor.setMarker(error.lineNumber - 1, null, 'line-error'));
+ }
+ });
+ }
+
+ return false;
+ }
+});
Oops, something went wrong.

0 comments on commit 625ac4e

Please sign in to comment.