fron 0.1.0 → 0.1.1
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/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/Rakefile +18 -0
- data/docs/configuration.md +8 -8
- data/lib/fron/version.rb +1 -1
- data/opal/fron/core.rb +1 -1
- data/opal/fron/core/adapters/{local-storage.rb → local.rb} +7 -6
- data/opal/fron/core/application.rb +13 -11
- data/opal/fron/core/configuration.rb +3 -4
- data/opal/fron/core/controller.rb +2 -2
- data/opal/fron/core/eventable.rb +5 -2
- data/opal/fron/core/logger.rb +7 -0
- data/opal/fron/core/model.rb +10 -8
- data/opal/fron/core/router.rb +1 -1
- data/opal/fron/dom.rb +1 -0
- data/opal/fron/dom/document.rb +4 -0
- data/opal/fron/dom/element.rb +22 -6
- data/opal/fron/dom/event.rb +71 -68
- data/opal/fron/dom/fragment.rb +1 -3
- data/opal/fron/dom/modules/classlist.rb +2 -2
- data/opal/fron/dom/modules/dimensions.rb +7 -8
- data/opal/fron/dom/modules/events.rb +57 -12
- data/opal/fron/dom/node.rb +45 -11
- data/opal/fron/dom/nodelist.rb +14 -0
- data/opal/fron/dom/style.rb +17 -15
- data/opal/fron/dom/text.rb +2 -4
- data/opal/fron/dom/window.rb +2 -3
- data/opal/fron/request/request.rb +17 -14
- data/opal/fron/storage/local-storage.rb +29 -13
- data/spec/core-ext/hash_spec.rb +18 -0
- data/spec/core/adapter/local_spec.rb +65 -0
- data/spec/core/adapter/rails_spec.rb +72 -0
- data/spec/core/application_spec.rb +35 -0
- data/spec/core/component_spec.rb +107 -0
- data/spec/core/configuration_spec.rb +20 -0
- data/spec/core/controlller_spec.rb +68 -0
- data/spec/core/eventable_spec.rb +74 -0
- data/spec/core/logger_spec.rb +28 -0
- data/spec/core/model_spec.rb +125 -0
- data/spec/core/router_spec.rb +127 -0
- data/spec/dom/document_spec.rb +41 -0
- data/spec/dom/element_spec.rb +164 -0
- data/spec/dom/event_spec.rb +121 -0
- data/spec/dom/fragment_spec.rb +13 -0
- data/spec/dom/modules/classlist_spec.rb +72 -0
- data/spec/dom/modules/dimensions_spec.rb +55 -0
- data/spec/dom/modules/events_spec.rb +73 -0
- data/spec/dom/node_spec.rb +189 -0
- data/spec/dom/nodelist_spec.rb +12 -0
- data/spec/dom/style_spec.rb +31 -0
- data/spec/dom/text_spec.rb +12 -0
- data/spec/dom/window_spec.rb +30 -0
- data/spec/request/request_spec.rb +71 -0
- data/spec/request/response_spec.rb +46 -0
- data/spec/storage/local-storage_spec.rb +58 -0
- metadata +36 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c0e03d014a5bf18112aa1e0e2b30a4c7ec7a882
|
4
|
+
data.tar.gz: 27d0049100bb53d0f9c837a1af4ce18af24a5e13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d734cef0c1d6e98667dea326f803f7bacb92955ab334eefbce18687a2e9cffb285eeb150f8a0a8d00bc70974cda37e29bb6171c7e742a56a9d834f492f3539b
|
7
|
+
data.tar.gz: 772c38050e98c59879cff8454facc2821bdd12eb5162d450a184e1772e9ade8ddf716747eda73fd135f2d7e20239cdd60afa108c04ec4b8a236eb9670ef65b12
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
fron
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fron (0.1.0)
|
5
|
+
opal (~> 0.6.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
hike (1.2.3)
|
11
|
+
json (1.8.1)
|
12
|
+
multi_json (1.10.0)
|
13
|
+
opal (0.6.2)
|
14
|
+
source_map
|
15
|
+
sprockets
|
16
|
+
opal-rspec (0.3.0.beta3)
|
17
|
+
opal (>= 0.6.0, < 1.0.0)
|
18
|
+
rack (1.5.2)
|
19
|
+
rake (10.3.1)
|
20
|
+
source_map (3.0.1)
|
21
|
+
json
|
22
|
+
sprockets (2.12.1)
|
23
|
+
hike (~> 1.2)
|
24
|
+
multi_json (~> 1.0)
|
25
|
+
rack (~> 1.0)
|
26
|
+
tilt (~> 1.1, != 1.3.0)
|
27
|
+
tilt (1.4.1)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
fron!
|
34
|
+
opal-rspec (~> 0.3.0.beta3)
|
35
|
+
rake
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
require 'opal/rspec/rake_task'
|
5
|
+
require 'rack'
|
6
|
+
|
7
|
+
Opal::RSpec::RakeTask.new(:default)
|
8
|
+
|
9
|
+
task :test do
|
10
|
+
|
11
|
+
app = Opal::Server.new { |s|
|
12
|
+
s.main = 'opal/rspec/sprockets_runner'
|
13
|
+
s.append_path 'spec'
|
14
|
+
s.debug = false
|
15
|
+
}
|
16
|
+
|
17
|
+
Rack::Server.start(:app => app, :Port => 9292)
|
18
|
+
end
|
data/docs/configuration.md
CHANGED
@@ -15,15 +15,15 @@ For using routes see the [routing documentation]().
|
|
15
15
|
## Example
|
16
16
|
```ruby
|
17
17
|
class TestApplication < Application
|
18
|
-
|
18
|
+
config.title = 'Test Application'
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
config.layout do |main|
|
21
|
+
component :header, 'header'
|
22
|
+
self << main
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
config.routes do
|
26
|
+
map SiteController
|
27
|
+
end
|
28
28
|
end
|
29
29
|
```
|
data/lib/fron/version.rb
CHANGED
data/opal/fron/core.rb
CHANGED
@@ -9,28 +9,29 @@ module Fron
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def all(&block)
|
12
|
-
block.call LocalStorage.all
|
12
|
+
block.call Fron::Storage::LocalStorage.all
|
13
13
|
end
|
14
14
|
|
15
15
|
def get(id, &block)
|
16
|
-
block.call LocalStorage.get id
|
16
|
+
block.call Fron::Storage::LocalStorage.get id
|
17
17
|
end
|
18
18
|
|
19
19
|
def set(id, data, &block)
|
20
20
|
id = SecureRandom.uuid unless id
|
21
21
|
data[:id] = id
|
22
22
|
unless (errors = validate data)
|
23
|
-
LocalStorage.set id, data
|
23
|
+
Fron::Storage::LocalStorage.set id, data
|
24
24
|
block.call nil
|
25
25
|
else
|
26
26
|
block.call errors
|
27
27
|
end
|
28
|
+
data
|
28
29
|
end
|
29
30
|
|
30
|
-
def validate(data)
|
31
|
+
def validate(data = {})
|
31
32
|
errors = {}
|
32
|
-
@options[:fields].map do |field|
|
33
|
-
next
|
33
|
+
@options[:fields].reject{|field| field == :id}.map do |field|
|
34
|
+
next if data[field] && data[field] != ""
|
34
35
|
errors[field] = ["can't be blank"]
|
35
36
|
valid = false
|
36
37
|
end
|
@@ -8,26 +8,28 @@ module Fron
|
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@routeMap = []
|
11
|
-
|
12
|
-
instance_eval &config.routeBlock
|
11
|
+
instance_eval &config.routeBlock if config.routeBlock
|
13
12
|
@router = Router.new @routeMap, config
|
14
13
|
|
15
|
-
DOM::Window.on
|
16
|
-
|
17
|
-
link = DOM::Element.new("link[rel=stylesheet][type=text/css][href=#{sheet}]")
|
18
|
-
link.on 'load' do
|
19
|
-
config.logger.info "External stylesheet loaded: #{sheet}"
|
20
|
-
end
|
21
|
-
DOM::Document.head << link
|
22
|
-
end
|
23
|
-
end
|
14
|
+
DOM::Window.on('load') { loadExternalStylesheets }
|
15
|
+
|
24
16
|
config.logger.info "Initialized Applicationation!"
|
25
17
|
config.logger.info "Inserting application to DOM!"
|
18
|
+
|
19
|
+
DOM::Document.title = config.title
|
26
20
|
DOM::Document.body << config.app
|
27
21
|
end
|
28
22
|
|
29
23
|
private
|
30
24
|
|
25
|
+
def loadExternalStylesheets
|
26
|
+
config.stylesheets.map do |sheet|
|
27
|
+
link = DOM::Element.new "link[rel=stylesheet][type=text/css][href=#{sheet}]"
|
28
|
+
link.on('load') { config.logger.info "External stylesheet loaded: #{sheet}" }
|
29
|
+
DOM::Document.head << link
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
31
33
|
def map(*args)
|
32
34
|
@routeMap << Router.map(*args)
|
33
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Fron
|
2
2
|
class Controller
|
3
3
|
class << self
|
4
|
-
|
4
|
+
attr_reader :baseComponent, :routes, :beforeFilters, :events
|
5
5
|
|
6
6
|
def base(component)
|
7
7
|
@baseComponent = component
|
@@ -17,7 +17,7 @@ module Fron
|
|
17
17
|
@events << {name: name, action: action}
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def before(method,actions)
|
21
21
|
@beforeFilters ||= []
|
22
22
|
@beforeFilters << {method: method, actions: actions}
|
23
23
|
end
|
data/opal/fron/core/eventable.rb
CHANGED
@@ -6,12 +6,13 @@ module Fron
|
|
6
6
|
@events ||= {}
|
7
7
|
@events[event] ||= []
|
8
8
|
@events[event] << block
|
9
|
+
block
|
9
10
|
end
|
10
11
|
|
11
12
|
def trigger(event, triggerGlobal = true)
|
12
|
-
Eventable.trigger event, false if triggerGlobal
|
13
13
|
return unless @events
|
14
14
|
return unless @events[event]
|
15
|
+
Eventable.trigger event, false if triggerGlobal && self != Fron::Eventable
|
15
16
|
@events[event].each do |block|
|
16
17
|
block.call
|
17
18
|
end
|
@@ -24,7 +25,9 @@ module Fron
|
|
24
25
|
elsif event
|
25
26
|
@events[event] = []
|
26
27
|
else
|
27
|
-
@events
|
28
|
+
@events.keys.each do |key|
|
29
|
+
@events.delete key
|
30
|
+
end
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
data/opal/fron/core/logger.rb
CHANGED
data/opal/fron/core/model.rb
CHANGED
@@ -5,11 +5,11 @@ module Fron
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
attr_accessor :fields
|
8
|
-
attr_accessor :
|
8
|
+
attr_accessor :adapterObject
|
9
9
|
|
10
10
|
def adapter(adapter, options = {})
|
11
|
-
options.merge! fields: @fields
|
12
|
-
@
|
11
|
+
options.merge! fields: @fields if @fields
|
12
|
+
@adapterObject = adapter.new options
|
13
13
|
end
|
14
14
|
|
15
15
|
def field(name)
|
@@ -25,14 +25,15 @@ module Fron
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def all(&block)
|
28
|
-
@
|
28
|
+
@adapterObject.all do |items|
|
29
|
+
break unless block_given?
|
29
30
|
block.call items.map{ |item| self.new item }
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
def find(id, &block)
|
34
35
|
user = self.new
|
35
|
-
@
|
36
|
+
@adapterObject.get id do |data|
|
36
37
|
user.merge data
|
37
38
|
block.call user
|
38
39
|
end
|
@@ -41,12 +42,13 @@ module Fron
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def initialize(data = {})
|
44
|
-
|
45
|
+
self.class.field :id
|
46
|
+
@data = data
|
45
47
|
end
|
46
48
|
|
47
|
-
def update(attributes, &block)
|
49
|
+
def update(attributes = {}, &block)
|
48
50
|
data = @data.dup.merge! attributes
|
49
|
-
self.class.instance_variable_get("@
|
51
|
+
self.class.instance_variable_get("@adapterObject").set id, data do |errors|
|
50
52
|
@errors = errors
|
51
53
|
merge data
|
52
54
|
block.call if block_given?
|
data/opal/fron/core/router.rb
CHANGED
@@ -35,7 +35,7 @@ module Fron
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def route(hash = DOM::Window.hash, controller = nil)
|
38
|
-
routes = controller ? controller.class.routes : @routes
|
38
|
+
routes = controller ? (controller.class.routes || []) : @routes
|
39
39
|
routes.each do |r|
|
40
40
|
if r[:path] == '*'
|
41
41
|
if r[:controller]
|
data/opal/fron/dom.rb
CHANGED
data/opal/fron/dom/document.rb
CHANGED
data/opal/fron/dom/element.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module DOM
|
2
|
-
class Element
|
3
|
-
include Node
|
2
|
+
class Element < NODE
|
4
3
|
include ClassList
|
5
4
|
include Dimensions
|
6
5
|
|
7
6
|
attr_reader :style
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
EVENT_TARGET_CLASS = self
|
9
|
+
ATTRIBUTE_REGEXP = /\[(.*?)=(.*?)\]/
|
10
|
+
TAG_REGEXP = /(^[A-Za-z_\-0-9]+)(.*)/
|
11
|
+
MODIFIER_REGEXP = /(#|\.)(.+?)(?=#|\.| |$)/
|
12
12
|
|
13
13
|
def initialize(data)
|
14
14
|
if `typeof #{data} === 'string'`
|
@@ -33,11 +33,23 @@ module DOM
|
|
33
33
|
self.text = m[0].strip
|
34
34
|
end
|
35
35
|
else
|
36
|
-
|
36
|
+
super data
|
37
37
|
end
|
38
38
|
@style = Style.new @el
|
39
39
|
end
|
40
40
|
|
41
|
+
def matches(selector)
|
42
|
+
%x{
|
43
|
+
var proto = Element.prototype
|
44
|
+
var matches = proto.matchesSelector ||
|
45
|
+
proto.mozMatchesSelector ||
|
46
|
+
proto.msMatchesSelector ||
|
47
|
+
proto.oMatchesSelector ||
|
48
|
+
proto.webkitMatchesSelector
|
49
|
+
return matches.call(#{@el},#{selector})
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
41
53
|
# Visiblity
|
42
54
|
# --------------------------------
|
43
55
|
def hide
|
@@ -98,5 +110,9 @@ module DOM
|
|
98
110
|
def tag
|
99
111
|
`#{@el}.tagName`.downcase
|
100
112
|
end
|
113
|
+
|
114
|
+
def id
|
115
|
+
self['id']
|
116
|
+
end
|
101
117
|
end
|
102
118
|
end
|
data/opal/fron/dom/event.rb
CHANGED
@@ -1,70 +1,73 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
1
|
+
module DOM
|
2
|
+
class Event
|
3
|
+
def initialize(e,targetClass)
|
4
|
+
@e = e
|
5
|
+
@targetClass = targetClass
|
6
|
+
end
|
7
|
+
|
8
|
+
def target
|
9
|
+
@targetClass.new `#{@e}.target`
|
10
|
+
end
|
11
|
+
|
12
|
+
def charCode
|
13
|
+
`#{@e}.charCode`
|
14
|
+
end
|
15
|
+
|
16
|
+
def keyCode
|
17
|
+
`#{@e}.keyCode`
|
18
|
+
end
|
19
|
+
|
20
|
+
def stop
|
21
|
+
preventDefault
|
22
|
+
stopPropagation
|
23
|
+
end
|
24
|
+
|
25
|
+
def preventDefault
|
26
|
+
`#{@e}.preventDefault()`
|
27
|
+
end
|
28
|
+
|
29
|
+
def stopPropagation
|
30
|
+
`#{@e}.stopPropagation()`
|
31
|
+
end
|
32
|
+
|
33
|
+
def pageX
|
34
|
+
`#{@e}.pageX`
|
35
|
+
end
|
36
|
+
|
37
|
+
def pageY
|
38
|
+
`#{@e}.pageY`
|
39
|
+
end
|
40
|
+
|
41
|
+
def screenX
|
42
|
+
`#{@e}.screenX`
|
43
|
+
end
|
44
|
+
|
45
|
+
def screenY
|
46
|
+
`#{@e}.screenY`
|
47
|
+
end
|
48
|
+
|
49
|
+
def clientX
|
50
|
+
`#{@e}.clientX`
|
51
|
+
end
|
52
|
+
|
53
|
+
def clientY
|
54
|
+
`#{@e}.clientY`
|
55
|
+
end
|
56
|
+
|
57
|
+
def alt?
|
58
|
+
`#{@e}.altKey`
|
59
|
+
end
|
60
|
+
|
61
|
+
def shift?
|
62
|
+
`#{@e}.shiftKey`
|
63
|
+
end
|
64
|
+
|
65
|
+
def ctrl?
|
66
|
+
`#{@e}.ctrlKey`
|
67
|
+
end
|
68
|
+
|
69
|
+
def meta?
|
70
|
+
`#{@e}.metaKey`
|
71
|
+
end
|
69
72
|
end
|
70
73
|
end
|