Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixing styling issues, cleaning up a bit

  • Loading branch information...
commit f1e3cf44226f1c93ea2db61571ff366f2b90e34a 1 parent e654aee
@jucovschi authored
View
8 Cakefile
@@ -19,6 +19,8 @@ client = [
'types/helpers'
'types/text'
'types/text-api'
+ 'types/etherpad'
+ 'types/etherpad-api'
'client/doc'
'client/connection'
'client/index'
@@ -83,13 +85,15 @@ buildtype = (name) ->
task 'webclient', 'Build the web client into one file', ->
compile client, 'webclient/share'
buildtype 'json'
+ buildtype 'etherpad'
buildtype 'text-tp2'
# TODO: This should also be closure compiled.
extrafiles = expandNames extras
e "coffee --compile --output webclient/ #{extrafiles}", ->
- # For backwards compatibility. (The ace.js file used to be called share-ace.js)
- e "cp webclient/ace.js webclient/share-ace.js"
+ # For backwards compatibility. (The ace.js file used to be called share-ace.js)
+ e "cp webclient/ace.js webclient/share-ace.js"
+ e "cp src/lib-etherpad/* webclient/"
#task 'lightwave', ->
# buildclosure ['client/web-prelude', 'client/microevent', 'types/text-tp2'], 'lightwave'
View
0  src/types/AttributePool.js → src/lib-etherpad/AttributePool.js
File renamed without changes
View
0  src/types/Changeset.js → src/lib-etherpad/Changeset.js
File renamed without changes
View
191 src/types/etherpad-api.coffee
@@ -1,120 +1,93 @@
# Text document API for text
-# :tabSize=4:indentSize=4:
+# :tabSize=2:indentSize=2:
if WEB?
- Changeset = window.ShareJS.Changeset
- AttributePool = window.ShareJS.AttributePool
+ if window.ShareJS? && window.ShareJS.Changeset?
+ Changeset = window.ShareJS.Changeset
+ AttributePool = window.ShareJS.AttributePool
+ else
+ console.log("Etherpad library not found. Make sure to include Attributepool.js and Changeset.js in your javascript sourcecode");
else
- etherpad = require './etherpad'
- AttributePool = require './AttributePool'
- Changeset = require './Changeset'
-
+ etherpad = require './../lib-etherpad/etherpad'
+ AttributePool = require './../lib-etherpad/AttributePool'
+ Changeset = require './Changeset'
+
etherpad.api =
- provides: {text:true}
+ provides: { text:true }
- # The number of characters in the string
- getLength: -> @snapshot.text.length
+ # The number of characters in the string
+ getLength: -> @snapshot.text.length
- # Get the text contents of a document
- getText: -> @snapshot.text
+ # Get the text contents of a document
+ getText: -> @snapshot.text
- getInteraction: (state) ->
- state.forward = true
- this.connection.send({
- doc: this.name,
- meta: state
- });
-
- # Get metadata starting from offset startOffset and having length length
- getMeta: (startOffset, length) ->
- if (typeof @snapshot.pool.getAttrib == "undefined")
- @snapshot = etherpad.tryDeserializeSnapshot(@snapshot);
- snapshot = @snapshot;
- iter = Changeset.opIterator(snapshot.attribs)
- offset = 0;
- result = [];
- rangeStart = Changeset.numToString(@snapshot.pool.putAttrib(["range.start",1], true));
- rangeEnd = Changeset.numToString(@snapshot.pool.putAttrib(["range.end",1], true));
- rangeProps = [];
- inRange = false;
- clearRange = false
- while iter.hasNext()
- o = iter.next()
- if (o.opcode=='-')
- continue;
- if (clearRange)
- rangeProps = "";
- inRange = true;
- clearRange = false;
- # range is started
- if (o.attribs.match("\\*"+rangeStart))
- rangeProps = o.attribs;
- inRange = true;
- # range finishes but needs to take effect starting from next token
- if (o.attribs.match("\\*"+rangeEnd))
- clearRange = true;
-
- if (offset + o.chars < startOffset)
- offset = offset + o.chars;
- continue;
- if (offset > startOffset + length)
- break;
+ # Get metadata starting from offset startOffset and having length length
+ getMeta: (startOffset, length) ->
+ if typeof @snapshot.pool.getAttrib == "undefined"
+ @snapshot = etherpad.tryDeserializeSnapshot(@snapshot);
+ snapshot = @snapshot;
+ iter = Changeset.opIterator(snapshot.attribs)
+ offset = 0;
+ result = [];
+ rangeStart = Changeset.numToString(@snapshot.pool.putAttrib(["range.start",1], true));
+ rangeEnd = Changeset.numToString(@snapshot.pool.putAttrib(["range.end",1], true));
+ rangeProps = [];
+ inRange = false;
+ clearRange = false
+ while iter.hasNext()
+ o = iter.next()
+ if o.opcode=='-'
+ continue;
+ if clearRange
+ rangeProps = "";
+ inRange = true;
+ clearRange = false;
+ # range is started
+ if o.attribs.match("\\*"+rangeStart)
+ rangeProps = o.attribs;
+ inRange = true;
+ # range finishes but needs to take effect starting from next token
+ if o.attribs.match("\\*"+rangeEnd)
+ clearRange = true;
+ if offset + o.chars < startOffset
+ offset = offset + o.chars;
+ continue;
+ if offset > startOffset + length
+ break;
- if (inRange)
- att = rangeProps;
- valList = [];
- att.replace(/\*([0-9a-zA-Z]+)/g, (match...) ->
- attid = Changeset.parseNum(match[1]);
- att = snapshot.pool.getAttrib(attid);
- valList.push({
- key:att[0],
- value:att[1]
- });
- )
- if (valList.length>0)
- result.push({
- start: Math.max(startOffset, offset),
- end: Math.min(startOffset+length, offset + o.chars),
- attributes: valList,
- })
- offset = offset + o.chars
- return result
-
- insert: (pos, text, callback) ->
- result = {};
- result.pool = new AttributePool();
- result.changeset = Changeset.builder(@snapshot.text.length)
- .keep(pos,0).insert(text, "", result.pool).toString()
- @submitOp result, callback
- result
+ insert: (pos, text, callback) ->
+ result = {};
+ result.pool = new AttributePool();
+ result.changeset = Changeset.builder(@snapshot.text.length)
+ .keep(pos,0).insert(text, "", result.pool).toString()
+ @submitOp result, callback
+ result
- del: (pos, length, callback) ->
- result = {};
- result.pool = new AttributePool()
- result.changeset = Changeset.builder(@snapshot.text.length).keep(pos,0).remove(length,0).toString()
- @submitOp result, callback
- result
+ del: (pos, length, callback) ->
+ result = {};
+ result.pool = new AttributePool()
+ result.changeset = Changeset.builder(@snapshot.text.length).keep(pos,0).remove(length,0).toString()
+ @submitOp result, callback
+ result
- _register: ->
- @on 'remoteop', (op) ->
- unpacked = Changeset.unpack(op.changeset);
- iter = Changeset.opIterator(unpacked.ops)
- strIter = Changeset.stringIterator(unpacked.charBank);
- offset = 0;
- refreshFirstOffset = 10000000;
- refreshLastOffset = -1;
- while iter.hasNext()
- o = iter.next()
- switch (o.opcode)
- when '+'
- @emit 'insert', offset, strIter.take(o.chars);
- offset = offset + o.chars
- when '-'
- @emit 'delete', offset, { length: o.chars }
- when '='
- if o.attribs.length > 0
- refreshFirstOffset = Math.min(offset, refreshFirstOffset);
- refreshLastOffset = Math.max(offset + o.chars, refreshLastOffset);
- offset = offset + o.chars
- #if (refreshLastOffset > 0)
- # @emit 'refresh', refreshFirstOffset, refreshLastOffset - refreshFirstOffset
+ _register: ->
+ @on 'remoteop', (op) ->
+ unpacked = Changeset.unpack(op.changeset);
+ iter = Changeset.opIterator(unpacked.ops)
+ strIter = Changeset.stringIterator(unpacked.charBank);
+ offset = 0;
+ refreshFirstOffset = 10000000;
+ refreshLastOffset = -1;
+ while iter.hasNext()
+ o = iter.next()
+ switch (o.opcode)
+ when '+'
+ @emit 'insert', offset, strIter.take(o.chars);
+ offset = offset + o.chars
+ when '-'
+ @emit 'delete', offset, { length: o.chars }
+ when '='
+ if o.attribs.length > 0
+ refreshFirstOffset = Math.min(offset, refreshFirstOffset);
+ refreshLastOffset = Math.max(offset + o.chars, refreshLastOffset);
+ offset = offset + o.chars
View
155 src/types/etherpad.coffee
@@ -1,107 +1,99 @@
# This is the type for etherpad changesets
# The snapshot has a JSON structure of
-# {
-# "text" - the text of the pad
-# "attribs" - attributes
-# "pool" - the attribute pool
-# }
+# {
+# "text" - the text of the pad
+# "attribs" - attributes
+# "pool" - the attribute pool
+# }
# The Changesets have the structure
-# {
-# "changeset" - serialized version of the changeset
-# "pool" - the pool
-# }
+# {
+# "changeset" - serialized version of the changeset
+# "pool" - the pool
+# }
if WEB?
- Changeset = window.ShareJS.Changeset
- AttributePool = window.ShareJS.AttributePool
+ if window.ShareJS? && window.ShareJS.Changeset?
+ Changeset = window.ShareJS.Changeset
+ AttributePool = window.ShareJS.AttributePool
+ else
+ console.log("Etherpad library not found. Make sure to include Attributepool.js and Changeset.js in your javascript sourcecode");
else
- Changeset = require("./Changeset");
- AttributePool = require("./AttributePool");
+ Changeset = require("./../lib-etherpad/Changeset");
+ AttributePool = require("./../lib-etherpad/AttributePool");
etherpad = {}
etherpad.name = "etherpad"
-etherpad.create = ->
- {
- "text" : "",
- "attribs" : Changeset.makeAttribution(""),
- "pool" : new AttributePool()
- }
+etherpad.create = ->
+ "text" : "",
+ "attribs" : Changeset.makeAttribution(""),
+ "pool" : new AttributePool()
etherpad.tryDeserializeSnapshot = (snapshot) ->
- if (snapshot.pool.clone)
- return snapshot
- snapshot.pool = new AttributePool().fromJsonable(snapshot.pool)
- return snapshot;
-
+ if snapshot.pool.clone
+ return snapshot
+ snapshot.pool = new AttributePool().fromJsonable(snapshot.pool)
+ return snapshot;
+
etherpad.tryDeserializeOp = (op) ->
- if (op.pool.clone)
- return op;
- if (op.pool.numToAttrib)
- op.pool = new AttributePool().fromJsonable(op.pool)
- else
- op.pool = new AttributePool().fromJsonable(JSON.parse(op.pool))
- return op
-
+ if op.pool.clone
+ return op;
+ if op.pool.numToAttrib
+ op.pool = new AttributePool().fromJsonable(op.pool)
+ else
+ op.pool = new AttributePool().fromJsonable(JSON.parse(op.pool))
+ return op
+
etherpad.apply = (snapshot, op) ->
- snapshot = etherpad.tryDeserializeSnapshot(snapshot)
- op = etherpad.tryDeserializeOp(op)
- result = {}
- result.pool = snapshot.pool.clone();
-
- newCS = Changeset.moveOpsToNewPool(op.changeset, op.pool, result.pool);
- result.text = Changeset.applyToText(newCS, snapshot.text);
- console.log(newCS);
- result.attribs = Changeset.applyToAttribution(newCS, snapshot.attribs, result.pool);
- return result
-
+ snapshot = etherpad.tryDeserializeSnapshot(snapshot)
+ op = etherpad.tryDeserializeOp(op)
+ result = {}
+ result.pool = snapshot.pool.clone();
+ newCS = Changeset.moveOpsToNewPool(op.changeset, op.pool, result.pool);
+ result.text = Changeset.applyToText(newCS, snapshot.text);
+ result.attribs = Changeset.applyToAttribution(newCS, snapshot.attribs, result.pool);
+ return result
+
etherpad.transform = (op1, op2, side) ->
- op1 = etherpad.tryDeserializeOp(op1)
- op2 = etherpad.tryDeserializeOp(op2)
- result = {}
- # join the operation pools into a new one
- newPool = op1.pool.clone();
- # newPool will hold the combined pool
- # op2cs will hold the rewritten op2 cs
- op2cs = Changeset.moveOpsToNewPool(op2.changeset, op2.pool, newPool);
- result.changeset = Changeset.follow(op1.changeset, op2cs, side=="right", newPool);
- result.pool = newPool
- return result
+ op1 = etherpad.tryDeserializeOp(op1)
+ op2 = etherpad.tryDeserializeOp(op2)
+ result = {}
+ # join the operation pools into a new one
+ newPool = op1.pool.clone();
+ # newPool will hold the combined pool
+ # op2cs will hold the rewritten op2 cs
+ op2cs = Changeset.moveOpsToNewPool(op2.changeset, op2.pool, newPool);
+ result.changeset = Changeset.follow(op1.changeset, op2cs, side=="right", newPool);
+ result.pool = newPool
+ return result
etherpad.compose = (op1, op2) ->
- op1 = etherpad.tryDeserializeOp(op1)
- op2 = etherpad.tryDeserializeOp(op2)
- result = {}
- # join the operation pools into a new one
- newPool = op1.pool.clone();
- # newPool will hold the combined pool
- # op2cs will hold the rewritten op2 cs
- op2cs = Changeset.moveOpsToNewPool(op2.changeset, op2.pool, newPool);
- result.changeset = Changeset.compose(op1.changeset, op2cs, newPool);
- result.pool = newPool
- return result
+ op1 = etherpad.tryDeserializeOp(op1)
+ op2 = etherpad.tryDeserializeOp(op2)
+ result = {}
+ # join the operation pools into a new one
+ newPool = op1.pool.clone();
+ # newPool will hold the combined pool
+ # op2cs will hold the rewritten op2 cs
+ op2cs = Changeset.moveOpsToNewPool(op2.changeset, op2.pool, newPool);
+ result.changeset = Changeset.compose(op1.changeset, op2cs, newPool);
+ result.pool = newPool
+ return result
etherpad.serialize = (snapshot) ->
- result = {}
- result.text = snapshot.text
- result.attribs = snapshot.attribs
- result.pool = snapshot.pool.toJsonable()
- return result
+ text = snapshot.text
+ attribs = snapshot.attribs
+ pool = snapshot.pool.toJsonable()
etherpad.serializeOp = (snapshot) ->
- result = {}
- result.changeset = snapshot.changeset
- result.pool = JSON.stringify(snapshot.pool)
- return result
+ changeset = snapshot.changeset
+ pool = JSON.stringify(snapshot.pool)
-
etherpad.deserialize = (obj) ->
- result = {}
- result.text = obj.text
- result.attribs = obj.attribs
- result.pool = new AttributePool().fromJsonable(obj.pool)
- return result
+ text = obj.text
+ attribs = obj.attribs
+ pool = new AttributePool().fromJsonable(obj.pool)
if WEB?
exports.types ||= {}
@@ -110,6 +102,3 @@ if WEB?
exports.types.etherpad = etherpad
else
module.exports = etherpad
-
- # require('./helpers').bootstrapTransform(json, json.transformComponent, json.checkValidOp, json.append)
-
View
2  src/types/index.coffee
@@ -12,4 +12,6 @@ register './text'
register './text-composable'
register './text-tp2'
+register './etherpad'
+
register './json'
Please sign in to comment.
Something went wrong with that request. Please try again.