sn-collab-editor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +37 -0
- data/app/assets/config/collab_manifest.js +2 -0
- data/app/assets/javascripts/collab/application.js +3 -0
- data/app/assets/javascripts/collab/cable.js +40 -0
- data/app/assets/javascripts/collab/channels/collab/edit.js +0 -0
- data/app/assets/javascripts/collab/documents.js +87 -0
- data/app/assets/stylesheets/collab/application.css +49 -0
- data/app/assets/stylesheets/collab/documents.css +4 -0
- data/app/channels/application_cable/channel.rb +4 -0
- data/app/channels/application_cable/connection.rb +4 -0
- data/app/channels/edit_channel.rb +21 -0
- data/app/controllers/collab/application_controller.rb +15 -0
- data/app/controllers/collab/documents_controller.rb +35 -0
- data/app/helpers/collab/application_helper.rb +4 -0
- data/app/helpers/collab/documents_helper.rb +4 -0
- data/app/jobs/collab/application_job.rb +4 -0
- data/app/mailers/collab/application_mailer.rb +6 -0
- data/app/models/collab/application_record.rb +5 -0
- data/app/models/collab/document.rb +4 -0
- data/app/views/collab/documents/show.html.erb +9 -0
- data/app/views/layouts/collab/application.html.erb +13 -0
- data/config/cable.yml +9 -0
- data/config/initializers/assets.rb +3 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20170222133537_create_collab_documents.rb +9 -0
- data/lib/collab.rb +5 -0
- data/lib/collab/engine.rb +5 -0
- data/lib/collab/version.rb +3 -0
- data/lib/tasks/collab_tasks.rake +4 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 49de97f783331e2e553b985f416c595d7d55a103
|
4
|
+
data.tar.gz: f2764ac59a5a37b1837405e6a7acc22438bceac1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2d722e15f7aa2bd7d71c955069dc66317e9b06e854929ec0b5e1e629788ab4f929eadfd092361011f0d43ab1a78aa5e469833f2345edd7e18d3caccbacad5d6
|
7
|
+
data.tar.gz: 1d31c2fe4bbaa60d4e0ffe329f81363df4cab6cd597bf954e2faae7efb4cffcc0b7a9e0cd375f03dc9df2b2144543c80376e5568f890dd12307c64c94f9856a6
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Collab
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'collab'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install collab
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Collab'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,40 @@
|
|
1
|
+
// Action Cable provides the framework to deal with WebSockets in Rails.
|
2
|
+
// You can generate new channels where WebSocket features live using the rails generate channel command.
|
3
|
+
//
|
4
|
+
//= require action_cable
|
5
|
+
//= require_self
|
6
|
+
//= require_tree ./channels
|
7
|
+
|
8
|
+
document.addEventListener("DOMContentLoaded", function(event) {
|
9
|
+
|
10
|
+
var clientId = Math.random()*100;
|
11
|
+
|
12
|
+
App.socket = {};
|
13
|
+
App.socket.cable = ActionCable.createConsumer();
|
14
|
+
|
15
|
+
App.socket.subscribeToDoc = function(docId, callback) {
|
16
|
+
App.socket.channel = App.socket.cable.subscriptions.create({channel: "EditChannel", doc_id: docId}, {
|
17
|
+
connected: function() {
|
18
|
+
// Called when the subscription is ready for use on the server
|
19
|
+
},
|
20
|
+
|
21
|
+
disconnected: function() {
|
22
|
+
// Called when the subscription has been terminated by the server
|
23
|
+
},
|
24
|
+
|
25
|
+
received: function(data) {
|
26
|
+
console.log("received data", data);
|
27
|
+
// Called when there's incoming data on the websocket for this channel
|
28
|
+
if(data.clientId != clientId) {
|
29
|
+
callback(data.message);
|
30
|
+
}
|
31
|
+
},
|
32
|
+
|
33
|
+
speak: function(message) {
|
34
|
+
console.log("speaking", message);
|
35
|
+
return this.perform('speak', {message: message, id: docId, sender: clientId});
|
36
|
+
}
|
37
|
+
});
|
38
|
+
};
|
39
|
+
|
40
|
+
}.bind(this))
|
File without changes
|
@@ -0,0 +1,87 @@
|
|
1
|
+
//= require ./cable.js
|
2
|
+
|
3
|
+
document.addEventListener("DOMContentLoaded", function(event) {
|
4
|
+
|
5
|
+
var editor = document.getElementById("editor");
|
6
|
+
|
7
|
+
function createNewDocument() {
|
8
|
+
console.log("doc not found, going to new");
|
9
|
+
window.location.href = "/collab/doc/new";
|
10
|
+
}
|
11
|
+
|
12
|
+
function subscribeToDocId(docId) {
|
13
|
+
// subscribe to updates
|
14
|
+
console.log("subscribing to doc", docId);
|
15
|
+
App.socket.subscribeToDoc(docId, function(message){
|
16
|
+
console.log("Received message in callback:", message);
|
17
|
+
editor.value = message;
|
18
|
+
})
|
19
|
+
}
|
20
|
+
|
21
|
+
var uuidLength = 36;
|
22
|
+
var location = window.location.href;
|
23
|
+
var uuidCandidate = location.split("/").slice(-1)[0];
|
24
|
+
var hasDocument = uuidCandidate.length == uuidLength;
|
25
|
+
var noteId = sessionStorage.getItem("lastNoteId");
|
26
|
+
|
27
|
+
if(window.parent != window) {
|
28
|
+
if(hasDocument) {
|
29
|
+
// inform parent of new document
|
30
|
+
console.log("notifying parent of new doc", noteId);
|
31
|
+
window.parent.postMessage({text: buildParamsString({id: uuidCandidate}), id: noteId}, '*');
|
32
|
+
subscribeToDocId(uuidCandidate);
|
33
|
+
} else {
|
34
|
+
window.parent.postMessage({status: "ready"}, '*');
|
35
|
+
}
|
36
|
+
} else {
|
37
|
+
if(!hasDocument) {
|
38
|
+
createNewDocument();
|
39
|
+
} else {
|
40
|
+
subscribeToDocId(uuidCandidate);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
function buildParamsString(doc) {
|
45
|
+
var string = "";
|
46
|
+
for(var key in doc) {
|
47
|
+
string += key + ": " + doc[key] + "\n";
|
48
|
+
}
|
49
|
+
string += "%%Do not modify above this line%%";
|
50
|
+
return string;
|
51
|
+
}
|
52
|
+
|
53
|
+
window.addEventListener("message", function(event){
|
54
|
+
|
55
|
+
console.log("Received message from parent frame", event.data);
|
56
|
+
|
57
|
+
var text = event.data.text || "";
|
58
|
+
sessionStorage.setItem("lastNoteId", event.data.id);
|
59
|
+
|
60
|
+
var paramString = text.split("%%Do not modify above this line%%")[0];
|
61
|
+
var lines = paramString.split("\n");
|
62
|
+
var params = {};
|
63
|
+
lines.forEach(function(line){
|
64
|
+
var comps = line.split(": ");
|
65
|
+
var key = comps[0];
|
66
|
+
var value = comps[1];
|
67
|
+
params[key] = value;
|
68
|
+
})
|
69
|
+
|
70
|
+
console.log("params", params);
|
71
|
+
|
72
|
+
let docId = params["id"]
|
73
|
+
if (docId && docId.length) {
|
74
|
+
window.location.href = "/collab/doc/" + docId;
|
75
|
+
} else {
|
76
|
+
createNewDocument();
|
77
|
+
}
|
78
|
+
}, false);
|
79
|
+
|
80
|
+
if(editor) {
|
81
|
+
editor.addEventListener("input", function(event){
|
82
|
+
var text = event.target.value;
|
83
|
+
App.socket.channel.speak(text);
|
84
|
+
})
|
85
|
+
}
|
86
|
+
|
87
|
+
})
|
@@ -0,0 +1,49 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
16
|
+
|
17
|
+
html, body {
|
18
|
+
height: 100%;
|
19
|
+
width: 100%;
|
20
|
+
font-size: 14px;
|
21
|
+
font-family: sans-serif;
|
22
|
+
margin: 0;
|
23
|
+
padding: 7px;
|
24
|
+
}
|
25
|
+
|
26
|
+
#wrapper {
|
27
|
+
height: 100%;
|
28
|
+
display: flex;
|
29
|
+
flex-direction: column;
|
30
|
+
}
|
31
|
+
|
32
|
+
#editor {
|
33
|
+
flex: 1;
|
34
|
+
width: 100%;
|
35
|
+
height: 100%:
|
36
|
+
resize: none;
|
37
|
+
font-size: 16px;
|
38
|
+
border: 1px solid rgb(226, 226, 226);
|
39
|
+
border-radius: 4px;
|
40
|
+
padding: 15px;
|
41
|
+
margin-top: 10px;
|
42
|
+
font-family: monospace;
|
43
|
+
}
|
44
|
+
|
45
|
+
* {
|
46
|
+
box-sizing: border-box;
|
47
|
+
}
|
48
|
+
|
49
|
+
textarea, input, button { outline: none; }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class EditChannel < ApplicationCable::Channel
|
2
|
+
def subscribed
|
3
|
+
doc = Collab::Document.find_by_uuid(params['doc_id'])
|
4
|
+
# stream_from "doc_#{params[:doc_id]}"
|
5
|
+
stream_for doc
|
6
|
+
end
|
7
|
+
|
8
|
+
def unsubscribed
|
9
|
+
# ActionCable.server.broadcast('messages', message: render_message(data['message']))
|
10
|
+
end
|
11
|
+
|
12
|
+
def speak(data)
|
13
|
+
puts "received message #{data.inspect}"
|
14
|
+
message = data['message']
|
15
|
+
# ActionCable.server.broadcast('messages', message: message)
|
16
|
+
doc = Collab::Document.find_by_uuid(data['id'])
|
17
|
+
doc.content = message
|
18
|
+
doc.save
|
19
|
+
EditChannel.broadcast_to(doc, {:message => message})
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Collab
|
2
|
+
class ApplicationController < ActionController::Base
|
3
|
+
protect_from_forgery with: :null_session
|
4
|
+
|
5
|
+
after_action :allow_iframe
|
6
|
+
|
7
|
+
def allow_iframe
|
8
|
+
response.headers.except! 'X-Frame-Options'
|
9
|
+
end
|
10
|
+
|
11
|
+
def wrapper
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_dependency "collab/application_controller"
|
2
|
+
|
3
|
+
module Collab
|
4
|
+
class DocumentsController < ApplicationController
|
5
|
+
|
6
|
+
def show
|
7
|
+
if params[:uuid]
|
8
|
+
@doc = Document.find_by_uuid(params[:uuid])
|
9
|
+
end
|
10
|
+
if !@doc
|
11
|
+
return
|
12
|
+
end
|
13
|
+
@url = url
|
14
|
+
end
|
15
|
+
|
16
|
+
def url
|
17
|
+
"#{Collab.mount_url}/doc/#{@doc.uuid}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
@doc = Document.new
|
22
|
+
@doc.uuid = SecureRandom.uuid
|
23
|
+
@doc.save
|
24
|
+
end
|
25
|
+
|
26
|
+
def new
|
27
|
+
puts "\n\nCreating new document\n\n"
|
28
|
+
@doc = Document.new
|
29
|
+
@doc.uuid = SecureRandom.uuid
|
30
|
+
@doc.save
|
31
|
+
redirect_to(url)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Collab</title>
|
5
|
+
<%= stylesheet_link_tag "collab/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "collab/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<%= yield %>
|
11
|
+
|
12
|
+
</body>
|
13
|
+
</html>
|
data/config/cable.yml
ADDED
data/config/routes.rb
ADDED
data/lib/collab.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sn-collab-editor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Standard Notes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.1
|
27
|
+
description: Standard Notes editor with collaboration abilities.
|
28
|
+
email:
|
29
|
+
- hello@standardnotes.org
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- app/assets/config/collab_manifest.js
|
38
|
+
- app/assets/javascripts/collab/application.js
|
39
|
+
- app/assets/javascripts/collab/cable.js
|
40
|
+
- app/assets/javascripts/collab/channels/collab/edit.js
|
41
|
+
- app/assets/javascripts/collab/documents.js
|
42
|
+
- app/assets/stylesheets/collab/application.css
|
43
|
+
- app/assets/stylesheets/collab/documents.css
|
44
|
+
- app/channels/application_cable/channel.rb
|
45
|
+
- app/channels/application_cable/connection.rb
|
46
|
+
- app/channels/edit_channel.rb
|
47
|
+
- app/controllers/collab/application_controller.rb
|
48
|
+
- app/controllers/collab/documents_controller.rb
|
49
|
+
- app/helpers/collab/application_helper.rb
|
50
|
+
- app/helpers/collab/documents_helper.rb
|
51
|
+
- app/jobs/collab/application_job.rb
|
52
|
+
- app/mailers/collab/application_mailer.rb
|
53
|
+
- app/models/collab/application_record.rb
|
54
|
+
- app/models/collab/document.rb
|
55
|
+
- app/views/collab/documents/show.html.erb
|
56
|
+
- app/views/layouts/collab/application.html.erb
|
57
|
+
- config/cable.yml
|
58
|
+
- config/initializers/assets.rb
|
59
|
+
- config/routes.rb
|
60
|
+
- db/migrate/20170222133537_create_collab_documents.rb
|
61
|
+
- lib/collab.rb
|
62
|
+
- lib/collab/engine.rb
|
63
|
+
- lib/collab/version.rb
|
64
|
+
- lib/tasks/collab_tasks.rake
|
65
|
+
homepage: https://standardnotes.org
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.4.8
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Standard Notes editor with collaboration abilities.
|
89
|
+
test_files: []
|