jointjs 0.0.3
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/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +4 -0
- data/ethereal.gemspec +23 -0
- data/lib/ethereal.rb +5 -0
- data/lib/ethereal/app/assets/javascripts/ethereal.js.coffee +6 -0
- data/lib/ethereal/app/assets/javascripts/ethereal/base.js.coffee +51 -0
- data/lib/ethereal/app/assets/javascripts/ethereal/ext.js.coffee +7 -0
- data/lib/ethereal/app/assets/javascripts/ethereal/god.js.coffee +43 -0
- data/lib/ethereal/app/assets/javascripts/ethereal/model.js.coffee +8 -0
- data/lib/ethereal/app/assets/javascripts/ethereal/watcher.js.coffee +50 -0
- data/lib/ethereal/app/assets/javascripts/ethereal/xhr.js.coffee +34 -0
- data/lib/ethereal/app/views/layouts/application.js.erb +6 -0
- data/lib/ethereal/railtie.rb +8 -0
- data/lib/ethereal/version.rb +3 -0
- data/test/application.rb +11 -0
- data/test/config/database.yml +5 -0
- data/test/integration/load_test.rb +24 -0
- data/test/js/base.js +33 -0
- data/test/js/god.js +67 -0
- data/test/js/list.js +21 -0
- data/test/js/models.js +23 -0
- data/test/js/watcher.js +110 -0
- data/test/test_helper.rb +15 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 02aa4d86af26c37f22af7d0d5b37dd45afc38003
|
4
|
+
data.tar.gz: f4a8921aa06e7fa7e5ea0e9977e2f645e2c216cc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1bf513ca071257ec05d0909cdea4d078cab624589fc03816d781b6bcaf70601b714ac563c6fdf632ecc35d3124823908c23c9cbb389e23067bd3b2345faac1ea
|
7
|
+
data.tar.gz: 9f32ce523cd077fc836752c53a379194a4c582552694df32fffbaa4c65620aecf6b57dc36ea6d7b203d0ebedb55fe8480cab3db10517e01e3aaf4d7b3109df2e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Pier-Olivier Thibault
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Ethereal
|
2
|
+
|
3
|
+
Event based JavaScript framework tailored made for Ruby on rails.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ethereal'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then add this line to application.js
|
14
|
+
|
15
|
+
```js
|
16
|
+
//= require 'ethereal'
|
17
|
+
```
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Ethereal is an event based framework that manages the life cycle of JavaScript objects. Here's a simple Todo where you can dynamically add/remove items on the list.
|
21
|
+
|
22
|
+
```erb
|
23
|
+
<!-- views/todos/index.html.erb -->
|
24
|
+
<%= content_tag :ol, as: 'Todo.List', do %>
|
25
|
+
<%= render @todos %>
|
26
|
+
<% end %>
|
27
|
+
```
|
28
|
+
|
29
|
+
```coffee
|
30
|
+
# assets/javascripts/todos/list.js.coffee
|
31
|
+
class Todos
|
32
|
+
# @element() always return the element to which your object is bound.
|
33
|
+
|
34
|
+
loaded: =>
|
35
|
+
@element().on 'todos:create', @add
|
36
|
+
@element().on 'todos:destroy', @delete
|
37
|
+
|
38
|
+
add: (e) =>
|
39
|
+
@element().appendChild(e.html)
|
40
|
+
|
41
|
+
delete: (e) =>
|
42
|
+
@element().querySelector("[tid=#{e.todoId}]")?.remove()
|
43
|
+
|
44
|
+
Ethereal.Models.add Todos, 'Todo.List'
|
45
|
+
```
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
#views/todos/create.js.erb
|
49
|
+
e.html = "<%= j render(@todo) %>".toHTML()
|
50
|
+
```
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
#views/todos/destroy.js.erb
|
54
|
+
e.todoId = <%= @todo.id %>
|
55
|
+
```
|
56
|
+
|
57
|
+
Some notes:
|
58
|
+
|
59
|
+
- Automatic instantiation. No need to wrap things in DOMContentReady anymore.
|
60
|
+
- Events are built following the "controller:action" pattern.
|
61
|
+
- A callback (@loaded) is called right after Ethereal has instantiated an object.
|
62
|
+
- In *.js.erb, an event is created. You can set HTML to the event object.
|
63
|
+
- To ease the process, a toHTML() method has been added to the String object (JS).
|
64
|
+
- You need to register any class you create through the ```Ethereal.Models.add Class, 'name'```. The name is the attribute you set in your DOM.
|
65
|
+
|
66
|
+
|
data/Rakefile
ADDED
data/ethereal.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ethereal/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jointjs"
|
8
|
+
spec.version = Ethereal::VERSION
|
9
|
+
spec.authors = ["Pier-Olivier Thibault"]
|
10
|
+
spec.email = ["pothibo@gmail.com"]
|
11
|
+
spec.summary = %q{Event based JavaScript framework tailored for Ruby on rails.}
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "rails", "~> 4.1"
|
22
|
+
spec.add_development_dependency "sqlite3"
|
23
|
+
end
|
data/lib/ethereal.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
@Ethereal = {
|
2
|
+
attributeName: 'as'
|
3
|
+
}
|
4
|
+
|
5
|
+
@Ethereal.isDOM = (el) ->
|
6
|
+
el instanceof HTMLDocument ||
|
7
|
+
el instanceof HTMLElement
|
8
|
+
|
9
|
+
listen = (e) ->
|
10
|
+
if e.type && e.type == 'DOMContentLoaded'
|
11
|
+
document.removeEventListener('DOMContentLoaded', listen)
|
12
|
+
|
13
|
+
Ethereal.Watcher(document, {
|
14
|
+
attributes: true,
|
15
|
+
subtree: true,
|
16
|
+
childList: true,
|
17
|
+
attributeFilter: [Ethereal.attributeName],
|
18
|
+
characterData: true
|
19
|
+
})
|
20
|
+
|
21
|
+
Ethereal.Watcher().inspect(document.body)
|
22
|
+
|
23
|
+
document.addEventListener 'submit', (e) ->
|
24
|
+
if e.target.getAttribute('disabled')? || e.target.dataset['remote'] != 'true'
|
25
|
+
return
|
26
|
+
|
27
|
+
Ethereal.XHR.Form(e.target)
|
28
|
+
|
29
|
+
e.preventDefault()
|
30
|
+
return false
|
31
|
+
|
32
|
+
document.addEventListener 'click', (e) ->
|
33
|
+
return unless e.target instanceof HTMLAnchorElement
|
34
|
+
|
35
|
+
if e.target.getAttribute('disabled')? || e.target.dataset['remote'] != 'true'
|
36
|
+
return
|
37
|
+
|
38
|
+
xhr = new Ethereal.XHR(e.target)
|
39
|
+
xhr.send(e.target.getAttribute('href'))
|
40
|
+
|
41
|
+
e.preventDefault()
|
42
|
+
return false
|
43
|
+
|
44
|
+
|
45
|
+
if document.readyState == 'complete'
|
46
|
+
listen()
|
47
|
+
else
|
48
|
+
document.addEventListener('DOMContentLoaded', listen)
|
49
|
+
|
50
|
+
|
51
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class God
|
2
|
+
update: (el) =>
|
3
|
+
model = el.getAttribute(Ethereal.attributeName)
|
4
|
+
if model?
|
5
|
+
@create(el, model)
|
6
|
+
else
|
7
|
+
@destroy(el)
|
8
|
+
|
9
|
+
create: (el) =>
|
10
|
+
model = el.getAttribute(Ethereal.attributeName)
|
11
|
+
if @modelExists(model)
|
12
|
+
el.instance = new Ethereal.Models.klass[model](el)
|
13
|
+
|
14
|
+
el.instance.element = ->
|
15
|
+
el
|
16
|
+
|
17
|
+
el.instance.on = (event, target, callback) ->
|
18
|
+
if callback?
|
19
|
+
el.instance.on.events.push([event, target, callback])
|
20
|
+
else
|
21
|
+
callback = target
|
22
|
+
target = el
|
23
|
+
target.addEventListener(event, callback)
|
24
|
+
|
25
|
+
el.instance.on.events = []
|
26
|
+
|
27
|
+
if el.instance.loaded?
|
28
|
+
el.instance.loaded()
|
29
|
+
|
30
|
+
else
|
31
|
+
throw "error: #{model} is not registered. Add your model with Ethereal.Models.add(#{model})"
|
32
|
+
|
33
|
+
destroy: (el) =>
|
34
|
+
el.instance.on.events?.forEach (event) ->
|
35
|
+
event[1].removeEventListener(event[0], event[2])
|
36
|
+
|
37
|
+
|
38
|
+
modelExists: (name) =>
|
39
|
+
Ethereal.Models.klass[name]?
|
40
|
+
|
41
|
+
|
42
|
+
Ethereal.God = new God
|
43
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
instance = undefined
|
2
|
+
|
3
|
+
class Watcher
|
4
|
+
constructor: (target, config = {}) ->
|
5
|
+
@observer = new MutationObserver(@observed)
|
6
|
+
@observer.observe(target, config)
|
7
|
+
|
8
|
+
observed: (mutations) =>
|
9
|
+
mutations.forEach (mutation) =>
|
10
|
+
if mutation.type == 'attributes'
|
11
|
+
Ethereal.God.update(target)
|
12
|
+
else
|
13
|
+
@add(mutation.addedNodes)
|
14
|
+
@destroy(mutation.removedNodes)
|
15
|
+
|
16
|
+
|
17
|
+
add: (nodes) =>
|
18
|
+
for node in nodes
|
19
|
+
continue unless Ethereal.isDOM(node)
|
20
|
+
if node.hasAttribute(Ethereal.attributeName)
|
21
|
+
Ethereal.God.create(node, node.getAttribute(Ethereal.attributeName))
|
22
|
+
|
23
|
+
for child in node.querySelectorAll("[#{Ethereal.attributeName}]")
|
24
|
+
Ethereal.God.create(child, child.getAttribute(Ethereal.attributeName))
|
25
|
+
|
26
|
+
destroy: (nodes) =>
|
27
|
+
for node in nodes
|
28
|
+
continue unless Ethereal.isDOM(node)
|
29
|
+
if node.hasAttribute(Ethereal.attributeName)
|
30
|
+
Ethereal.God.destroy(node)
|
31
|
+
|
32
|
+
for child in node.querySelectorAll("[#{Ethereal.attributeName}]")
|
33
|
+
Ethereal.God.destroy(child)
|
34
|
+
|
35
|
+
inspect: (node) ->
|
36
|
+
if Ethereal.isDOM(node)
|
37
|
+
found = node.querySelectorAll("[#{Ethereal.attributeName}]")
|
38
|
+
Ethereal.God.create(el) for el in found
|
39
|
+
|
40
|
+
# !! **************************************** !! #
|
41
|
+
|
42
|
+
Ethereal.Watcher = ->
|
43
|
+
unless instance?
|
44
|
+
i = 0
|
45
|
+
target = null
|
46
|
+
target = if Ethereal.isDOM(arguments[i]) then arguments[i++] else document
|
47
|
+
instance = new Watcher(target, arguments[i])
|
48
|
+
|
49
|
+
instance
|
50
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class XHR
|
2
|
+
script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
|
3
|
+
constructor: (el) ->
|
4
|
+
@element(el)
|
5
|
+
@request = new XMLHttpRequest()
|
6
|
+
@request.addEventListener('load', @completed)
|
7
|
+
|
8
|
+
|
9
|
+
element: (el) ->
|
10
|
+
@element = ->
|
11
|
+
el
|
12
|
+
|
13
|
+
completed: (e) =>
|
14
|
+
if e.target.responseText.length > 1
|
15
|
+
eval(e.target.responseText)(@element())
|
16
|
+
|
17
|
+
send: (src, method = 'GET', data) =>
|
18
|
+
@request.open(method, src)
|
19
|
+
@request.setRequestHeader('accept', "*/*;q=0.5, #{@script}")
|
20
|
+
@request.setRequestHeader('X-Requested-With', "XMLHttpRequest")
|
21
|
+
|
22
|
+
@request.send(data)
|
23
|
+
|
24
|
+
@Form: (element) =>
|
25
|
+
xhr = new XHR(element)
|
26
|
+
data = new FormData(element)
|
27
|
+
param = document.querySelector('meta[name=csrf-param]').getAttribute('content')
|
28
|
+
token = document.querySelector('meta[name=csrf-token]').getAttribute('content')
|
29
|
+
data.append(param, token)
|
30
|
+
xhr.send(element.getAttribute('action'), element.getAttribute('method'), data)
|
31
|
+
xhr
|
32
|
+
|
33
|
+
|
34
|
+
Ethereal.XHR = XHR
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Ethereal
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer 'ethereal.assets.paths', before: :add_view_paths do |app|
|
4
|
+
app.paths['vendor/assets'] << File.dirname(__FILE__) + '/app/assets/'
|
5
|
+
app.paths['app/views'] << File.dirname(__FILE__) + '/app/views/'
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
data/test/application.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class PathsTest < ActiveSupport::TestCase
|
2
|
+
test "assets are in path" do
|
3
|
+
app = Rails.application
|
4
|
+
assets = app.paths['vendor/assets'].to_ary
|
5
|
+
paths = assets.select do |p|
|
6
|
+
p[/ethereal/]
|
7
|
+
end
|
8
|
+
|
9
|
+
assert(!paths.nil?, "Couldn't find path in assets")
|
10
|
+
assert(paths.any?, "Couldn't find path in assets")
|
11
|
+
end
|
12
|
+
|
13
|
+
test "views are in path" do
|
14
|
+
app = Rails.application
|
15
|
+
assets = app.paths['app/views'].to_ary
|
16
|
+
paths = assets.select do |p|
|
17
|
+
p[/ethereal/]
|
18
|
+
end
|
19
|
+
|
20
|
+
assert(!paths.nil?, "Couldn't find path in views")
|
21
|
+
assert(paths.any?, "Couldn't find path in views")
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/test/js/base.js
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
2
|
+
(function() {
|
3
|
+
var listen;
|
4
|
+
|
5
|
+
this.Shiny = {
|
6
|
+
attributeName: 'as'
|
7
|
+
};
|
8
|
+
|
9
|
+
this.Shiny.isDOM = function(el) {
|
10
|
+
return el instanceof HTMLDocument || el instanceof HTMLElement;
|
11
|
+
};
|
12
|
+
|
13
|
+
listen = function(e) {
|
14
|
+
if (e.type && e.type === 'DOMContentLoaded') {
|
15
|
+
document.removeEventListener('DOMContentLoaded', listen);
|
16
|
+
}
|
17
|
+
Shiny.Watcher(document, {
|
18
|
+
attributes: true,
|
19
|
+
subtree: true,
|
20
|
+
childList: true,
|
21
|
+
attributeFilter: [Shiny.attributeName],
|
22
|
+
characterData: true
|
23
|
+
});
|
24
|
+
return Shiny.Watcher().inspect(document.body);
|
25
|
+
};
|
26
|
+
|
27
|
+
if (document.readyState === 'complete') {
|
28
|
+
listen();
|
29
|
+
} else {
|
30
|
+
document.addEventListener('DOMContentLoaded', listen);
|
31
|
+
}
|
32
|
+
|
33
|
+
}).call(this);
|
data/test/js/god.js
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
2
|
+
(function() {
|
3
|
+
var God,
|
4
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
5
|
+
|
6
|
+
God = (function() {
|
7
|
+
function God() {
|
8
|
+
this.modelExists = __bind(this.modelExists, this);
|
9
|
+
this.destroy = __bind(this.destroy, this);
|
10
|
+
this.create = __bind(this.create, this);
|
11
|
+
this.update = __bind(this.update, this);
|
12
|
+
}
|
13
|
+
|
14
|
+
God.prototype.update = function(el) {
|
15
|
+
var model;
|
16
|
+
model = el.getAttribute(Shiny.attributeName);
|
17
|
+
if (model != null) {
|
18
|
+
return this.create(el, model);
|
19
|
+
} else {
|
20
|
+
return this.destroy(el);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
|
24
|
+
God.prototype.create = function(el) {
|
25
|
+
var model;
|
26
|
+
model = el.getAttribute(Shiny.attributeName);
|
27
|
+
if (this.modelExists(model)) {
|
28
|
+
el.instance = new Shiny.Models.klass[model](el);
|
29
|
+
el.instance.element = function() {
|
30
|
+
return el;
|
31
|
+
};
|
32
|
+
el.instance.on = function(event, target, callback) {
|
33
|
+
if (callback != null) {
|
34
|
+
el.instance.on.events.push([event, target, callback]);
|
35
|
+
} else {
|
36
|
+
callback = target;
|
37
|
+
target = el;
|
38
|
+
}
|
39
|
+
return target.addEventListener(event, callback);
|
40
|
+
};
|
41
|
+
el.instance.on.events = [];
|
42
|
+
if (el.instance.loaded != null) {
|
43
|
+
return el.instance.loaded();
|
44
|
+
}
|
45
|
+
} else {
|
46
|
+
throw "error: " + model + " is not registered. Add your model with Shiny.Models.add(" + model + ")";
|
47
|
+
}
|
48
|
+
};
|
49
|
+
|
50
|
+
God.prototype.destroy = function(el) {
|
51
|
+
var _ref;
|
52
|
+
return (_ref = el.instance.on.events) != null ? _ref.forEach(function(event) {
|
53
|
+
return event[1].removeEventListener(event[0], event[2]);
|
54
|
+
}) : void 0;
|
55
|
+
};
|
56
|
+
|
57
|
+
God.prototype.modelExists = function(name) {
|
58
|
+
return Shiny.Models.klass[name] != null;
|
59
|
+
};
|
60
|
+
|
61
|
+
return God;
|
62
|
+
|
63
|
+
})();
|
64
|
+
|
65
|
+
Shiny.God = new God;
|
66
|
+
|
67
|
+
}).call(this);
|
data/test/js/list.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
(function() {
|
2
|
+
|
3
|
+
function List() {
|
4
|
+
|
5
|
+
this.loaded = function() {
|
6
|
+
|
7
|
+
this.on('click', this.remove)
|
8
|
+
this.on('click', document, this.hello)
|
9
|
+
}
|
10
|
+
|
11
|
+
this.remove = function() {
|
12
|
+
this.remove()
|
13
|
+
}
|
14
|
+
|
15
|
+
this.hello = function() {
|
16
|
+
console.log('hello')
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
Shiny.Models.add(List, "List")
|
21
|
+
})()
|
data/test/js/models.js
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
2
|
+
(function() {
|
3
|
+
var Models;
|
4
|
+
|
5
|
+
Models = (function() {
|
6
|
+
function Models() {}
|
7
|
+
|
8
|
+
Models.prototype.klass = {};
|
9
|
+
|
10
|
+
Models.prototype.add = function(kls, name) {
|
11
|
+
if (name == null) {
|
12
|
+
name = kls.name;
|
13
|
+
}
|
14
|
+
return this.klass[name] = kls;
|
15
|
+
};
|
16
|
+
|
17
|
+
return Models;
|
18
|
+
|
19
|
+
})();
|
20
|
+
|
21
|
+
Shiny.Models = new Models;
|
22
|
+
|
23
|
+
}).call(this);
|
data/test/js/watcher.js
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
2
|
+
(function() {
|
3
|
+
var Watcher, instance,
|
4
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
5
|
+
|
6
|
+
instance = void 0;
|
7
|
+
|
8
|
+
Watcher = (function() {
|
9
|
+
function Watcher(target, config) {
|
10
|
+
if (config == null) {
|
11
|
+
config = {};
|
12
|
+
}
|
13
|
+
this.destroy = __bind(this.destroy, this);
|
14
|
+
this.add = __bind(this.add, this);
|
15
|
+
this.observed = __bind(this.observed, this);
|
16
|
+
this.observer = new MutationObserver(this.observed);
|
17
|
+
this.observer.observe(target, config);
|
18
|
+
}
|
19
|
+
|
20
|
+
Watcher.prototype.observed = function(mutations) {
|
21
|
+
var _this = this;
|
22
|
+
return mutations.forEach(function(mutation) {
|
23
|
+
if (mutation.type === 'attributes') {
|
24
|
+
return Shiny.God.update(target);
|
25
|
+
} else {
|
26
|
+
_this.add(mutation.addedNodes);
|
27
|
+
return _this.destroy(mutation.removedNodes);
|
28
|
+
}
|
29
|
+
});
|
30
|
+
};
|
31
|
+
|
32
|
+
Watcher.prototype.add = function(nodes) {
|
33
|
+
var child, node, _i, _len, _results;
|
34
|
+
_results = [];
|
35
|
+
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
|
36
|
+
node = nodes[_i];
|
37
|
+
if (!Shiny.isDOM(node)) {
|
38
|
+
continue;
|
39
|
+
}
|
40
|
+
if (node.hasAttribute(Shiny.attributeName)) {
|
41
|
+
Shiny.God.create(node, node.getAttribute(Shiny.attributeName));
|
42
|
+
}
|
43
|
+
_results.push((function() {
|
44
|
+
var _j, _len1, _ref, _results1;
|
45
|
+
_ref = node.querySelectorAll("[" + Shiny.attributeName + "]");
|
46
|
+
_results1 = [];
|
47
|
+
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
48
|
+
child = _ref[_j];
|
49
|
+
_results1.push(Shiny.God.create(child, child.getAttribute(Shiny.attributeName)));
|
50
|
+
}
|
51
|
+
return _results1;
|
52
|
+
})());
|
53
|
+
}
|
54
|
+
return _results;
|
55
|
+
};
|
56
|
+
|
57
|
+
Watcher.prototype.destroy = function(nodes) {
|
58
|
+
var child, node, _i, _len, _results;
|
59
|
+
_results = [];
|
60
|
+
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
|
61
|
+
node = nodes[_i];
|
62
|
+
if (!Shiny.isDOM(node)) {
|
63
|
+
continue;
|
64
|
+
}
|
65
|
+
if (node.hasAttribute(Shiny.attributeName)) {
|
66
|
+
Shiny.God.destroy(node);
|
67
|
+
}
|
68
|
+
_results.push((function() {
|
69
|
+
var _j, _len1, _ref, _results1;
|
70
|
+
_ref = node.querySelectorAll("[" + Shiny.attributeName + "]");
|
71
|
+
_results1 = [];
|
72
|
+
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
|
73
|
+
child = _ref[_j];
|
74
|
+
_results1.push(Shiny.God.destroy(child));
|
75
|
+
}
|
76
|
+
return _results1;
|
77
|
+
})());
|
78
|
+
}
|
79
|
+
return _results;
|
80
|
+
};
|
81
|
+
|
82
|
+
Watcher.prototype.inspect = function(node) {
|
83
|
+
var el, found, _i, _len, _results;
|
84
|
+
if (Shiny.isDOM(node)) {
|
85
|
+
found = node.querySelectorAll("[" + Shiny.attributeName + "]");
|
86
|
+
_results = [];
|
87
|
+
for (_i = 0, _len = found.length; _i < _len; _i++) {
|
88
|
+
el = found[_i];
|
89
|
+
_results.push(Shiny.God.create(el));
|
90
|
+
}
|
91
|
+
return _results;
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
return Watcher;
|
96
|
+
|
97
|
+
})();
|
98
|
+
|
99
|
+
Shiny.Watcher = function() {
|
100
|
+
var i, target;
|
101
|
+
if (instance == null) {
|
102
|
+
i = 0;
|
103
|
+
target = null;
|
104
|
+
target = Shiny.isDOM(arguments[i]) ? arguments[i++] : document;
|
105
|
+
instance = new Watcher(target, arguments[i]);
|
106
|
+
}
|
107
|
+
return instance;
|
108
|
+
};
|
109
|
+
|
110
|
+
}).call(this);
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# The order of this file is important as some requirements execute ruby code automatically.
|
2
|
+
|
3
|
+
ENV['RAILS_ENV'] ||= 'test'
|
4
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
5
|
+
|
6
|
+
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
7
|
+
require_relative 'application'
|
8
|
+
|
9
|
+
Ethereal::Application.initialize!
|
10
|
+
|
11
|
+
require 'rails/test_help'
|
12
|
+
|
13
|
+
class ActiveSupport::TestCase
|
14
|
+
end
|
15
|
+
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jointjs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pier-Olivier Thibault
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- pothibo@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- ethereal.gemspec
|
82
|
+
- lib/ethereal.rb
|
83
|
+
- lib/ethereal/app/assets/javascripts/ethereal.js.coffee
|
84
|
+
- lib/ethereal/app/assets/javascripts/ethereal/base.js.coffee
|
85
|
+
- lib/ethereal/app/assets/javascripts/ethereal/ext.js.coffee
|
86
|
+
- lib/ethereal/app/assets/javascripts/ethereal/god.js.coffee
|
87
|
+
- lib/ethereal/app/assets/javascripts/ethereal/model.js.coffee
|
88
|
+
- lib/ethereal/app/assets/javascripts/ethereal/watcher.js.coffee
|
89
|
+
- lib/ethereal/app/assets/javascripts/ethereal/xhr.js.coffee
|
90
|
+
- lib/ethereal/app/views/layouts/application.js.erb
|
91
|
+
- lib/ethereal/railtie.rb
|
92
|
+
- lib/ethereal/version.rb
|
93
|
+
- test/application.rb
|
94
|
+
- test/config/database.yml
|
95
|
+
- test/integration/load_test.rb
|
96
|
+
- test/js/base.js
|
97
|
+
- test/js/god.js
|
98
|
+
- test/js/list.js
|
99
|
+
- test/js/models.js
|
100
|
+
- test/js/watcher.js
|
101
|
+
- test/test_helper.rb
|
102
|
+
homepage:
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Event based JavaScript framework tailored for Ruby on rails.
|
126
|
+
test_files:
|
127
|
+
- test/application.rb
|
128
|
+
- test/config/database.yml
|
129
|
+
- test/integration/load_test.rb
|
130
|
+
- test/js/base.js
|
131
|
+
- test/js/god.js
|
132
|
+
- test/js/list.js
|
133
|
+
- test/js/models.js
|
134
|
+
- test/js/watcher.js
|
135
|
+
- test/test_helper.rb
|