ende 0.3.6 → 0.3.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 508121894c529c825b8be23734809551052843b0
4
- data.tar.gz: c1bb6a5676fcff34bb0c33b60f869bf96c8d4989
3
+ metadata.gz: 387fd35051f7507b9378515433c49a59673177c5
4
+ data.tar.gz: 36894b94c636fb11ea5ccf35e47d119091c9ec3a
5
5
  SHA512:
6
- metadata.gz: e1ace745145b3787b7b74fbc1ea6d022137e26c98d4d3ac9e0bec815fca1d0144a808f00eb60ee5a057e2a4b2fcbb0d1eb20dd11624cec82886bd022058edb6a
7
- data.tar.gz: a1e37960784210d21d53baef5aa9dc4a8065ec2d33ae6e6620ffe5a91643315b0e25fbbeb863d7cd12a50fbb3560f2a626cd290783dc8bcbe080e144529158a9
6
+ metadata.gz: 1a57d4ba49ddcfa92e58a69c004301e52ba57ca52ca06bd56801fabb280cbc4b1368e6fcfe9888b9fc3f823f8c5503667e7d4774d18d628c8aec266a5ffeae7b
7
+ data.tar.gz: 0eafb7dd7a3475901306b3d1f6822cd2508422d854741983ee8d2cfe2a6ab3c6566f3aa43fcc5f227e5c38e1d2b991824ae284c414b09716a0638e2f6af3839d
@@ -17,6 +17,7 @@ end.compact!
17
17
  models_list.each do |model_file|
18
18
  require_asset model_file
19
19
  end
20
+
20
21
  %>
21
22
 
22
23
  'use strict'
@@ -61,7 +62,7 @@ define 'aura/extensions/models', <%= models_list.to_json %>, (models...) ->
61
62
  core.resource = core.model = sandbox.resource = sandbox.model = (name) ->
62
63
  # TODO use a Map internally in indemma
63
64
  model = indemma.model[name]
64
- throw new TypeError "resources: Resource was not defined: #{name}" unless model?
65
+ throw new TypeError unless model?
65
66
  model
66
67
 
67
68
  # TODO rename core.models and core.domain, to core.resources, completely
@@ -14,33 +14,98 @@ define 'aura/extensions/routes', (routes) ->
14
14
  (application) ->
15
15
  core = application.core
16
16
  mediator = core.mediator
17
+ history = Modernizr.history
17
18
 
18
- # TODO unify router api
19
- router = new Lennon
20
- # TODO implement logger api for lennon or change lennon library
21
- # logger: application.logger
19
+ # TODO use diferent routers depending if history is enabled or not
20
+ lennon_extensions =
22
21
  publishEvent: (name, params) ->
23
22
 
24
- current_route = window.location.href
25
- if router.last_route != current_route
26
- mediator.emit 'route.changed'
27
- router.last_route = current_route
23
+ if router.last_route != router.current_route
24
+ mediator.emit 'route.changed', router.current_route
28
25
 
29
26
  # TODO method parsing (get, delete, put, post)
30
27
  mediator.emit name, params
31
28
 
32
- lennon_extensions =
29
+ process: ->
30
+ context = {}
31
+
32
+ if history
33
+ path = window.location.pathname
34
+ else
35
+ path = window.location.hash.replace('#!', '') || '/'
36
+ [path, search] = path.split('?') if path.indexOf('?') != -1
37
+
38
+ #-- If we land on the page with a hash value and history is enabled, redirect to the non-hash page
39
+ if ( window.location.hash.indexOf('#!') != -1 && history )
40
+ window.location.href = window.location.hash.replace('#!', '')
41
+
42
+ #-- If we land on the page with a path and history is disabled, redirect to the hash page
43
+ else if ( '/' != window.location.pathname && !history )
44
+ window.location.href = '/#!' + window.location.pathname
45
+
46
+
47
+ #-- Process the route
48
+ application.logger.info('Processing path', path)
49
+ for route in @routes
50
+
51
+ #-- See if the currently evaluated route matches the current path
52
+ params = path.match route.pattern
53
+
54
+ #-- If there is a match, extract the path values and match them to their variable names for context
55
+ if ( params )
56
+ paramKeys = route.path.match /:(\w*)/g,"(\\w*)"
57
+
58
+ j = 1
59
+ while j <= route.paramCount
60
+ context[paramKeys[j - 1].replace(/:/g, '')] = params[j]
61
+ j++
62
+
63
+ if ( @current_route )
64
+
65
+ #-- Don't dispatch the route we are already on
66
+ if ( @current_route.path == route.path && @current_route.search == search)
67
+ return false
68
+
69
+ #-- Dispatch the exit event for the route we are leaving
70
+ if ( @current_route.exitEventName )
71
+
72
+ application.logger.info('Exiting', @current_route.path, 'with', context || {})
73
+
74
+ #-- Execute the callback
75
+ if ( 'function' == typeof @current_route.exitEventName )
76
+ @current_route.exitEventName(context || {})
77
+ #-- Run the publish event
78
+ options.publishEvent(@current_route.exitEventName, context || {})
79
+
80
+ #-- Update the current route
81
+ @last_route = @current_route
82
+ @current_route = route
83
+
84
+ #-- Update the current route search string
85
+ @current_route.search = search
86
+
87
+ #-- Dispatch
88
+ return @dispatch(route, context)
89
+
90
+
91
+ #-- No route has been found, hence, nothing dispatched
92
+ application.logger.warn('No route dispatched')
93
+
33
94
  location: (href, process = true) ->
34
- if Modernizr.history
95
+ # TODO load router depending of history api
96
+ if history
35
97
  window.history.pushState null, null, href
36
98
  else
37
99
  # TODO parse href and extract path!
38
- window.location.hash = href
100
+ window.location.hash = '!' + href
39
101
 
40
- process and router.process()
102
+ process and @process()
41
103
 
42
- define: ->
43
- return false
104
+ # TODO unify router api
105
+ router = new Lennon
106
+ # TODO implement logger api for lennon or change lennon library
107
+ # logger: application.logger
108
+ publishEvent: lennon_extensions.publishEvent
44
109
 
45
110
 
46
111
  application.core.router = core.util.extend router, lennon_extensions
@@ -48,15 +113,23 @@ define 'aura/extensions/routes', (routes) ->
48
113
  location = Object.create null,
49
114
  # TODO cache query parsing
50
115
  query:
51
- get: -> query.parse window.location.search.substring(1)
116
+ get: ->
117
+ # TODO move routers implementation outside this file
118
+ if history
119
+ query.parse window.location.search.substring(1)
120
+ else
121
+ query.parse window.location.hash.split('?')[1]
122
+
52
123
 
53
124
  toString: -> window.location
54
125
 
55
126
  version: '0.2.1'
56
127
 
57
128
  initialize: (application) ->
129
+ {logger} = application
58
130
  application.sandbox.location = location
59
131
 
60
- afterAppStart: (application) ->
61
- # router.process()
62
-
132
+ # TODO pull request on aura to add info method on logger
133
+ # TODO better argument checking
134
+ logger._info = (-> console.info arguments[0], arguments[1], arguments[2]) || logger._log
135
+ logger.info = -> this.write this._info, arguments
@@ -3,7 +3,7 @@ define ['./states/index', './presenter'], (templates, presenter) ->
3
3
  # If some extension provides you can use the type defined in there
4
4
  # to extend your widget. Defaults to Base constructor.
5
5
  #
6
- # type: 'Base'
6
+ type: 'Base'
7
7
 
8
8
 
9
9
  # TODO add support for authentication keys
data/lib/ende/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ende
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
@@ -27469,6 +27469,8 @@ require.register("ened/vendor/assets/javascripts/lennon/lennon.js", function(exp
27469
27469
 
27470
27470
  if ( !initialized ) {
27471
27471
 
27472
+ router.routes = routes
27473
+
27472
27474
  $(document).on('click', options.linkSelector, function() {
27473
27475
  var $this = $(this),
27474
27476
  href = $this.attr('href');
@@ -27469,6 +27469,8 @@ require.register("ened/vendor/assets/javascripts/lennon/lennon.js", function(exp
27469
27469
 
27470
27470
  if ( !initialized ) {
27471
27471
 
27472
+ router.routes = routes
27473
+
27472
27474
  $(document).on('click', options.linkSelector, function() {
27473
27475
  var $this = $(this),
27474
27476
  href = $this.attr('href');
@@ -41,6 +41,8 @@
41
41
 
42
42
  if ( !initialized ) {
43
43
 
44
+ router.routes = routes
45
+
44
46
  $(document).on('click', options.linkSelector, function() {
45
47
  var $this = $(this),
46
48
  href = $this.attr('href');
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ende
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heitor Salazar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-12 00:00:00.000000000 Z
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler