jointjs 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Rakefile +2 -3
  4. data/{ethereal.gemspec → jointjs.gemspec} +2 -2
  5. data/lib/jointjs.rb +5 -0
  6. data/lib/jointjs/app/assets/javascripts/joint.js.coffee +12 -0
  7. data/lib/jointjs/app/assets/javascripts/joint/base.js.coffee +18 -0
  8. data/lib/{ethereal/app/assets/javascripts/ethereal/god.js.coffee → jointjs/app/assets/javascripts/joint/creator.js.coffee} +8 -13
  9. data/lib/{ethereal/app/assets/javascripts/ethereal → jointjs/app/assets/javascripts/joint}/ext.js.coffee +0 -0
  10. data/lib/jointjs/app/assets/javascripts/joint/watcher.js.coffee +49 -0
  11. data/lib/jointjs/app/assets/javascripts/joint/xhr.js.coffee +110 -0
  12. data/lib/{ethereal → jointjs}/app/views/layouts/application.js.erb +0 -0
  13. data/lib/{ethereal → jointjs}/railtie.rb +2 -2
  14. data/lib/jointjs/version.rb +3 -0
  15. data/test/Gemfile +27 -0
  16. data/test/Gemfile.lock +164 -0
  17. data/test/README.rdoc +28 -0
  18. data/test/Rakefile +6 -0
  19. data/test/app/assets/javascripts/application.js +4 -0
  20. data/test/app/assets/javascripts/item.js.coffee +2 -0
  21. data/test/app/assets/javascripts/list.js.coffee +6 -0
  22. data/test/app/assets/javascripts/tests/instances.js.coffee +17 -0
  23. data/test/app/assets/javascripts/tests/xhr.js.coffee +20 -0
  24. data/test/app/controllers/todos_controller.rb +18 -0
  25. data/test/app/models/todo.rb +2 -0
  26. data/test/app/views/layouts/application.html.erb +16 -0
  27. data/test/app/views/todos/_todo.html.erb +1 -0
  28. data/test/app/views/todos/create.js.erb +1 -0
  29. data/test/app/views/todos/index.html.erb +11 -0
  30. data/test/bin/bundle +3 -0
  31. data/test/bin/rails +8 -0
  32. data/test/bin/rake +8 -0
  33. data/test/bin/setup +29 -0
  34. data/test/bin/spring +18 -0
  35. data/test/config.ru +4 -0
  36. data/test/config/application.rb +26 -0
  37. data/test/config/boot.rb +3 -0
  38. data/test/config/database.yml +8 -2
  39. data/test/config/environment.rb +5 -0
  40. data/test/config/environments/development.rb +41 -0
  41. data/test/config/environments/production.rb +79 -0
  42. data/test/config/environments/test.rb +42 -0
  43. data/test/config/initializers/assets.rb +11 -0
  44. data/test/config/initializers/backtrace_silencers.rb +7 -0
  45. data/test/config/initializers/cookies_serializer.rb +3 -0
  46. data/test/config/initializers/filter_parameter_logging.rb +4 -0
  47. data/test/config/initializers/inflections.rb +16 -0
  48. data/test/config/initializers/mime_types.rb +4 -0
  49. data/test/config/initializers/session_store.rb +3 -0
  50. data/test/config/initializers/wrap_parameters.rb +14 -0
  51. data/test/config/locales/en.yml +23 -0
  52. data/test/config/routes.rb +4 -0
  53. data/test/config/secrets.yml +2 -0
  54. data/test/db/joint_test +0 -0
  55. data/test/db/migrate/20150106151240_create_todos.rb +9 -0
  56. data/test/db/schema.rb +22 -0
  57. data/test/db/seeds.rb +1 -0
  58. metadata +97 -28
  59. data/lib/ethereal.rb +0 -5
  60. data/lib/ethereal/app/assets/javascripts/ethereal.js.coffee +0 -6
  61. data/lib/ethereal/app/assets/javascripts/ethereal/base.js.coffee +0 -51
  62. data/lib/ethereal/app/assets/javascripts/ethereal/model.js.coffee +0 -8
  63. data/lib/ethereal/app/assets/javascripts/ethereal/watcher.js.coffee +0 -50
  64. data/lib/ethereal/app/assets/javascripts/ethereal/xhr.js.coffee +0 -34
  65. data/lib/ethereal/version.rb +0 -3
  66. data/test/application.rb +0 -11
  67. data/test/js/base.js +0 -33
  68. data/test/js/god.js +0 -67
  69. data/test/js/list.js +0 -21
  70. data/test/js/models.js +0 -23
  71. data/test/js/watcher.js +0 -110
  72. data/test/test_helper.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02aa4d86af26c37f22af7d0d5b37dd45afc38003
4
- data.tar.gz: f4a8921aa06e7fa7e5ea0e9977e2f645e2c216cc
3
+ metadata.gz: f81115aa1ce8a93aa1629486dd6a6f9c7fe5192b
4
+ data.tar.gz: e379c48042f370eae737ed535d1dab71afe08aee
5
5
  SHA512:
6
- metadata.gz: 1bf513ca071257ec05d0909cdea4d078cab624589fc03816d781b6bcaf70601b714ac563c6fdf632ecc35d3124823908c23c9cbb389e23067bd3b2345faac1ea
7
- data.tar.gz: 9f32ce523cd077fc836752c53a379194a4c582552694df32fffbaa4c65620aecf6b57dc36ea6d7b203d0ebedb55fe8480cab3db10517e01e3aaf4d7b3109df2e
6
+ metadata.gz: 6dabe31450383d3a69b87cbe490d07ae46d6f01927df7404f812d8b1af2580511fa78a44c5f5836b0a74e9b4a526bb1c67a09d3342326504fc03220b278e159d
7
+ data.tar.gz: bfce9aebd8a14f896baf57625a379c602cf0628844936cd604c647ff509cba2d5e99e4f445b9355b89e7fbfd8f9a58e4f150187ceee05762c439f1b4cefa1fc9
data/.gitignore CHANGED
@@ -6,7 +6,8 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
- /tmp/
9
+ tmp
10
+ *.gem
10
11
  *.bundle
11
12
  *.so
12
13
  *.o
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- require "bundler/gem_tasks"
2
- require_relative "test/test_helper"
1
+ require File.expand_path('../test/application', __FILE__)
3
2
 
4
- Ethereal::Application.load_tasks
3
+ JointTest::Application.load_tasks
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ethereal/version'
4
+ require 'jointjs/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "jointjs"
8
- spec.version = Ethereal::VERSION
8
+ spec.version = JointJS::VERSION
9
9
  spec.authors = ["Pier-Olivier Thibault"]
10
10
  spec.email = ["pothibo@gmail.com"]
11
11
  spec.summary = %q{Event based JavaScript framework tailored for Ruby on rails.}
data/lib/jointjs.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "jointjs/version"
2
+
3
+ module JointJS
4
+ require 'jointjs/railtie'
5
+ end
@@ -0,0 +1,12 @@
1
+ #= require 'joint/ext'
2
+ #= require 'joint/base'
3
+ #= require 'joint/watcher'
4
+ #= require 'joint/creator'
5
+ #= require 'joint/xhr'
6
+
7
+ if document.readyState == 'complete'
8
+ window.Joint.initialize()
9
+ else
10
+ document.addEventListener 'DOMContentLoaded', ->
11
+ window.Joint.initialize()
12
+
@@ -0,0 +1,18 @@
1
+ class Joint
2
+ attributeName: 'as'
3
+
4
+ constructor: ->
5
+ @cache = {}
6
+
7
+ initialize: =>
8
+ event = new CustomEvent('joint:loaded')
9
+ document.dispatchEvent(event)
10
+
11
+ isDOM: (el) ->
12
+ el instanceof HTMLDocument ||
13
+ el instanceof HTMLElement
14
+
15
+ bind: (name, kls) =>
16
+ @cache[name] = kls
17
+
18
+ window.Joint = new Joint()
@@ -1,15 +1,16 @@
1
- class God
1
+ class Creator
2
+
2
3
  update: (el) =>
3
- model = el.getAttribute(Ethereal.attributeName)
4
+ model = el.getAttribute(Joint.attributeName)
4
5
  if model?
5
6
  @create(el, model)
6
7
  else
7
8
  @destroy(el)
8
9
 
9
10
  create: (el) =>
10
- model = el.getAttribute(Ethereal.attributeName)
11
- if @modelExists(model)
12
- el.instance = new Ethereal.Models.klass[model](el)
11
+ model = el.getAttribute(Joint.attributeName)
12
+ if Joint.cache[model]?
13
+ el.instance = new Joint.cache[model](el)
13
14
 
14
15
  el.instance.element = ->
15
16
  el
@@ -28,16 +29,10 @@ class God
28
29
  el.instance.loaded()
29
30
 
30
31
  else
31
- throw "error: #{model} is not registered. Add your model with Ethereal.Models.add(#{model})"
32
+ throw "error: #{model} is not registered. Add your model with Joint.Models.add(#{model})"
32
33
 
33
34
  destroy: (el) =>
34
35
  el.instance.on.events?.forEach (event) ->
35
36
  event[1].removeEventListener(event[0], event[2])
36
37
 
37
-
38
- modelExists: (name) =>
39
- Ethereal.Models.klass[name]?
40
-
41
-
42
- Ethereal.God = new God
43
-
38
+ @Joint.Creator = new Creator()
@@ -0,0 +1,49 @@
1
+ class Watcher
2
+ constructor: ->
3
+ document.addEventListener('joint:loaded', @start)
4
+
5
+ start: =>
6
+ @observer = new MutationObserver(@observed)
7
+ @observer.observe(document, {
8
+ attributes: true,
9
+ subtree: true,
10
+ childList: true,
11
+ attributeFilter: [Joint.attributeName],
12
+ characterData: true
13
+ })
14
+
15
+ @inspect(document)
16
+
17
+ observed: (mutations) =>
18
+ mutations.forEach (mutation) =>
19
+ if mutation.type == 'attributes'
20
+ Joint.Creator.update(target)
21
+ else
22
+ @add(mutation.addedNodes)
23
+ @destroy(mutation.removedNodes)
24
+
25
+
26
+ add: (nodes) =>
27
+ for node in nodes
28
+ continue unless Joint.isDOM(node)
29
+ if node.hasAttribute(Joint.attributeName)
30
+ Joint.Creator.create(node, node.getAttribute(Joint.attributeName))
31
+
32
+ for child in node.querySelectorAll("[#{Joint.attributeName}]")
33
+ Joint.Creator.create(child, child.getAttribute(Joint.attributeName))
34
+
35
+ destroy: (nodes) =>
36
+ for node in nodes
37
+ continue unless Joint.isDOM(node)
38
+ if node.hasAttribute(Joint.attributeName)
39
+ Joint.Creator.destroy(node)
40
+
41
+ for child in node.querySelectorAll("[#{Joint.attributeName}]")
42
+ Joint.Creator.destroy(child)
43
+
44
+ inspect: (node) ->
45
+ if Joint.isDOM(node)
46
+ found = node.querySelectorAll("[#{Joint.attributeName}]")
47
+ Joint.Creator.create(el) for el in found
48
+
49
+ @Joint.Watcher = new Watcher()
@@ -0,0 +1,110 @@
1
+ class XHRData
2
+ constructor: (el) ->
3
+ @backend = {}
4
+ if el instanceof HTMLFormElement
5
+ @form = el
6
+
7
+ set: (k, v) =>
8
+ @backend[k] = v
9
+ @keys().push(k)
10
+
11
+ value: (k) =>
12
+ @backend[k]
13
+
14
+ has: (k) =>
15
+ @backend[k]?
16
+
17
+ keys: =>
18
+ store = []
19
+ fn = ->
20
+ store
21
+ @keys = fn
22
+ fn()
23
+
24
+ any: =>
25
+ @keys().length > 0
26
+
27
+ serialize: =>
28
+ formData = new FormData(@form)
29
+ for key in @keys()
30
+ formData.append key, @value(key)
31
+
32
+ formData
33
+
34
+ class XHR
35
+ script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
36
+
37
+ @completed: (e) ->
38
+ if e.target.responseText.length > 1
39
+ eval(e.target.responseText)(e.target.element)
40
+
41
+ @send: (el) ->
42
+
43
+ xhr = new XHR(el)
44
+ xhr.send()
45
+ xhr
46
+
47
+ constructor: (el) ->
48
+ @data = new XHRData(el)
49
+ @request = new XMLHttpRequest()
50
+ @request.element = el
51
+ @request.addEventListener 'load', XHR.completed
52
+
53
+ @method = el.getAttribute('method') || 'GET'
54
+
55
+ send: =>
56
+ action = @request.element.getAttribute('action') || @request.element.getAttribute('href')
57
+
58
+ unless action?
59
+ throw "Cannot send a request to the server if the element isn't a Form or if the element doesn't have the HREF attributes: <div href>"
60
+ return
61
+
62
+ if @method == 'GET' && @data.any()
63
+ parser = document.createElement('a')
64
+ parser.href = action
65
+ params = parser.search.substring(1).split('&')
66
+
67
+ for key in @data.keys()
68
+ params.push "#{key}=#{@data.value(key)}"
69
+
70
+ parser.search = "?#{params.join("&")}"
71
+
72
+ action = parser.href
73
+
74
+ @request.open @method, action
75
+ @request.setRequestHeader 'accept', "*/*;q=0.5, #{@script}"
76
+ @request.setRequestHeader 'X-Requested-With', "XMLHttpRequest"
77
+
78
+ if @method != 'GET'
79
+ token = document.querySelector('meta[name=csrf-token]').getAttribute('content')
80
+ @request.setRequestHeader 'X-CSRF-Token', token
81
+
82
+ @request.send(@data.serialize())
83
+
84
+
85
+ Joint.XHR = XHR
86
+
87
+ document.addEventListener 'submit', (e) =>
88
+ if e.target.getAttribute('disabled')? || e.target.dataset['remote'] != 'true'
89
+ return
90
+
91
+ XHR.send(e.target)
92
+
93
+ e.preventDefault()
94
+ return false
95
+
96
+ document.addEventListener 'click', (e) =>
97
+ el = e.target
98
+ while el? && !(el instanceof HTMLAnchorElement)
99
+ el = el.parentElement
100
+
101
+ return unless el?
102
+
103
+ if el.getAttribute('disabled')? || el.dataset['remote'] != 'true'
104
+ return
105
+
106
+ XHR.send(el)
107
+
108
+ e.preventDefault()
109
+ return false
110
+
@@ -1,6 +1,6 @@
1
- module Ethereal
1
+ module JointJS
2
2
  class Railtie < Rails::Railtie
3
- initializer 'ethereal.assets.paths', before: :add_view_paths do |app|
3
+ initializer 'joint.assets.paths', before: :add_view_paths do |app|
4
4
  app.paths['vendor/assets'] << File.dirname(__FILE__) + '/app/assets/'
5
5
  app.paths['app/views'] << File.dirname(__FILE__) + '/app/views/'
6
6
  end
@@ -0,0 +1,3 @@
1
+ module JointJS
2
+ VERSION = "0.0.4"
3
+ end
data/test/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ gem 'rails', '4.2.0'
5
+ gem 'sqlite3'
6
+ gem 'sass-rails', '~> 5.0'
7
+ gem 'uglifier', '>= 1.3.0'
8
+ gem 'coffee-rails', '~> 4.1.0'
9
+ gem 'jquery-rails'
10
+ gem 'turbolinks'
11
+ gem 'jbuilder', '~> 2.0'
12
+
13
+ path = Pathname.new(__FILE__) + '..'
14
+
15
+ gem 'jointjs', path: path.dirname
16
+
17
+ group :development, :test do
18
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
19
+ gem 'byebug'
20
+
21
+ # Access an IRB console on exception pages or by using <%= console %> in views
22
+ gem 'web-console', '~> 2.0'
23
+
24
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
25
+ gem 'spring'
26
+ end
27
+
data/test/Gemfile.lock ADDED
@@ -0,0 +1,164 @@
1
+ PATH
2
+ remote: /Users/pothibo/Develop/jointjs
3
+ specs:
4
+ jointjs (0.0.4)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionmailer (4.2.0)
10
+ actionpack (= 4.2.0)
11
+ actionview (= 4.2.0)
12
+ activejob (= 4.2.0)
13
+ mail (~> 2.5, >= 2.5.4)
14
+ rails-dom-testing (~> 1.0, >= 1.0.5)
15
+ actionpack (4.2.0)
16
+ actionview (= 4.2.0)
17
+ activesupport (= 4.2.0)
18
+ rack (~> 1.6.0)
19
+ rack-test (~> 0.6.2)
20
+ rails-dom-testing (~> 1.0, >= 1.0.5)
21
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
22
+ actionview (4.2.0)
23
+ activesupport (= 4.2.0)
24
+ builder (~> 3.1)
25
+ erubis (~> 2.7.0)
26
+ rails-dom-testing (~> 1.0, >= 1.0.5)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
28
+ activejob (4.2.0)
29
+ activesupport (= 4.2.0)
30
+ globalid (>= 0.3.0)
31
+ activemodel (4.2.0)
32
+ activesupport (= 4.2.0)
33
+ builder (~> 3.1)
34
+ activerecord (4.2.0)
35
+ activemodel (= 4.2.0)
36
+ activesupport (= 4.2.0)
37
+ arel (~> 6.0)
38
+ activesupport (4.2.0)
39
+ i18n (~> 0.7)
40
+ json (~> 1.7, >= 1.7.7)
41
+ minitest (~> 5.1)
42
+ thread_safe (~> 0.3, >= 0.3.4)
43
+ tzinfo (~> 1.1)
44
+ arel (6.0.0)
45
+ binding_of_caller (0.7.2)
46
+ debug_inspector (>= 0.0.1)
47
+ builder (3.2.2)
48
+ byebug (3.5.1)
49
+ columnize (~> 0.8)
50
+ debugger-linecache (~> 1.2)
51
+ slop (~> 3.6)
52
+ coffee-rails (4.1.0)
53
+ coffee-script (>= 2.2.0)
54
+ railties (>= 4.0.0, < 5.0)
55
+ coffee-script (2.3.0)
56
+ coffee-script-source
57
+ execjs
58
+ coffee-script-source (1.8.0)
59
+ columnize (0.9.0)
60
+ debug_inspector (0.0.2)
61
+ debugger-linecache (1.2.0)
62
+ erubis (2.7.0)
63
+ execjs (2.2.2)
64
+ globalid (0.3.0)
65
+ activesupport (>= 4.1.0)
66
+ hike (1.2.3)
67
+ i18n (0.7.0)
68
+ jbuilder (2.2.6)
69
+ activesupport (>= 3.0.0, < 5)
70
+ multi_json (~> 1.2)
71
+ jquery-rails (4.0.3)
72
+ rails-dom-testing (~> 1.0)
73
+ railties (>= 4.2.0)
74
+ thor (>= 0.14, < 2.0)
75
+ json (1.8.1)
76
+ loofah (2.0.1)
77
+ nokogiri (>= 1.5.9)
78
+ mail (2.6.3)
79
+ mime-types (>= 1.16, < 3)
80
+ mime-types (2.4.3)
81
+ mini_portile (0.6.2)
82
+ minitest (5.5.0)
83
+ multi_json (1.10.1)
84
+ nokogiri (1.6.5)
85
+ mini_portile (~> 0.6.0)
86
+ rack (1.6.0)
87
+ rack-test (0.6.2)
88
+ rack (>= 1.0)
89
+ rails (4.2.0)
90
+ actionmailer (= 4.2.0)
91
+ actionpack (= 4.2.0)
92
+ actionview (= 4.2.0)
93
+ activejob (= 4.2.0)
94
+ activemodel (= 4.2.0)
95
+ activerecord (= 4.2.0)
96
+ activesupport (= 4.2.0)
97
+ bundler (>= 1.3.0, < 2.0)
98
+ railties (= 4.2.0)
99
+ sprockets-rails
100
+ rails-deprecated_sanitizer (1.0.3)
101
+ activesupport (>= 4.2.0.alpha)
102
+ rails-dom-testing (1.0.5)
103
+ activesupport (>= 4.2.0.beta, < 5.0)
104
+ nokogiri (~> 1.6.0)
105
+ rails-deprecated_sanitizer (>= 1.0.1)
106
+ rails-html-sanitizer (1.0.1)
107
+ loofah (~> 2.0)
108
+ railties (4.2.0)
109
+ actionpack (= 4.2.0)
110
+ activesupport (= 4.2.0)
111
+ rake (>= 0.8.7)
112
+ thor (>= 0.18.1, < 2.0)
113
+ rake (10.4.2)
114
+ sass (3.4.9)
115
+ sass-rails (5.0.1)
116
+ railties (>= 4.0.0, < 5.0)
117
+ sass (~> 3.1)
118
+ sprockets (>= 2.8, < 4.0)
119
+ sprockets-rails (>= 2.0, < 4.0)
120
+ tilt (~> 1.1)
121
+ slop (3.6.0)
122
+ spring (1.2.0)
123
+ sprockets (2.12.3)
124
+ hike (~> 1.2)
125
+ multi_json (~> 1.0)
126
+ rack (~> 1.0)
127
+ tilt (~> 1.1, != 1.3.0)
128
+ sprockets-rails (2.2.2)
129
+ actionpack (>= 3.0)
130
+ activesupport (>= 3.0)
131
+ sprockets (>= 2.8, < 4.0)
132
+ sqlite3 (1.3.10)
133
+ thor (0.19.1)
134
+ thread_safe (0.3.4)
135
+ tilt (1.4.1)
136
+ turbolinks (2.5.3)
137
+ coffee-rails
138
+ tzinfo (1.2.2)
139
+ thread_safe (~> 0.1)
140
+ uglifier (2.6.1)
141
+ execjs (>= 0.3.0)
142
+ json (>= 1.8.0)
143
+ web-console (2.0.0)
144
+ activemodel (~> 4.0)
145
+ binding_of_caller (>= 0.7.2)
146
+ railties (~> 4.0)
147
+ sprockets-rails (>= 2.0, < 4.0)
148
+
149
+ PLATFORMS
150
+ ruby
151
+
152
+ DEPENDENCIES
153
+ byebug
154
+ coffee-rails (~> 4.1.0)
155
+ jbuilder (~> 2.0)
156
+ jointjs!
157
+ jquery-rails
158
+ rails (= 4.2.0)
159
+ sass-rails (~> 5.0)
160
+ spring
161
+ sqlite3
162
+ turbolinks
163
+ uglifier (>= 1.3.0)
164
+ web-console (~> 2.0)