Skip to content

Commit

Permalink
cleaned up swap files in repo
Browse files Browse the repository at this point in the history
  • Loading branch information
collin committed Oct 9, 2008
1 parent 7bec143 commit 7d6bd85
Show file tree
Hide file tree
Showing 13 changed files with 1,176 additions and 231 deletions.
5 changes: 5 additions & 0 deletions build
Expand Up @@ -58,9 +58,14 @@ class GistLiveContinuousBuilder < ContinuousBuilder
:files => "./public/edit_area/*.js",
:update => :repack

watches :legs,
:files => "./public/legs.js",
:update => :repack

def pack
pack = []
pack << ($dir/'vendor'/'jquery-1.2.6.min.js').read
pack << ($dir/'vendor'/'json2.js').read
pack
end

Expand Down
45 changes: 26 additions & 19 deletions lib/mission_control.rb
Expand Up @@ -4,46 +4,53 @@
require 'ostruct'

Legs.start do
def initialize
@documents = {}
@editors = {}
@owners = {}
end

def begin_editing data, file_name
document = OpenStruct.new :name => file_name,
:id => UUID.new, :data => data
:uuid => UUID.new, :data => data

@documents[document.id] = document
@editors[document.id] = [self]
@owners[document.id] = self
@documents[document.uuid] = document
@editors[document.uuid] = [@caller]
@owners[document.uuid] = @caller

document
@caller.notify! :uuid, document.uuid
true
end

def also_edit document_id
def also_editing document_id
document = @documents[document_id]
@editors[document_id] << self
document
@editors[document_id] << @caller
@caller.notify! :edit, document.send(:table)
true
end

def stop_editing document_id, reason="saved"
return false unless @owners[document_id] == self
for editor in @editors[document_id] - [self]
return :false unless @owners[document_id] == @caller
for editor in (@editors[document_id] - [@caller])
editor.notify!(:stopped, reason)
end
true
end


def diff document_id, patch
for editor in @editors[document_id] - [self]
editor.notify! :patch, patch
for editor in @editors[document_id]
if editor == @caller
@caller.notify! :info, "patching remotely"
else
editor.notify! :patch, patch
end
end
true
'diffed'
end

private

def initialize
@documents = {}
@editors = {}
@owners = {}
end

def log?; true end
end

Expand Down
50 changes: 0 additions & 50 deletions lib/mission_control.rb~

This file was deleted.

41 changes: 39 additions & 2 deletions public/editor.html
Expand Up @@ -18,14 +18,51 @@
<script src='http://localhost:4567/editor.js'></script>
<script type='text/javascript'>
//<![CDATA[
document.write('<textarea id="editarea">'+window.name+'</textarea>');
if(name) {
var gist = JSON.parse(name);
document.write('<textarea id="editarea">'+gist.text+'</textarea>');
}
else {
document.write('<textarea id="editarea"></textarea>');
}

var dmp = new diff_match_patch();
var last_value;

function watch_editarea() {
if(location.hash) {
uuid = location.hash.slice(1);
Legs.also_editing(uuid)
}

if(!window.uuid) {
Legs.begin_editing(gist.text, gist.filename)
}

var area = jQuery('#frame_editarea').contents().find('textarea')
last_value = editAreaLoader.getValue('editarea')
var current, patch;
function patch_loop() {
current = editAreaLoader.getValue('editarea')
patch = dmp.patch_make(last_value, current)
patch = dmp.patch_toText(patch)
if(patch) Legs.diff(window.uuid, patch)
last_value = current
setTimeout(patch_loop, 1000)
}
patch_loop()
}

editAreaLoader.init({
id : "editarea" // textarea id
,syntax: "ruby" // syntax to be uses for highgliting
,start_highlight: true // to display with highlight mode on start-up
,toolbar: "search, go_to_line, undo, redo, change_smooth_selection, reset_highlight, highlight, help, save, syntax_selection"
,toolbar: "search, go_to_line.find('#textarea'), undo, redo, change_smooth_selection, reset_highlight, highlight, help, save, syntax_selection"
,allow_toggle: false
,EA_load_callback: 'watch_editarea'
})
//]]>
</script>
</head>
<body></body>
</html>

0 comments on commit 7d6bd85

Please sign in to comment.