fron 0.1.2 → 0.1.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fron/version.rb +1 -1
- data/opal/fron.rb +1 -0
- data/opal/fron/core-ext.rb +5 -0
- data/opal/fron/core-ext/hash.rb +14 -0
- data/opal/fron/core-ext/kernel.rb +10 -0
- data/opal/fron/core-ext/numeric.rb +9 -0
- data/opal/fron/core-ext/proc.rb +9 -0
- data/opal/fron/core-ext/string.rb +7 -0
- data/opal/fron/core/adapters/local.rb +4 -3
- data/opal/fron/core/adapters/rails.rb +24 -8
- data/opal/fron/core/configuration.rb +5 -1
- data/opal/fron/core/eventable.rb +3 -3
- data/opal/fron/core/model.rb +25 -5
- data/opal/fron/core/router.rb +12 -7
- data/opal/fron/dom.rb +1 -0
- data/opal/fron/dom/document.rb +6 -2
- data/opal/fron/dom/element.rb +16 -4
- data/opal/fron/dom/event.rb +115 -0
- data/opal/fron/dom/file-reader.rb +14 -0
- data/opal/fron/dom/modules/events.rb +27 -16
- data/opal/fron/dom/node.rb +6 -1
- data/opal/fron/request.rb +0 -1
- data/spec/core/adapter/local_spec.rb +6 -6
- data/spec/core/adapter/rails_spec.rb +11 -6
- data/spec/core/model_spec.rb +4 -4
- data/spec/core/router_spec.rb +2 -5
- data/spec/dom/event_spec.rb +1 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c8bd754f6372347b316b3fd740d149d0ae7c161
|
4
|
+
data.tar.gz: fd0f5c90f5555e54bee2643663ec94aab3932753
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c592e4dd96a7653a6bd58a0f36766fe46be4b67483bf2bd5b5cc7fb391f056da487ced52ccf2ca53409b0cc2cdb7a855c7502908463d0c0cf9816799f548a9f
|
7
|
+
data.tar.gz: bb19996d1ec2c74df54787283a2262995ed0e5fa1bd554cbff18f67152322abcd15146780ea522e2c5beb3b04241824e0e8a480493f40dac33364a569e3a37f2
|
data/Gemfile.lock
CHANGED
data/lib/fron/version.rb
CHANGED
data/opal/fron.rb
CHANGED
data/opal/fron/core-ext/hash.rb
CHANGED
@@ -14,4 +14,18 @@ class Hash
|
|
14
14
|
end
|
15
15
|
r
|
16
16
|
end
|
17
|
+
|
18
|
+
def deepDiff(b)
|
19
|
+
a = self
|
20
|
+
(a.keys + b.keys).uniq.inject({}) do |diff, k|
|
21
|
+
if a[k] != b[k]
|
22
|
+
if a[k].respond_to?(:deepDiff) && b[k].respond_to?(:deepDiff)
|
23
|
+
diff[k] = a[k].deepDiff(b[k])
|
24
|
+
else
|
25
|
+
diff[k] = [a[k], b[k]]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
diff
|
29
|
+
end
|
30
|
+
end
|
17
31
|
end
|
@@ -16,14 +16,15 @@ module Fron
|
|
16
16
|
block.call Fron::Storage::LocalStorage.get id
|
17
17
|
end
|
18
18
|
|
19
|
-
def set(
|
19
|
+
def set(model, data, &block)
|
20
|
+
id = model.id
|
20
21
|
id = SecureRandom.uuid unless id
|
21
22
|
data[:id] = id
|
22
23
|
unless (errors = validate data)
|
23
24
|
Fron::Storage::LocalStorage.set id, data
|
24
|
-
block.call nil
|
25
|
+
block.call nil, data
|
25
26
|
else
|
26
|
-
block.call errors
|
27
|
+
block.call errors, {}
|
27
28
|
end
|
28
29
|
data
|
29
30
|
end
|
@@ -8,9 +8,16 @@ module Fron
|
|
8
8
|
@request.headers = {'Content-Type' => 'application/json'}
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def del(model,&block)
|
12
|
+
setUrl model
|
13
|
+
@request.request 'DELETE', transform({}) do
|
14
|
+
block.call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def all(data = nil, &block)
|
12
19
|
setUrl nil
|
13
|
-
@request.get { |response| block.call response.json }
|
20
|
+
@request.get(data) { |response| block.call response.json }
|
14
21
|
end
|
15
22
|
|
16
23
|
def get(id,&block)
|
@@ -18,29 +25,38 @@ module Fron
|
|
18
25
|
@request.get { |response| block.call response.json }
|
19
26
|
end
|
20
27
|
|
21
|
-
def set(
|
22
|
-
setUrl
|
23
|
-
method = id ? 'put' : 'post'
|
28
|
+
def set(model,data,&block)
|
29
|
+
setUrl model
|
30
|
+
method = model.id ? 'put' : 'post'
|
24
31
|
@request.send(method,transform(data)) do |response|
|
25
|
-
|
32
|
+
error = case response.status
|
26
33
|
when 201, 204
|
27
34
|
nil
|
28
35
|
when 422
|
29
36
|
response.json
|
30
37
|
end
|
38
|
+
block.call error, response.json
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
34
42
|
private
|
35
43
|
|
36
|
-
def setUrl(
|
37
|
-
|
44
|
+
def setUrl(model)
|
45
|
+
id = model.is_a?(Fron::Model) ? model.id : model
|
46
|
+
endpoint = if @options[:endpoint].is_a? Proc
|
47
|
+
model.instance_eval &@options[:endpoint]
|
48
|
+
else
|
49
|
+
@options[:endpoint]
|
50
|
+
end
|
51
|
+
base = endpoint + "/" + @options[:resources]
|
38
52
|
base += id ? "/" + id.to_s : ".json"
|
39
53
|
@request.url = base
|
40
54
|
end
|
41
55
|
|
42
56
|
def transform(data)
|
43
57
|
newdata = {}
|
58
|
+
meta = DOM::Document.head.find("meta[name=csrf-token]")
|
59
|
+
newdata[:authenticity_token] = meta['content'] if meta
|
44
60
|
newdata[@options[:resource]] = data.dup
|
45
61
|
newdata
|
46
62
|
end
|
@@ -5,7 +5,7 @@ module Fron
|
|
5
5
|
class Yield < Component
|
6
6
|
end
|
7
7
|
|
8
|
-
attr_accessor :title, :stylesheets, :logger
|
8
|
+
attr_accessor :title, :stylesheets, :logger, :injectBlock
|
9
9
|
attr_reader :routeBlock, :main, :app
|
10
10
|
|
11
11
|
def initialize
|
@@ -21,5 +21,9 @@ module Fron
|
|
21
21
|
def layout(&block)
|
22
22
|
@app.instance_exec @main, &block
|
23
23
|
end
|
24
|
+
|
25
|
+
def customInject(&block)
|
26
|
+
@injectBlock = block
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
data/opal/fron/core/eventable.rb
CHANGED
@@ -9,12 +9,12 @@ module Fron
|
|
9
9
|
block
|
10
10
|
end
|
11
11
|
|
12
|
-
def trigger(event, triggerGlobal = true)
|
12
|
+
def trigger(event, data = {}, triggerGlobal = true)
|
13
13
|
return unless @events
|
14
14
|
return unless @events[event]
|
15
|
-
Eventable.trigger event, false if triggerGlobal && self != Fron::Eventable
|
15
|
+
Eventable.trigger event, data, false if triggerGlobal && self != Fron::Eventable
|
16
16
|
@events[event].each do |block|
|
17
|
-
block.call
|
17
|
+
block.call data
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
data/opal/fron/core/model.rb
CHANGED
@@ -24,8 +24,8 @@ module Fron
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def all(&block)
|
28
|
-
@adapterObject.all do |items|
|
27
|
+
def all(data = nil, &block)
|
28
|
+
@adapterObject.all data do |items|
|
29
29
|
break unless block_given?
|
30
30
|
block.call items.map{ |item| self.new item }
|
31
31
|
end
|
@@ -47,8 +47,8 @@ module Fron
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def update(attributes = {}, &block)
|
50
|
-
data =
|
51
|
-
self.class.instance_variable_get("@adapterObject").set
|
50
|
+
data = gather.merge! attributes
|
51
|
+
self.class.instance_variable_get("@adapterObject").set self, data do |errors,data|
|
52
52
|
@errors = errors
|
53
53
|
merge data
|
54
54
|
block.call if block_given?
|
@@ -61,9 +61,29 @@ module Fron
|
|
61
61
|
|
62
62
|
private
|
63
63
|
|
64
|
+
def clone(data = {})
|
65
|
+
cl = self.class.new @data.merge data
|
66
|
+
cl.instance_variable_set "@errors", self.errors
|
67
|
+
cl
|
68
|
+
end
|
69
|
+
|
70
|
+
def destroy(&block)
|
71
|
+
self.class.instance_variable_get("@adapterObject").del self do
|
72
|
+
block.call if block_given?
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def gather
|
77
|
+
@data.dup.reject{|key| !self.class.fields.include?(key)}
|
78
|
+
end
|
79
|
+
|
64
80
|
def merge(data)
|
65
81
|
data.each_pair do |key,value|
|
66
|
-
|
82
|
+
if self.respond_to?(key+"=")
|
83
|
+
self.send(key+"=", value)
|
84
|
+
else
|
85
|
+
@data[key] = value
|
86
|
+
end
|
67
87
|
end
|
68
88
|
end
|
69
89
|
end
|
data/opal/fron/core/router.rb
CHANGED
@@ -31,17 +31,17 @@ module Fron
|
|
31
31
|
|
32
32
|
def self.pathToRegexp(path)
|
33
33
|
return path if path == "*"
|
34
|
-
{regexp: Regexp.new('^'+path.gsub(/:(
|
34
|
+
{regexp: Regexp.new('^'+path.gsub(/:([^\/]+)/, '([^\/]+)')), map: path.scan(/:([^\/]+)/).flatten }
|
35
35
|
end
|
36
36
|
|
37
|
-
def route(hash = DOM::Window.hash, controller = nil)
|
37
|
+
def route(hash = DOM::Window.hash, controller = nil, startParams = {})
|
38
38
|
routes = controller ? (controller.class.routes || []) : @routes
|
39
39
|
routes.each do |r|
|
40
40
|
if r[:path] == '*'
|
41
41
|
if r[:controller]
|
42
|
-
break route(hash,r[:controller])
|
42
|
+
break route(hash,r[:controller],startParams)
|
43
43
|
else
|
44
|
-
break applyRoute(controller,r)
|
44
|
+
break applyRoute(controller,r,startParams)
|
45
45
|
end
|
46
46
|
else
|
47
47
|
matches = hash.match(r[:path][:regexp]).to_a[1..-1]
|
@@ -53,9 +53,9 @@ module Fron
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
if r[:action]
|
56
|
-
break applyRoute(controller,r,params)
|
56
|
+
break applyRoute(controller,r,startParams.merge(params))
|
57
57
|
else
|
58
|
-
break route hash.gsub(r[:path][:regexp],''), r[:controller]
|
58
|
+
break route hash.gsub(r[:path][:regexp],''), r[:controller], startParams.merge(params)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -72,10 +72,15 @@ module Fron
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
|
+
controller.send(:empty) if controller.respond_to?(:empty)
|
75
76
|
controller.send(route[:action], params)
|
76
77
|
@config.logger.info "Navigate >> #{controller.class}##{route[:action]} with params #{params}"
|
77
78
|
@config.main.empty
|
78
|
-
@config.
|
79
|
+
if @config.injectBlock
|
80
|
+
@config.injectBlock.call controller.base
|
81
|
+
else
|
82
|
+
@config.main << controller.base
|
83
|
+
end
|
79
84
|
end
|
80
85
|
end
|
81
86
|
end
|
data/opal/fron/dom.rb
CHANGED
data/opal/fron/dom/document.rb
CHANGED
data/opal/fron/dom/element.rb
CHANGED
@@ -87,10 +87,6 @@ module DOM
|
|
87
87
|
`#{@el}.innerHTML = #{value}`
|
88
88
|
end
|
89
89
|
|
90
|
-
def empty
|
91
|
-
self.html = ''
|
92
|
-
end
|
93
|
-
|
94
90
|
def value
|
95
91
|
`#{@el}.value`
|
96
92
|
end
|
@@ -107,6 +103,22 @@ module DOM
|
|
107
103
|
`#{@el}.checked = #{value}`
|
108
104
|
end
|
109
105
|
|
106
|
+
def disabled
|
107
|
+
`#{@el}.disabled`
|
108
|
+
end
|
109
|
+
|
110
|
+
def disabled=(value)
|
111
|
+
`#{@el}.disabled = #{value}`
|
112
|
+
end
|
113
|
+
|
114
|
+
def focus
|
115
|
+
`#{@el}.focus()`
|
116
|
+
end
|
117
|
+
|
118
|
+
def files
|
119
|
+
Native `#{@el}.files`
|
120
|
+
end
|
121
|
+
|
110
122
|
def tag
|
111
123
|
`#{@el}.tagName`.downcase
|
112
124
|
end
|
data/opal/fron/dom/event.rb
CHANGED
@@ -1,10 +1,125 @@
|
|
1
1
|
module DOM
|
2
2
|
class Event
|
3
|
+
|
4
|
+
SPECIAL_KEYS = {
|
5
|
+
8 => 'backspace',
|
6
|
+
9 => 'tab',
|
7
|
+
12 => 'num',
|
8
|
+
13 => 'enter',
|
9
|
+
16 => 'shift',
|
10
|
+
17 => 'ctrl',
|
11
|
+
18 => 'alt',
|
12
|
+
19 => 'pause',
|
13
|
+
20 => 'capslock',
|
14
|
+
27 => 'esc',
|
15
|
+
32 => 'space',
|
16
|
+
33 => 'pageup',
|
17
|
+
34 => 'pagedown',
|
18
|
+
35 => 'end',
|
19
|
+
36 => 'home',
|
20
|
+
37 => 'left',
|
21
|
+
38 => 'up',
|
22
|
+
39 => 'right',
|
23
|
+
40 => 'down',
|
24
|
+
44 => 'print',
|
25
|
+
45 => 'insert',
|
26
|
+
46 => 'delete',
|
27
|
+
48 => '0',
|
28
|
+
49 => '1',
|
29
|
+
50 => '2',
|
30
|
+
51 => '3',
|
31
|
+
52 => '4',
|
32
|
+
53 => '5',
|
33
|
+
54 => '6',
|
34
|
+
55 => '7',
|
35
|
+
56 => '8',
|
36
|
+
57 => '9',
|
37
|
+
65 => 'a',
|
38
|
+
66 => 'b',
|
39
|
+
67 => 'c',
|
40
|
+
68 => 'd',
|
41
|
+
69 => 'e',
|
42
|
+
70 => 'f',
|
43
|
+
71 => 'g',
|
44
|
+
72 => 'h',
|
45
|
+
73 => 'i',
|
46
|
+
74 => 'j',
|
47
|
+
75 => 'k',
|
48
|
+
76 => 'l',
|
49
|
+
77 => 'm',
|
50
|
+
78 => 'n',
|
51
|
+
79 => 'o',
|
52
|
+
80 => 'p',
|
53
|
+
81 => 'q',
|
54
|
+
82 => 'r',
|
55
|
+
83 => 's',
|
56
|
+
84 => 't',
|
57
|
+
85 => 'u',
|
58
|
+
86 => 'v',
|
59
|
+
87 => 'w',
|
60
|
+
88 => 'x',
|
61
|
+
89 => 'y',
|
62
|
+
90 => 'z',
|
63
|
+
91 => 'cmd',
|
64
|
+
92 => 'cmd',
|
65
|
+
93 => 'cmd',
|
66
|
+
96 => 'num_0',
|
67
|
+
97 => 'num_1',
|
68
|
+
98 => 'num_2',
|
69
|
+
99 => 'num_3',
|
70
|
+
100 => 'num_4',
|
71
|
+
101 => 'num_5',
|
72
|
+
102 => 'num_6',
|
73
|
+
103 => 'num_7',
|
74
|
+
104 => 'num_8',
|
75
|
+
105 => 'num_9',
|
76
|
+
106 => 'multiply',
|
77
|
+
107 => 'add',
|
78
|
+
108 => 'enter',
|
79
|
+
109 => 'subtract',
|
80
|
+
110 => 'decimal',
|
81
|
+
111 => 'divide',
|
82
|
+
124 => 'print',
|
83
|
+
144 => 'num',
|
84
|
+
145 => 'scroll',
|
85
|
+
186 => ';',
|
86
|
+
187 => '=',
|
87
|
+
188 => ',',
|
88
|
+
189 => '-',
|
89
|
+
190 => '.',
|
90
|
+
191 => '/',
|
91
|
+
192 => '`',
|
92
|
+
219 => '[',
|
93
|
+
220 => '\\',
|
94
|
+
221 => ']',
|
95
|
+
222 => '\'',
|
96
|
+
224 => 'cmd',
|
97
|
+
57392 => 'ctrl',
|
98
|
+
63289 => 'num'
|
99
|
+
}
|
100
|
+
|
3
101
|
def initialize(e,targetClass)
|
4
102
|
@e = e
|
5
103
|
@targetClass = targetClass
|
6
104
|
end
|
7
105
|
|
106
|
+
def key
|
107
|
+
return SPECIAL_KEYS[keyCode] if SPECIAL_KEYS[keyCode]
|
108
|
+
`String.fromCharCode(#{keyCode}).toLowerCase()`
|
109
|
+
end
|
110
|
+
|
111
|
+
def stopImmediatePropagation
|
112
|
+
`#{@e}.stopImmediatePropagation()`
|
113
|
+
end
|
114
|
+
|
115
|
+
def dataTransfer
|
116
|
+
Native `#{@e}.dataTransfer`
|
117
|
+
end
|
118
|
+
|
119
|
+
def button
|
120
|
+
`#{@e}.button`
|
121
|
+
end
|
122
|
+
|
8
123
|
def target
|
9
124
|
@targetClass.new `#{@e}.target`
|
10
125
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module DOM
|
2
2
|
module Events
|
3
|
+
attr_reader :listeners
|
4
|
+
|
3
5
|
def trigger(type, data = {})
|
4
6
|
%x{
|
5
|
-
event = document.createEvent("HTMLEvents");
|
7
|
+
var event = document.createEvent("HTMLEvents");
|
6
8
|
event.initEvent(#{type}, true, true);
|
7
9
|
for (key in #{data}) {
|
8
10
|
value = #{data}[key];
|
@@ -12,28 +14,20 @@ module DOM
|
|
12
14
|
}
|
13
15
|
end
|
14
16
|
|
15
|
-
def on(type, &listener)
|
16
|
-
|
17
|
-
|
18
|
-
else
|
19
|
-
Hash
|
20
|
-
end
|
21
|
-
method = `function(e){#{ listener.call Event.new(`e`,klass)}}`
|
22
|
-
|
23
|
-
@listeners ||= {}
|
24
|
-
@listeners[type] ||= []
|
25
|
-
@listeners[type] << method
|
17
|
+
def on!(type, &listener)
|
18
|
+
_on type, true, &listener
|
19
|
+
end
|
26
20
|
|
27
|
-
|
28
|
-
|
21
|
+
def on(type, &listener)
|
22
|
+
_on type, &listener
|
29
23
|
end
|
30
24
|
|
31
25
|
def off(type = nil, method = nil)
|
32
26
|
return unless @listeners
|
33
27
|
|
34
28
|
if type == nil
|
35
|
-
@listeners.keys.each do |
|
36
|
-
removeListeners
|
29
|
+
@listeners.keys.each do |ltype|
|
30
|
+
removeListeners ltype
|
37
31
|
end
|
38
32
|
elsif method == nil
|
39
33
|
removeListeners type
|
@@ -41,6 +35,7 @@ module DOM
|
|
41
35
|
return unless @listeners[type].index(method)
|
42
36
|
@listeners[type].delete method
|
43
37
|
`#{@el}.removeEventListener(#{type},#{method})`
|
38
|
+
`#{@el}.removeEventListener(#{type},#{method},true)`
|
44
39
|
end
|
45
40
|
end
|
46
41
|
|
@@ -54,6 +49,22 @@ module DOM
|
|
54
49
|
|
55
50
|
private
|
56
51
|
|
52
|
+
def _on(type, capture = false, &listener)
|
53
|
+
klass = if defined? self.class::EVENT_TARGET_CLASS
|
54
|
+
self.class::EVENT_TARGET_CLASS
|
55
|
+
else
|
56
|
+
Hash
|
57
|
+
end
|
58
|
+
method = `function(e){#{ listener.call Event.new(`e`,klass)}}`
|
59
|
+
|
60
|
+
@listeners ||= {}
|
61
|
+
@listeners[type] ||= []
|
62
|
+
@listeners[type] << method
|
63
|
+
|
64
|
+
`#{@el}.addEventListener(#{type},#{method},#{capture})`
|
65
|
+
method
|
66
|
+
end
|
67
|
+
|
57
68
|
def removeListeners(type)
|
58
69
|
@listeners[type].each do |method|
|
59
70
|
@listeners[type].delete method
|
data/opal/fron/dom/node.rb
CHANGED
@@ -35,6 +35,10 @@ module DOM
|
|
35
35
|
el ? DOM::NODE.new(el) : nil
|
36
36
|
end
|
37
37
|
|
38
|
+
def empty
|
39
|
+
children.each { |node| node.remove! }
|
40
|
+
end
|
41
|
+
|
38
42
|
def empty?
|
39
43
|
`#{@el}.childNodes.length === 0`
|
40
44
|
end
|
@@ -65,7 +69,8 @@ module DOM
|
|
65
69
|
end
|
66
70
|
|
67
71
|
def insertBefore(what,where)
|
68
|
-
|
72
|
+
return what >> self unless where # Fir for firefox...
|
73
|
+
`#{@el}.insertBefore(#{NODE.getElement what},#{NODE.getElement where})`
|
69
74
|
end
|
70
75
|
|
71
76
|
# Text manipulation
|
data/opal/fron/request.rb
CHANGED
@@ -33,21 +33,21 @@ describe Fron::Adapters::LocalAdapter do
|
|
33
33
|
describe "#set" do
|
34
34
|
it "should call localStorage#set" do
|
35
35
|
Fron::Storage::LocalStorage.should receive(:set).once
|
36
|
-
subject.set 0, {name: 'test'}, &proc
|
36
|
+
subject.set double(id: 0), {name: 'test'}, &proc
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should run the block with nil if there are no errors" do
|
40
|
-
proc.should receive(:call).with nil
|
41
|
-
subject.set 0, {name: 'test'}, &proc
|
40
|
+
proc.should receive(:call).with nil, {name: 'test', id: 0}
|
41
|
+
subject.set double(id: 0), {name: 'test'}, &proc
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should run the block with erros if ther are any" do
|
45
|
-
proc.should receive(:call).with({name: ["can't be blank"]})
|
46
|
-
subject.set 0, {name: ''}, &proc
|
45
|
+
proc.should receive(:call).with({name: ["can't be blank"]}, {})
|
46
|
+
subject.set double(id: 0), {name: ''}, &proc
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should add id if there isn't any" do
|
50
|
-
result = subject.set nil, {name: ''}, &proc
|
50
|
+
result = subject.set double(id: nil), {name: ''}, &proc
|
51
51
|
result[:id].should_not be nil
|
52
52
|
end
|
53
53
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'fron/core'
|
2
2
|
require 'fron/storage'
|
3
3
|
|
4
|
+
class TestModel < Fron::Model
|
5
|
+
end
|
6
|
+
|
4
7
|
describe Fron::Adapters::RailsAdapter do
|
5
8
|
|
6
9
|
subject do
|
@@ -14,6 +17,8 @@ describe Fron::Adapters::RailsAdapter do
|
|
14
17
|
|
15
18
|
let(:proc) { Proc.new {} }
|
16
19
|
let(:request) { double :request }
|
20
|
+
let(:model) { TestModel.new({ id: 0 }) }
|
21
|
+
let(:newModel) { TestModel.new }
|
17
22
|
|
18
23
|
before do
|
19
24
|
subject.instance_variable_set "@request", request
|
@@ -45,19 +50,19 @@ describe Fron::Adapters::RailsAdapter do
|
|
45
50
|
it "should call POST request for new record" do
|
46
51
|
request.should receive(:url=).with "test/users.json"
|
47
52
|
request.should receive(:post) do |&block|
|
48
|
-
block.call double status: 201
|
53
|
+
block.call double status: 201, json: ''
|
49
54
|
end
|
50
55
|
proc.should receive(:call)
|
51
|
-
subject.set
|
56
|
+
subject.set newModel, {}, &proc
|
52
57
|
end
|
53
58
|
|
54
59
|
it "should call PUT request for exsistsing record" do
|
55
60
|
request.should receive(:url=).with "test/users/0"
|
56
61
|
request.should receive(:put) do |&block|
|
57
|
-
block.call double status: 201
|
62
|
+
block.call double status: 201, json: ''
|
58
63
|
end
|
59
64
|
proc.should receive(:call)
|
60
|
-
subject.set
|
65
|
+
subject.set model, {}, &proc
|
61
66
|
end
|
62
67
|
|
63
68
|
it "should call block with error" do
|
@@ -65,8 +70,8 @@ describe Fron::Adapters::RailsAdapter do
|
|
65
70
|
request.should receive(:put) do |&block|
|
66
71
|
block.call double status: 422, json: 'error'
|
67
72
|
end
|
68
|
-
proc.should receive(:call).with 'error'
|
69
|
-
subject.set
|
73
|
+
proc.should receive(:call).with 'error', 'error'
|
74
|
+
subject.set model, {}, &proc
|
70
75
|
end
|
71
76
|
end
|
72
77
|
end
|
data/spec/core/model_spec.rb
CHANGED
@@ -12,11 +12,11 @@ class MockAdapter
|
|
12
12
|
block.call({name: 'User'})
|
13
13
|
end
|
14
14
|
|
15
|
-
def set(
|
16
|
-
if id == 0
|
17
|
-
block.call
|
15
|
+
def set(model,data,&block)
|
16
|
+
if model.id == 0
|
17
|
+
block.call(nil, data)
|
18
18
|
else
|
19
|
-
block.call({errors: true})
|
19
|
+
block.call({errors: true}, {})
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/spec/core/router_spec.rb
CHANGED
@@ -10,10 +10,6 @@ class TestRouteController < Fron::Controller
|
|
10
10
|
route "show/:id", :show
|
11
11
|
route "*", :test
|
12
12
|
|
13
|
-
before :empty, [:show]
|
14
|
-
|
15
|
-
def empty
|
16
|
-
end
|
17
13
|
def show
|
18
14
|
end
|
19
15
|
def test
|
@@ -27,6 +23,7 @@ describe Fron::Router do
|
|
27
23
|
let(:window_listeners) {window.instance_variable_get("@listeners")}
|
28
24
|
let(:controller) { TestRouteController.new }
|
29
25
|
let(:config) { double :config, {
|
26
|
+
injectBlock: nil,
|
30
27
|
logger: double(:logger,info: true),
|
31
28
|
main: double(:main, :"<<" => true, "empty" => true)
|
32
29
|
}
|
@@ -45,7 +42,7 @@ describe Fron::Router do
|
|
45
42
|
it "should return regexp for path" do
|
46
43
|
result = described_class.map "/test", :test
|
47
44
|
result[:path][:regexp].should eq Regexp.new "^/test"
|
48
|
-
result[:path][:map].should eq
|
45
|
+
result[:path][:map].should eq []
|
49
46
|
result[:action].should eq :test
|
50
47
|
end
|
51
48
|
|
data/spec/dom/event_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gusztav Szikszai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -57,7 +57,12 @@ files:
|
|
57
57
|
- lib/fron.rb
|
58
58
|
- lib/fron/version.rb
|
59
59
|
- opal/fron.rb
|
60
|
+
- opal/fron/core-ext.rb
|
60
61
|
- opal/fron/core-ext/hash.rb
|
62
|
+
- opal/fron/core-ext/kernel.rb
|
63
|
+
- opal/fron/core-ext/numeric.rb
|
64
|
+
- opal/fron/core-ext/proc.rb
|
65
|
+
- opal/fron/core-ext/string.rb
|
61
66
|
- opal/fron/core.rb
|
62
67
|
- opal/fron/core/adapters/local.rb
|
63
68
|
- opal/fron/core/adapters/rails.rb
|
@@ -73,6 +78,7 @@ files:
|
|
73
78
|
- opal/fron/dom/document.rb
|
74
79
|
- opal/fron/dom/element.rb
|
75
80
|
- opal/fron/dom/event.rb
|
81
|
+
- opal/fron/dom/file-reader.rb
|
76
82
|
- opal/fron/dom/fragment.rb
|
77
83
|
- opal/fron/dom/modules/classlist.rb
|
78
84
|
- opal/fron/dom/modules/dimensions.rb
|