Permalink
Browse files

integrate CodeMirror

  • Loading branch information...
1 parent 43d2246 commit cd15b5ea63dd83c6c7aaef3f90918b157f6fe6c4 @mzero committed Oct 29, 2010
View
@@ -0,0 +1,23 @@
+ Copyright (c) 2007-2010 Marijn Haverbeke
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any
+ damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any
+ purpose, including commercial applications, and to alter it and
+ redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must
+ not claim that you wrote the original software. If you use this
+ software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+
+ Marijn Haverbeke
+ marijnh@gmail.com
View
@@ -63,12 +63,12 @@ Additional Credits
------------------
* [jQuery][c1] *-- MIT License*
-* [Elastic][c2] a jQuery plugin by Jan Jarfalk *-- MIT License*
+* [CodeMirror][c2] by Marijn Haverbeke *-- zlib-style license*
* ["A Lady Beetle Perches on Barley"][c3] by T. Voekler
*-- Creative Commons Attribution-ShareAlike 3.0 Unported*
* [Silk Icons][c4] by Mark James *-- Creative Commons Attribution 2.5*
[c1]: http://jquery.com/
-[c2]: http://www.unwrongest.com/projects/elastic/
+[c2]: http://codemirror.net/
[c3]: http://commons.wikimedia.org/wiki/File:A_lady_beetle_perches_on_barley.JPG
[c4]: http://www.famfamfam.com/lab/icons/silk/
View
@@ -52,6 +52,11 @@ How to use this list:
[] init --force = copy even if the dest is not empty.
** Do not add these flags to start, which should always be safe.
+[] reevaluate our file case handling decisions
+ -- we have Haskell code named with initial uppers to match module names
+ -- but then things like .css files w/o... and URLs to said files have lower
+ -- case? i.e.: /source?file=Source.hs !!!
+
[+m] make sure file path is rational before serving:
- no ".." elements, no ".*" elements
[+m] need a better term than "run" for the act of invoking code to return a page
@@ -88,24 +93,22 @@ Source Editor
-- previews if ext is .html or (.hs and not in ./Library)
[+m] preview disabled for things under lib/
[+m] line numbers
+ [+m] integrate CodeMirror as the source editor
+ [] "better" size the code editing box
+ [] change background color on edit/readonly
+ [] selection to research field is broken
+ [] eliminate annoying "shift" when CodeMirror loads the text
+ [] syntax parser for Haskell
[] On source editing cancel, if the text was changed, show a button
(or link): "Undo Cancel" save and restore the text as needed.
[] Not clear if Edit in this state should restore or not.
-
- [] elastic.js seems to not handle missing trailing newline well
- - see what happens when you add text on last line of source
[] research fill-from-selection should work even when source is read-only
- but form elements don't have a selection when disabled.. hack?
[] combine research text entry fields into one
[] optional setting to get side-by-side for the preview and edit panels
- [] line numbers don't track when user resizes text area, or changes
- number of lines of text
- [] text field should be non-wrapping
[m] icons for the action links
[?m] switch icon set to Fugue icons
[] 80 column line would sure be nice
- [] syntax coloring WTF
- [] tab should insert spaces to multiple of four, or indent/outdent
AJAX Compile
[] on edit save, submit in background to a new endpoint
@@ -129,8 +132,9 @@ Content
[+m] move community links to a sub-menu of Haskell
[+m] write index.hs that gives the user a hello and what to do next
[+m] factor common code between Index.hs and Source.hs into lib/DevUtils.hs
- [m] move source.hs into a dev directory
- [m] scaffold.css should probably be named something better like barley.css
+ [+m] scaffold.css should probably be named something better like barley.css
+ [] move source.hs & project.hs into a dev directory
+ -- after compilation can handle hierarchical modules
[] Better Index page that actually points at the chapters & steps
[] Documentation page with links to sources
[?] embedded iframe of user's local doc set
@@ -146,11 +150,14 @@ Compilation
[] handle reloading with something better than the nu hack...
[] model code used by Happstack plugins
[+m] put .hi and .o files in some .build tree
- [] check that hierarchicaly named modules do the right thing
[+m] ensure loading modules that import user modules works
[+m] make dependent modules as needed
[+m] look for dependent modules rooted in both "." and "lib"
for both compilation and loading
+ [] handle hierarchically named modules
+ -- currently referenced modules are build correctly
+ -- but the top level module is placed/looked for in wrong .build dir
+ -- if the top level module is in a sub dir: say, Tools/Source.hs
[] editing an included, but not viewed module should trigger recompile
for modules that use
[] compilation system tracks mod and compilation times to avoid reloading
View
@@ -110,8 +110,8 @@ emptyModule filename =
scriptSrcs :: [String]
scriptSrcs =
- [ "static/jquery.js"
- , "static/jquery.elastic.js"
+ [ "/static/jquery.js"
+ , "/static/codemirror_min.js"
, "Source.js"
]
View
@@ -6,15 +6,36 @@ bDisable = function(i) {
$(i).attr('disabled', 'disabled').animate({opacity: 0.2}, 'fast');
}
+editor = null;
+
+buildEditor = function(readOnly) {
+ if (editor) {
+ editor.toTextArea();
+ editor = null;
+ }
+ editor = CodeMirror.fromTextArea("txt-src", {
+ basefiles: ["/static/codemirror_base_min.js"],
+ parserfile: ["/static/codemirror_parse_dummy_min.js"],
+ stylesheet: "/static/codemirror.css",
+ autoMatchParens: true,
+ textWrapping: false,
+ lineNumbers: true,
+ indentUnit: 4,
+ tabMode: "spaces",
+ readOnly: readOnly
+ });
+}
mkEditable = function() {
$('#txt-src').removeAttr('readonly');
+ buildEditor(false);
bDisable('#btn-edit');
bEnable('#btn-cancel');
bEnable('#btn-save');
};
mkReadOnly = function() {
$('#txt-src').attr('readonly', 'readonly');
+ buildEditor(true);
bEnable('#btn-edit');
bDisable('#btn-cancel');
bDisable('#btn-save');
@@ -31,22 +52,6 @@ setResearch = function(e) {
};
};
-buildLineNos = function() {
- var ns = "";
- for (var i in $(this).get(0).innerHTML.split("\n")) {
- ns += (1*i + 1) + "\n";
- }
- var n = $("<pre>"+ns+"</pre>");
- n.attr("class", "linenos");
-
- $(this).wrap("<div class=\"with-linenos\" />")
- .before(n);
-};
-
-$('#txt-src')
- .select(function () { setResearch($(this).get(0)); })
- .elastic()
- .each(buildLineNos);
$('#btn-edit').click(mkEditable);
$('#btn-cancel').click(mkReadOnly);
mkReadOnly();
Oops, something went wrong. Retry.

0 comments on commit cd15b5e

Please sign in to comment.