fron 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fron/version.rb +1 -1
- data/opal/fron/core/adapters/rails.rb +3 -2
- data/opal/fron/core/component.rb +45 -14
- data/opal/fron/request/request.rb +9 -1
- data/spec/core/component_inheritance_spec.rb +43 -0
- data/spec/core/component_spec.rb +2 -2
- data/spec/request/request_spec.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c081b3b50bd27657d9e5f50c8f2b69c6f6b89bc
|
4
|
+
data.tar.gz: 3a71ea7cb7e1abfa225686200de85ef0ab5c99ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fb542de4835a8f2a69d285396ed483afdcfc834df4a63bcb902c4be28db1786542253ca6e29ad3a50ae7b94458dfe8cb65121636e1236e47ccf615ae5f1c112
|
7
|
+
data.tar.gz: d3c7799e2f0e7da34a820c17b8e104ba5156fd25ab83d6a7a63815dabbd418d5ac4d0163c90ec7c5bcde05807fa8faffd3854b0d57c03427f00ba09caed99389
|
data/Gemfile.lock
CHANGED
data/lib/fron/version.rb
CHANGED
@@ -5,6 +5,7 @@ module Fron
|
|
5
5
|
def initialize(options)
|
6
6
|
@options = options
|
7
7
|
@request = Request.new
|
8
|
+
@request.headers = {'Content-Type' => 'application/json'}
|
8
9
|
end
|
9
10
|
|
10
11
|
def all(&block)
|
@@ -39,8 +40,8 @@ module Fron
|
|
39
40
|
end
|
40
41
|
|
41
42
|
def transform(data)
|
42
|
-
newdata =
|
43
|
-
newdata
|
43
|
+
newdata = {}
|
44
|
+
newdata[@options[:resource]] = data.dup
|
44
45
|
newdata
|
45
46
|
end
|
46
47
|
end
|
data/opal/fron/core/component.rb
CHANGED
@@ -3,9 +3,20 @@ module Fron
|
|
3
3
|
attr_reader :model
|
4
4
|
|
5
5
|
class << self
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
attr_reader :events
|
7
|
+
attr_reader :tagname
|
8
|
+
attr_reader :components
|
9
|
+
attr_reader :delegates
|
10
|
+
|
11
|
+
def inherited(subclass)
|
12
|
+
[:components,:events,:delegates].each do |type|
|
13
|
+
if (var = instance_variable_get("@#{type}"))
|
14
|
+
inst_var = subclass.instance_variable_get('@#{type}')
|
15
|
+
subclass.instance_variable_set("@#{type}", []) unless inst_var
|
16
|
+
subclass.send(type).concat var
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
9
20
|
|
10
21
|
def tag(tag)
|
11
22
|
@tagname = tag
|
@@ -22,14 +33,9 @@ module Fron
|
|
22
33
|
@components << ( args << block )
|
23
34
|
end
|
24
35
|
|
25
|
-
def delegate(
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
define_method(method+"=") do |value|
|
31
|
-
instance_variable_get("@#{target}").send(method+"=",value)
|
32
|
-
end
|
36
|
+
def delegate(*args)
|
37
|
+
@delegates ||= []
|
38
|
+
@delegates << args
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
@@ -39,20 +45,29 @@ module Fron
|
|
39
45
|
@model = args[0]
|
40
46
|
when 2
|
41
47
|
tag, @model = args
|
48
|
+
when 3
|
49
|
+
tag, options, @model = args
|
42
50
|
end
|
43
51
|
|
44
52
|
super tag || self.class.tagname || self.class.name.split("::").last
|
45
53
|
|
46
54
|
applyEvents
|
47
55
|
createComponents
|
56
|
+
applyDelegates
|
57
|
+
|
58
|
+
if options
|
59
|
+
options.each do |method,value|
|
60
|
+
self.send(method+"=",value) if self.respond_to?(method+"=")
|
61
|
+
end
|
62
|
+
end
|
48
63
|
|
49
64
|
return if !respond_to?(:render) || !@model
|
50
65
|
@model.on 'change' do render end
|
51
66
|
render
|
52
67
|
end
|
53
68
|
|
54
|
-
def component(name,comp,&block)
|
55
|
-
c = comp.is_a?(Class) ? comp.new(
|
69
|
+
def component(name,comp,options,&block)
|
70
|
+
c = comp.is_a?(Class) ? comp.new(nil,options,@model) : Component.new(comp, options, @model)
|
56
71
|
c.instance_eval(&block) if block
|
57
72
|
self << c
|
58
73
|
self.instance_variable_set "@#{name}", c
|
@@ -63,7 +78,23 @@ module Fron
|
|
63
78
|
def createComponents
|
64
79
|
return unless self.class.components
|
65
80
|
self.class.components.each do |args|
|
66
|
-
|
81
|
+
arguments = args.dup
|
82
|
+
block = arguments.last.is_a?(Proc) ? arguments.pop : nil
|
83
|
+
component *arguments, &block
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def applyDelegates
|
88
|
+
return unless self.class.delegates
|
89
|
+
self.class.delegates.each do |args|
|
90
|
+
method, target = args
|
91
|
+
self.class.define_method(method) do
|
92
|
+
instance_variable_get("@#{target}").send(method)
|
93
|
+
end
|
94
|
+
|
95
|
+
self.class.define_method(method+"=") do |value|
|
96
|
+
instance_variable_get("@#{target}").send(method+"=",value)
|
97
|
+
end
|
67
98
|
end
|
68
99
|
end
|
69
100
|
|
@@ -6,6 +6,7 @@ module Fron
|
|
6
6
|
|
7
7
|
def initialize(url, headers = {})
|
8
8
|
@url = url
|
9
|
+
@headers = headers
|
9
10
|
@request = `new XMLHttpRequest()`
|
10
11
|
`#{@request}.addEventListener('readystatechange' , function(){#{handle_state_change}})`
|
11
12
|
self
|
@@ -16,10 +17,12 @@ module Fron
|
|
16
17
|
@callback = callback
|
17
18
|
if method.upcase == "GET" && data
|
18
19
|
`#{@request}.open(#{method},#{@url+"?"+data.to_query_string})`
|
20
|
+
setHeaders
|
19
21
|
`#{@request}.send()`
|
20
22
|
else
|
21
23
|
`#{@request}.open(#{method},#{@url})`
|
22
|
-
|
24
|
+
setHeaders
|
25
|
+
`#{@request}.send(#{data.to_json if data})`
|
23
26
|
end
|
24
27
|
else
|
25
28
|
raise "The request is already running!"
|
@@ -39,6 +42,11 @@ module Fron
|
|
39
42
|
end
|
40
43
|
|
41
44
|
private
|
45
|
+
def setHeaders
|
46
|
+
@headers.each_pair do |header,value|
|
47
|
+
`#{@request}.setRequestHeader(#{header},#{value})`
|
48
|
+
end
|
49
|
+
end
|
42
50
|
|
43
51
|
def ready_state
|
44
52
|
`#{@request}.readyState`
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'fron/core'
|
2
|
+
|
3
|
+
class BaseComponent < Fron::Component
|
4
|
+
component :text, 'text'
|
5
|
+
on :click, :render
|
6
|
+
delegate :text, :text
|
7
|
+
end
|
8
|
+
|
9
|
+
class InheritedComponent < BaseComponent
|
10
|
+
component :title, 'title'
|
11
|
+
end
|
12
|
+
|
13
|
+
class SuperComponent < InheritedComponent
|
14
|
+
end
|
15
|
+
|
16
|
+
describe SuperComponent do
|
17
|
+
subject { described_class }
|
18
|
+
|
19
|
+
it "should inherit components in order" do
|
20
|
+
subject.components.should_not be nil
|
21
|
+
subject.components[0].should eq [:text,'text',nil]
|
22
|
+
subject.components[1].should eq [:title,'title',nil]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe InheritedComponent do
|
27
|
+
subject { described_class }
|
28
|
+
|
29
|
+
it "should inherit components" do
|
30
|
+
subject.components.should_not be nil
|
31
|
+
subject.components[0].should eq [:text,'text',nil]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should inherit events" do
|
35
|
+
subject.events.should_not be nil
|
36
|
+
subject.events[0].should eq [:click, :render]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should inherit delegates" do
|
40
|
+
subject.delegates.should_not be nil
|
41
|
+
subject.delegates[0].should eq [:text,:text]
|
42
|
+
end
|
43
|
+
end
|
data/spec/core/component_spec.rb
CHANGED
@@ -52,8 +52,8 @@ describe Fron::Component do
|
|
52
52
|
describe '#delegate' do
|
53
53
|
it 'should create delegated methods' do
|
54
54
|
subject.delegate :text, :test
|
55
|
-
subject.
|
56
|
-
subject.
|
55
|
+
subject.delegates.should_not be nil
|
56
|
+
subject.delegates[0].should eq [:text,:test]
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -32,13 +32,13 @@ describe Fron::Request do
|
|
32
32
|
|
33
33
|
it 'should call #to_query_string on data if it is a GET' do
|
34
34
|
expect(data).to receive(:to_query_string)
|
35
|
-
expect(data).not_to receive(:
|
35
|
+
expect(data).not_to receive(:to_json)
|
36
36
|
subject.get data
|
37
37
|
end
|
38
38
|
|
39
|
-
it 'should call #
|
39
|
+
it 'should call #to_json on data if it is a GET' do
|
40
40
|
expect(data).not_to receive(:to_query_string)
|
41
|
-
expect(data).to receive(:
|
41
|
+
expect(data).to receive(:to_json)
|
42
42
|
subject.post data
|
43
43
|
end
|
44
44
|
|
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.2
|
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-05-
|
11
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- spec/core/adapter/local_spec.rb
|
92
92
|
- spec/core/adapter/rails_spec.rb
|
93
93
|
- spec/core/application_spec.rb
|
94
|
+
- spec/core/component_inheritance_spec.rb
|
94
95
|
- spec/core/component_spec.rb
|
95
96
|
- spec/core/configuration_spec.rb
|
96
97
|
- spec/core/controlller_spec.rb
|