fron 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +35 -0
  6. data/Rakefile +18 -0
  7. data/docs/configuration.md +8 -8
  8. data/lib/fron/version.rb +1 -1
  9. data/opal/fron/core.rb +1 -1
  10. data/opal/fron/core/adapters/{local-storage.rb → local.rb} +7 -6
  11. data/opal/fron/core/application.rb +13 -11
  12. data/opal/fron/core/configuration.rb +3 -4
  13. data/opal/fron/core/controller.rb +2 -2
  14. data/opal/fron/core/eventable.rb +5 -2
  15. data/opal/fron/core/logger.rb +7 -0
  16. data/opal/fron/core/model.rb +10 -8
  17. data/opal/fron/core/router.rb +1 -1
  18. data/opal/fron/dom.rb +1 -0
  19. data/opal/fron/dom/document.rb +4 -0
  20. data/opal/fron/dom/element.rb +22 -6
  21. data/opal/fron/dom/event.rb +71 -68
  22. data/opal/fron/dom/fragment.rb +1 -3
  23. data/opal/fron/dom/modules/classlist.rb +2 -2
  24. data/opal/fron/dom/modules/dimensions.rb +7 -8
  25. data/opal/fron/dom/modules/events.rb +57 -12
  26. data/opal/fron/dom/node.rb +45 -11
  27. data/opal/fron/dom/nodelist.rb +14 -0
  28. data/opal/fron/dom/style.rb +17 -15
  29. data/opal/fron/dom/text.rb +2 -4
  30. data/opal/fron/dom/window.rb +2 -3
  31. data/opal/fron/request/request.rb +17 -14
  32. data/opal/fron/storage/local-storage.rb +29 -13
  33. data/spec/core-ext/hash_spec.rb +18 -0
  34. data/spec/core/adapter/local_spec.rb +65 -0
  35. data/spec/core/adapter/rails_spec.rb +72 -0
  36. data/spec/core/application_spec.rb +35 -0
  37. data/spec/core/component_spec.rb +107 -0
  38. data/spec/core/configuration_spec.rb +20 -0
  39. data/spec/core/controlller_spec.rb +68 -0
  40. data/spec/core/eventable_spec.rb +74 -0
  41. data/spec/core/logger_spec.rb +28 -0
  42. data/spec/core/model_spec.rb +125 -0
  43. data/spec/core/router_spec.rb +127 -0
  44. data/spec/dom/document_spec.rb +41 -0
  45. data/spec/dom/element_spec.rb +164 -0
  46. data/spec/dom/event_spec.rb +121 -0
  47. data/spec/dom/fragment_spec.rb +13 -0
  48. data/spec/dom/modules/classlist_spec.rb +72 -0
  49. data/spec/dom/modules/dimensions_spec.rb +55 -0
  50. data/spec/dom/modules/events_spec.rb +73 -0
  51. data/spec/dom/node_spec.rb +189 -0
  52. data/spec/dom/nodelist_spec.rb +12 -0
  53. data/spec/dom/style_spec.rb +31 -0
  54. data/spec/dom/text_spec.rb +12 -0
  55. data/spec/dom/window_spec.rb +30 -0
  56. data/spec/request/request_spec.rb +71 -0
  57. data/spec/request/response_spec.rb +46 -0
  58. data/spec/storage/local-storage_spec.rb +58 -0
  59. metadata +36 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee70da4161fdf883ebd912c124c53c5a8bb8ada5
4
- data.tar.gz: ab1e9096d251fc25a772e8b9fcf9798b1b8deda4
3
+ metadata.gz: 0c0e03d014a5bf18112aa1e0e2b30a4c7ec7a882
4
+ data.tar.gz: 27d0049100bb53d0f9c837a1af4ce18af24a5e13
5
5
  SHA512:
6
- metadata.gz: cdddc4a004ae3e9160e82fa001db6f41199038d72e47426a4953ce40dbf2f681c0ba2dacd4f9fd31e66a8140c372590fadbe6004a0049b4f5ad1fd51b3592698
7
- data.tar.gz: d265e541022bfb84a9299c6b9ca24386738ba932f5679cfe37fe5b3bd959734aa2bf20f39ec3930cb101619a61d36dc754c84fa77a40daf5bea375b932fa3d07
6
+ metadata.gz: 0d734cef0c1d6e98667dea326f803f7bacb92955ab334eefbce18687a2e9cffb285eeb150f8a0a8d00bc70974cda37e29bb6171c7e742a56a9d834f492f3539b
7
+ data.tar.gz: 772c38050e98c59879cff8454facc2821bdd12eb5162d450a184e1772e9ade8ddf716747eda73fd135f2d7e20239cdd60afa108c04ec4b8a236eb9670ef65b12
@@ -0,0 +1 @@
1
+ fron
@@ -0,0 +1 @@
1
+ 2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem 'rake'
@@ -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
@@ -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
@@ -15,15 +15,15 @@ For using routes see the [routing documentation]().
15
15
  ## Example
16
16
  ```ruby
17
17
  class TestApplication < Application
18
- config.title = 'Test Application'
18
+ config.title = 'Test Application'
19
19
 
20
- config.layout do |main|
21
- component :header, 'header'
22
- self << main
23
- end
20
+ config.layout do |main|
21
+ component :header, 'header'
22
+ self << main
23
+ end
24
24
 
25
- config.routes do
26
- map SiteController
27
- end
25
+ config.routes do
26
+ map SiteController
27
+ end
28
28
  end
29
29
  ```
@@ -1,3 +1,3 @@
1
1
  module Fron
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require './core/logger'
2
2
  require './core/component'
3
3
  require './core/adapters/rails'
4
- require './core/adapters/local-storage'
4
+ require './core/adapters/local'
5
5
  require './core/configuration'
6
6
  require './core/eventable'
7
7
  require './core/model'
@@ -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 unless data[field] == ""
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
- DOM::Document.title = config.title
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 'load' do
16
- config.stylesheets.map do |sheet|
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
@@ -9,10 +9,9 @@ module Fron
9
9
  attr_reader :routeBlock, :main, :app
10
10
 
11
11
  def initialize
12
- @main = Yield.new
13
- @app = App.new
14
-
15
- DOM::Document.body.empty
12
+ @app = App.new
13
+ @main = Yield.new
14
+ @logger = Fron::Logger.new
16
15
  end
17
16
 
18
17
  def routes(&block)
@@ -1,7 +1,7 @@
1
1
  module Fron
2
2
  class Controller
3
3
  class << self
4
- attr_accessor :baseComponent, :routes, :beforeFilters, :events
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 beforeFilter(method,actions)
20
+ def before(method,actions)
21
21
  @beforeFilters ||= []
22
22
  @beforeFilters << {method: method, actions: actions}
23
23
  end
@@ -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
@@ -1,7 +1,14 @@
1
1
  module Fron
2
2
  class Logger
3
+ attr_accessor :level
4
+
5
+ def initialize
6
+ @level = :info
7
+ end
8
+
3
9
  def info(message)
4
10
  return if ENV == 'test'
11
+ return if @level == :error
5
12
  puts Time.now.strftime("[%H:%M] ") + message
6
13
  end
7
14
  end
@@ -5,11 +5,11 @@ module Fron
5
5
 
6
6
  class << self
7
7
  attr_accessor :fields
8
- attr_accessor :adapter
8
+ attr_accessor :adapterObject
9
9
 
10
10
  def adapter(adapter, options = {})
11
- options.merge! fields: @fields
12
- @adapter = adapter.new options
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
- @adapter.all do |items|
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
- @adapter.get id do |data|
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
- @data = data
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("@adapter").set id, data do |errors|
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?
@@ -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]
@@ -1,6 +1,7 @@
1
1
  require './dom/modules/events'
2
2
  require './dom/modules/classlist'
3
3
  require './dom/modules/dimensions'
4
+ require './dom/nodelist'
4
5
  require './dom/style'
5
6
  require './dom/node'
6
7
  require './dom/text'
@@ -8,6 +8,10 @@ module DOM
8
8
  find 'body'
9
9
  end
10
10
 
11
+ def self.title
12
+ `document.title`
13
+ end
14
+
11
15
  def self.title=(value)
12
16
  `document.title = #{value}`
13
17
  end
@@ -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
- ATTRIBUTE_REGEXP = /\[(.*?)=(.*?)\]/
10
- TAG_REGEXP = /(^[A-Za-z_\-0-9]+)(.*)/
11
- MODIFIER_REGEXP = /(#|\.)(.+?)(?=#|\.| |$)/
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
- @el = data
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
@@ -1,70 +1,73 @@
1
- class Event
2
- def initialize(e)
3
- @e = e
4
- end
5
-
6
- def target
7
- `#{@e}.target`
8
- end
9
-
10
- def charCode
11
- `#{@e}.charCode`
12
- end
13
-
14
- def keyCode
15
- `#{@e}.keyCode`
16
- end
17
-
18
- def stop
19
- preventDefault
20
- stopPropagation
21
- end
22
-
23
- def preventDefault
24
- `#{@e}.preventDefault()`
25
- end
26
-
27
- def stopPropagation
28
- `#{@e}.stopPropagation()`
29
- end
30
-
31
- def pageX
32
- `#{@e}.pageX`
33
- end
34
-
35
- def pageY
36
- `#{@e}.pageY`
37
- end
38
-
39
- def screenX
40
- `#{@e}.screenX`
41
- end
42
-
43
- def screenY
44
- `#{@e}.screenY`
45
- end
46
-
47
- def clientX
48
- `#{@e}.clientX`
49
- end
50
-
51
- def clientY
52
- `#{@e}.clientY`
53
- end
54
-
55
- def alt?
56
- `#{@e}.altkey`
57
- end
58
-
59
- def shift?
60
- `#{@e}.shiftkey`
61
- end
62
-
63
- def ctrl?
64
- `#{@e}.ctrlkey`
65
- end
66
-
67
- def meta?
68
- `#{@e}.metakey`
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