joosy 0.1.0.RC2 → 0.1.0.RC3
Sign up to get free protection for your applications and to get access to all the features.
- data/.codoopts +5 -0
- data/.gitignore +2 -0
- data/Gemfile.lock +4 -2
- data/README.md +10 -4
- data/app/assets/javascripts/joosy/core/application.js.coffee +3 -1
- data/app/assets/javascripts/joosy/core/form.js.coffee +69 -42
- data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +30 -0
- data/app/assets/javascripts/joosy/core/joosy.js.coffee +125 -66
- data/app/assets/javascripts/joosy/core/layout.js.coffee +106 -1
- data/app/assets/javascripts/joosy/core/modules/container.js.coffee +41 -0
- data/app/assets/javascripts/joosy/core/modules/events.js.coffee +88 -1
- data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +24 -0
- data/app/assets/javascripts/joosy/core/modules/log.js.coffee +18 -0
- data/app/assets/javascripts/joosy/core/modules/module.js.coffee +53 -1
- data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +22 -6
- data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +21 -0
- data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +26 -0
- data/app/assets/javascripts/joosy/core/page.js.coffee +225 -16
- data/app/assets/javascripts/joosy/core/preloader.js.coffee +8 -0
- data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +52 -15
- data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +78 -50
- data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +39 -41
- data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +36 -27
- data/app/assets/javascripts/joosy/core/router.js.coffee +95 -19
- data/app/assets/javascripts/joosy/core/widget.js.coffee +42 -1
- data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +39 -24
- data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +9 -7
- data/app/helpers/joosy/sprockets_helper.rb +4 -1
- data/lib/joosy/rails/version.rb +1 -1
- data/spec/javascripts/joosy/core/application_spec.js.coffee +3 -3
- data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +0 -2
- data/spec/javascripts/joosy/core/router_spec.js.coffee +24 -24
- data/vendor/assets/javascripts/jquery.form.js +978 -963
- data/vendor/assets/javascripts/sugar.js +1 -1
- metadata +20 -20
- data/app/assets/javascripts/joosy/core/helpers.js.coffee +0 -16
- data/vendor/assets/javascripts/base64.js +0 -135
@@ -1,23 +1,77 @@
|
|
1
1
|
#= require joosy/core/joosy
|
2
2
|
|
3
|
+
#
|
4
|
+
# Router. Reacts on a hash change event and loads proper pages
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
# Joosy.Router.map
|
8
|
+
# 404 : (path) -> alert "Page '#{path}' was not found :("
|
9
|
+
# '/' : Welcome.IndexPage
|
10
|
+
# '/resources' :
|
11
|
+
# '/' : Resource.IndexPage
|
12
|
+
# '/:id' : Resource.ShowPage
|
13
|
+
# '/:id/edit' : Resource.EditPage
|
14
|
+
# '/new' : Resource.EditPage
|
15
|
+
#
|
16
|
+
# @module
|
17
|
+
#
|
3
18
|
Joosy.Router =
|
19
|
+
#
|
20
|
+
# The Object containing route parts in keys and pages/lambdas in values
|
21
|
+
#
|
4
22
|
rawRoutes: Object.extended()
|
23
|
+
|
24
|
+
#
|
25
|
+
# Flattern routes mapped to regexps (to check if current route is what we
|
26
|
+
# need) and actual executors
|
27
|
+
#
|
5
28
|
routes: Object.extended()
|
6
29
|
|
30
|
+
#
|
31
|
+
# Clears the routes
|
32
|
+
#
|
7
33
|
reset: ->
|
8
34
|
@rawRoutes = Object.extended()
|
9
35
|
@routes = Object.extended()
|
10
36
|
|
37
|
+
#
|
38
|
+
# Registers the set of raw routes
|
39
|
+
# This method will only store routes and will not make them act immediately
|
40
|
+
# Routes get registered only once at system initialization during #__setupRoutes call
|
41
|
+
#
|
42
|
+
# @param [Object] routes Set of routes in inner format (see class description)
|
43
|
+
#
|
11
44
|
map: (routes) ->
|
12
45
|
Joosy.Module.merge @rawRoutes, routes
|
13
46
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
47
|
+
#
|
48
|
+
# Changes current hash with shebang (#!) and therefore triggers new route loading
|
49
|
+
# to be loaded
|
50
|
+
#
|
51
|
+
# @param [String] to Route to navigate to
|
52
|
+
#
|
53
|
+
navigate: (to) ->
|
54
|
+
location.hash = '!' + to
|
19
55
|
|
20
|
-
|
56
|
+
#
|
57
|
+
# Inits the routing system and loads the current route
|
58
|
+
# Binds the window hashchange event and therefore should only be called once
|
59
|
+
# during system startup
|
60
|
+
#
|
61
|
+
__setupRoutes: ->
|
62
|
+
@__prepareRoutes @rawRoutes
|
63
|
+
@__respondRoute location.hash
|
64
|
+
$(window).hashchange =>
|
65
|
+
@__respondRoute location.hash
|
66
|
+
|
67
|
+
#
|
68
|
+
# Compiles routes to map object
|
69
|
+
# Object will contain regexp string as key and lambda/Page to load as value
|
70
|
+
#
|
71
|
+
# @param [Object] routes Raw routes to prepare
|
72
|
+
# @param [String] namespace Inner cursor for recursion
|
73
|
+
#
|
74
|
+
__prepareRoutes: (routes, namespace='') ->
|
21
75
|
if !namespace && routes[404]
|
22
76
|
@wildcardAction = routes[404]
|
23
77
|
delete routes[404]
|
@@ -25,11 +79,18 @@ Joosy.Router =
|
|
25
79
|
Object.each routes, (path, response) =>
|
26
80
|
path = (namespace + path).replace /\/{2,}/, '/'
|
27
81
|
if response && (Object.isFunction(response) || response.prototype?)
|
28
|
-
Joosy.Module.merge @routes, @
|
82
|
+
Joosy.Module.merge @routes, @__prepareRoute(path, response)
|
29
83
|
else
|
30
|
-
@
|
31
|
-
|
32
|
-
|
84
|
+
@__prepareRoutes response, path
|
85
|
+
|
86
|
+
#
|
87
|
+
# Compiles one single route
|
88
|
+
#
|
89
|
+
# @param [String] path Full path from raw route
|
90
|
+
# @param [Joosy.Page] response Page that should be loaded at this route
|
91
|
+
# @param [Function] response Lambda to call at this route
|
92
|
+
#
|
93
|
+
__prepareRoute: (path, response) ->
|
33
94
|
matchPath = path.replace(/\/:([^\/]+)/g, '/([^/]+)').replace(/^\/?/, '^/?').replace(/\/?$/, '/?$')
|
34
95
|
result = Object.extended()
|
35
96
|
|
@@ -39,18 +100,23 @@ Joosy.Router =
|
|
39
100
|
action: response
|
40
101
|
result
|
41
102
|
|
42
|
-
|
103
|
+
#
|
104
|
+
# Searches the corresponding route through compiled routes
|
105
|
+
#
|
106
|
+
# @param [String] hash Hash value to search route for
|
107
|
+
#
|
108
|
+
__respondRoute: (hash) ->
|
43
109
|
Joosy.Modules.Log.debug "Router> Answering '#{hash}'"
|
44
110
|
fullPath = hash.replace /^#!?/, ''
|
45
111
|
@currentPath = fullPath
|
46
112
|
found = false
|
47
113
|
queryArray = fullPath.split '&'
|
48
114
|
path = queryArray.shift()
|
49
|
-
urlParams = @
|
115
|
+
urlParams = @__paramsFromQueryArray queryArray
|
50
116
|
|
51
117
|
for regex, route of @routes when @routes.hasOwnProperty regex
|
52
118
|
if vals = path.match new RegExp(regex)
|
53
|
-
params = @
|
119
|
+
params = @__paramsFromRouteMatch(vals, route).merge urlParams
|
54
120
|
|
55
121
|
if Joosy.Module.hasAncestor route.action, Joosy.Page
|
56
122
|
Joosy.Application.setCurrentPage route.action, params
|
@@ -63,7 +129,14 @@ Joosy.Router =
|
|
63
129
|
if !found && @wildcardAction?
|
64
130
|
@wildcardAction path, urlParams
|
65
131
|
|
66
|
-
|
132
|
+
#
|
133
|
+
# Collects params from route placeholders (/foo/:placeholder)
|
134
|
+
#
|
135
|
+
# @param [Array] vals Array of value gathered by regexp
|
136
|
+
# @param [Object] route Compiled route
|
137
|
+
# @returns [Object] Hash of params
|
138
|
+
#
|
139
|
+
__paramsFromRouteMatch: (vals, route) ->
|
67
140
|
params = Object.extended()
|
68
141
|
|
69
142
|
vals.shift()
|
@@ -72,7 +145,13 @@ Joosy.Router =
|
|
72
145
|
|
73
146
|
params
|
74
147
|
|
75
|
-
|
148
|
+
#
|
149
|
+
# Collects params from query routes (/foo/&a=b)
|
150
|
+
#
|
151
|
+
# @param [Array] queryArray Array of query string split by '&' sign
|
152
|
+
# @returns [Object] Hash of params
|
153
|
+
#
|
154
|
+
__paramsFromQueryArray: (queryArray) ->
|
76
155
|
params = Object.extended()
|
77
156
|
|
78
157
|
if queryArray
|
@@ -81,7 +160,4 @@ Joosy.Router =
|
|
81
160
|
pair = @split '='
|
82
161
|
params[pair[0]] = pair[1]
|
83
162
|
|
84
|
-
params
|
85
|
-
|
86
|
-
navigate: (to) ->
|
87
|
-
location.hash = '!' + to
|
163
|
+
params
|
@@ -6,6 +6,15 @@
|
|
6
6
|
#= require joosy/core/modules/renderer
|
7
7
|
#= require joosy/core/modules/filters
|
8
8
|
|
9
|
+
#
|
10
|
+
# Base class for all of your Joosy Layouts.
|
11
|
+
#
|
12
|
+
# @todo Add link to the 5th chapter of guides here.
|
13
|
+
#
|
14
|
+
# @example Sample widget
|
15
|
+
# class @FooWidget extends Joosy.Widget
|
16
|
+
# @view 'foo'
|
17
|
+
#
|
9
18
|
class Joosy.Widget extends Joosy.Module
|
10
19
|
@include Joosy.Modules.Log
|
11
20
|
@include Joosy.Modules.Events
|
@@ -14,16 +23,41 @@ class Joosy.Widget extends Joosy.Module
|
|
14
23
|
@include Joosy.Modules.Filters
|
15
24
|
@include Joosy.Modules.TimeManager
|
16
25
|
|
26
|
+
#
|
27
|
+
# By default widget will not render on load
|
28
|
+
#
|
17
29
|
__renderer: false
|
18
|
-
|
30
|
+
|
31
|
+
#
|
32
|
+
# Initial data that will be passed to view on load
|
33
|
+
# False (and not {}) by default to have a chance to check if data was loaded
|
34
|
+
#
|
19
35
|
data: false
|
20
36
|
|
37
|
+
#
|
38
|
+
# Proxy to Joosy.Router#navigate
|
39
|
+
#
|
21
40
|
navigate: (args...) ->
|
22
41
|
Joosy.Router.navigate args...
|
23
42
|
|
43
|
+
#
|
44
|
+
# This is required by {Joosy.Modules.Renderer}
|
45
|
+
# Sets the base template dir to app_name/templates/widgets
|
46
|
+
#
|
24
47
|
__renderSection: ->
|
25
48
|
'widgets'
|
26
49
|
|
50
|
+
#
|
51
|
+
# Widget bootstrap proccess
|
52
|
+
#
|
53
|
+
# * Rendering (if required)
|
54
|
+
# * {Joosy.Modules.Container#refreshElements}
|
55
|
+
# * {Joosy.Modules.Container#__delegateEvents}
|
56
|
+
# * {Joosy.Modules.Filters#__runAfterLoads}
|
57
|
+
#
|
58
|
+
# @param [Joosy.Page, Joosy.Layout] Page or Layout to attach to
|
59
|
+
# @param [jQuery] container Container to attach to
|
60
|
+
#
|
27
61
|
__load: (@parent, @container) ->
|
28
62
|
if @__renderer
|
29
63
|
@container.html @__renderer(@data || {})
|
@@ -33,6 +67,13 @@ class Joosy.Widget extends Joosy.Module
|
|
33
67
|
|
34
68
|
this
|
35
69
|
|
70
|
+
#
|
71
|
+
# Layout destruction proccess.
|
72
|
+
#
|
73
|
+
# * {Joosy.Modules.TimeManager#__clearTime}
|
74
|
+
# * {Joosy.Modules.Renderer#__removeMetamorphs}
|
75
|
+
# * {Joosy.Modules.Filters#__runAfterUnloads}
|
76
|
+
#
|
36
77
|
__unload: ->
|
37
78
|
@__clearTime()
|
38
79
|
@__removeMetamorphs()
|
@@ -1,18 +1,20 @@
|
|
1
|
-
#= require base64
|
2
|
-
|
3
1
|
#
|
4
2
|
# Preloader for libraries with localStorage cache
|
5
3
|
#
|
6
|
-
#
|
4
|
+
# @note The `start` callback will only be called if loading required.
|
5
|
+
# While working with cache, `complete` is the only callback that will be triggered.
|
6
|
+
#
|
7
|
+
# @example Basic usage
|
7
8
|
# libraries = [['/test1.js', 100], ['/test2.js', 500]] #100, 500 - size in bytes
|
9
|
+
#
|
8
10
|
# CachingPreloader.load libraries,
|
9
11
|
# start: -> console.log 'preloading started'
|
10
12
|
# progress: (percent) -> console.log "#{percent}% loaded"
|
11
13
|
# complete: -> console.log 'preloading finished'
|
12
14
|
#
|
13
|
-
# @
|
15
|
+
# @module
|
14
16
|
#
|
15
|
-
@
|
17
|
+
@CachingPreloader =
|
16
18
|
#
|
17
19
|
# If set to true, localStorage cache will be avoided
|
18
20
|
#
|
@@ -50,6 +52,7 @@
|
|
50
52
|
@restore()
|
51
53
|
else
|
52
54
|
@start?.call window
|
55
|
+
@clean()
|
53
56
|
@download libraries
|
54
57
|
|
55
58
|
#
|
@@ -60,16 +63,21 @@
|
|
60
63
|
for name, i in @libraries
|
61
64
|
flag &&= window.localStorage.getItem(name)?
|
62
65
|
flag
|
63
|
-
|
66
|
+
|
67
|
+
#
|
68
|
+
# Escapes non-printable terminal chars before storing to localStorage to prevent IE bug
|
69
|
+
#
|
70
|
+
# @param [String] String, that will be prepared for localStorage
|
71
|
+
#
|
72
|
+
escapeStr: (str) ->
|
73
|
+
str.replace(new RegExp("\u0001", 'g'), "\\u0001").replace(new RegExp("\u000B", 'g'), "\\u000B")
|
74
|
+
|
64
75
|
#
|
65
76
|
# Gets sources of scripts from localStorage and evals them
|
66
77
|
#
|
67
78
|
restore: ->
|
68
79
|
for name, i in @libraries
|
69
|
-
|
70
|
-
if window.navigator.appName == "Microsoft Internet Explorer"
|
71
|
-
code = Base64.decode code
|
72
|
-
@evalGlobaly code
|
80
|
+
window.evalGlobaly window.localStorage.getItem name
|
73
81
|
@complete?.call window, true
|
74
82
|
|
75
83
|
#
|
@@ -89,12 +97,11 @@
|
|
89
97
|
@ajax url, size, (xhr) =>
|
90
98
|
code = xhr.responseText
|
91
99
|
if window.navigator.appName == "Microsoft Internet Explorer"
|
92
|
-
code =
|
100
|
+
code = @escapeStr code
|
93
101
|
window.localStorage.setItem @prefix+url, code
|
94
|
-
|
102
|
+
window.evalGlobaly xhr.responseText
|
95
103
|
@download libraries
|
96
104
|
else
|
97
|
-
@clean()
|
98
105
|
@complete?.call window
|
99
106
|
|
100
107
|
#
|
@@ -135,20 +142,28 @@
|
|
135
142
|
#
|
136
143
|
clean: ->
|
137
144
|
i = 0
|
145
|
+
|
146
|
+
find = (arr, obj) ->
|
147
|
+
(return i if obj == x) for x in arr
|
148
|
+
return -1
|
138
149
|
|
139
150
|
while i < window.localStorage.length && key = window.localStorage.key(i)
|
140
|
-
if key.indexOf(@prefix) == 0 && @libraries
|
151
|
+
if key.indexOf(@prefix) == 0 && find(@libraries, key) < 0
|
141
152
|
window.localStorage.removeItem key
|
142
153
|
else
|
143
154
|
i += 1
|
144
155
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
156
|
+
#
|
157
|
+
# Evals source at a global scope
|
158
|
+
# Don't touch it! It should be window's property, or FF3.6 will execute scripts on preloader context.
|
159
|
+
#
|
160
|
+
# @param [String] JS source to execute
|
161
|
+
#
|
162
|
+
window.evalGlobaly = (src) ->
|
163
|
+
return if src.length == 0
|
164
|
+
if window.execScript
|
165
|
+
window.execScript src
|
166
|
+
else
|
167
|
+
window.eval src
|
168
|
+
|
169
|
+
@Preloader = @CachingPreloader
|
@@ -1,18 +1,18 @@
|
|
1
1
|
#
|
2
|
-
# Preloader for libraries using
|
2
|
+
# Preloader for libraries using `script src` without any caching magic
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# @example Basic usage
|
5
5
|
# libraries = [['/test1.js'], ['/test2.js']]
|
6
|
+
#
|
6
7
|
# InlinePreloader.load libraries,
|
7
8
|
# start: -> console.log 'preloading started'
|
8
9
|
# complete: -> console.log 'preloading finished'
|
9
10
|
#
|
10
|
-
# @
|
11
|
+
# @module
|
11
12
|
#
|
12
|
-
@
|
13
|
-
|
13
|
+
@InlinePreloader =
|
14
14
|
#
|
15
|
-
# Loads set of libraries by adding
|
15
|
+
# Loads set of libraries by adding `script src` to DOM head
|
16
16
|
# See class description for example of usage
|
17
17
|
#
|
18
18
|
# @param [Array] 2-levels array of libraries URLs i.e. [['/test1.js'],['/test2.js']]
|
@@ -30,7 +30,7 @@
|
|
30
30
|
@complete?()
|
31
31
|
|
32
32
|
#
|
33
|
-
# Loads one script by adding
|
33
|
+
# Loads one script by adding `script src` to DOM head
|
34
34
|
#
|
35
35
|
# @param [String] url to load script from
|
36
36
|
# @param [Function] `() -> null` to call after script was loaded and executed
|
@@ -52,3 +52,5 @@
|
|
52
52
|
|
53
53
|
head.appendChild script
|
54
54
|
return undefined
|
55
|
+
|
56
|
+
@Preloader = @InlinePreloader
|
@@ -1,10 +1,13 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
1
3
|
module Joosy::SprocketsHelper
|
2
4
|
def extract_sources_and_sizes_from_include_tag(name)
|
3
5
|
code = javascript_include_tag name
|
4
6
|
resources = code.scan(/(?:href|src)=['"]([^'"]+)['"]/).flatten
|
5
7
|
|
6
8
|
resources.map do |resource|
|
7
|
-
|
9
|
+
uri = URI.parse resource
|
10
|
+
path = ::Rails.root.to_s + "/public" + uri.path
|
8
11
|
size = File.size(path) rescue false
|
9
12
|
[resource, size]
|
10
13
|
end.to_json.html_safe
|
data/lib/joosy/rails/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
describe "Joosy.Application", ->
|
2
2
|
|
3
3
|
beforeEach ->
|
4
|
-
sinon.stub(Joosy.Router, "
|
4
|
+
sinon.stub(Joosy.Router, "__setupRoutes")
|
5
5
|
@seedGround()
|
6
6
|
|
7
7
|
afterEach ->
|
8
|
-
Joosy.Router.
|
8
|
+
Joosy.Router.__setupRoutes.restore()
|
9
9
|
|
10
10
|
it "should initialize", ->
|
11
11
|
Joosy.Application.initialize 'app', '#application'
|
@@ -13,7 +13,7 @@ describe "Joosy.Application", ->
|
|
13
13
|
expect(Joosy.Application.selector).toEqual '#application'
|
14
14
|
expect(Joosy.Application.sandboxSelector).toMatch /#[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}/
|
15
15
|
expect($(Joosy.Application.sandboxSelector).length).toEqual 1
|
16
|
-
expect(Joosy.Router.
|
16
|
+
expect(Joosy.Router.__setupRoutes.callCount).toEqual 1
|
17
17
|
expect(Joosy.Application.name).toEqual 'app'
|
18
18
|
|
19
19
|
it "should set container", ->
|
@@ -19,8 +19,6 @@ describe "Joosy.Resource.REST", ->
|
|
19
19
|
expect(@Test.__buildSource()).toEqual 'uri/'
|
20
20
|
@Test.primary 'uid'
|
21
21
|
expect(@Test::__primaryKey).toEqual 'uid'
|
22
|
-
@Test.beforeLoad 'function'
|
23
|
-
expect(@Test::__beforeLoad).toEqual 'function'
|
24
22
|
|
25
23
|
it "should build source url based on entity name", ->
|
26
24
|
options =
|
@@ -26,20 +26,20 @@ describe "Joosy.Router", ->
|
|
26
26
|
expect(Joosy.Router.rawRoutes).toEqual map
|
27
27
|
|
28
28
|
it "should initialize on setup", ->
|
29
|
-
sinon.stub Joosy.Router, '
|
30
|
-
sinon.stub Joosy.Router, '
|
29
|
+
sinon.stub Joosy.Router, '__prepareRoutes'
|
30
|
+
sinon.stub Joosy.Router, '__respondRoute'
|
31
31
|
|
32
32
|
Joosy.Router.map map
|
33
|
-
Joosy.Router.
|
34
|
-
expect(Joosy.Router.
|
35
|
-
expect(Joosy.Router.
|
36
|
-
expect(Joosy.Router.
|
37
|
-
expect(Joosy.Router.
|
38
|
-
Joosy.Router.
|
39
|
-
Joosy.Router.
|
33
|
+
Joosy.Router.__setupRoutes()
|
34
|
+
expect(Joosy.Router.__prepareRoutes.callCount).toEqual 1
|
35
|
+
expect(Joosy.Router.__prepareRoutes.args[0][0]).toEqual map
|
36
|
+
expect(Joosy.Router.__respondRoute.callCount).toEqual 1
|
37
|
+
expect(Joosy.Router.__respondRoute.args[0][0]).toEqual location.hash
|
38
|
+
Joosy.Router.__prepareRoutes.restore()
|
39
|
+
Joosy.Router.__respondRoute.restore()
|
40
40
|
|
41
41
|
it "should prepare route", ->
|
42
|
-
route = Joosy.Router.
|
42
|
+
route = Joosy.Router.__prepareRoute "/such/a/long/long/url/:with/:plenty/:of/:params", "123"
|
43
43
|
|
44
44
|
expect(route).toEqual Object.extended
|
45
45
|
'^/?such/a/long/long/url/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$':
|
@@ -47,10 +47,10 @@ describe "Joosy.Router", ->
|
|
47
47
|
action: "123"
|
48
48
|
|
49
49
|
it "should cook routes", ->
|
50
|
-
sinon.stub Joosy.Router, '
|
50
|
+
sinon.stub Joosy.Router, '__respondRoute'
|
51
51
|
|
52
52
|
Joosy.Router.map map
|
53
|
-
Joosy.Router.
|
53
|
+
Joosy.Router.__setupRoutes()
|
54
54
|
|
55
55
|
expect(Joosy.Router.routes).toEqual Object.extended
|
56
56
|
'^/?/?$':
|
@@ -66,11 +66,11 @@ describe "Joosy.Router", ->
|
|
66
66
|
capture: ['more']
|
67
67
|
action: TestPage
|
68
68
|
|
69
|
-
Joosy.Router.
|
69
|
+
Joosy.Router.__respondRoute.restore()
|
70
70
|
|
71
71
|
it "should get route params", ->
|
72
|
-
route = Joosy.Router.
|
73
|
-
result = Joosy.Router.
|
72
|
+
route = Joosy.Router.__prepareRoute "/such/a/long/long/url/:with/:plenty/:of/:params", "123"
|
73
|
+
result = Joosy.Router.__paramsFromRouteMatch ['full regex match here', 1, 2, 3, 4], route.values().first()
|
74
74
|
|
75
75
|
expect(result).toEqual Object.extended
|
76
76
|
'with': 1
|
@@ -79,37 +79,37 @@ describe "Joosy.Router", ->
|
|
79
79
|
'params': 4
|
80
80
|
|
81
81
|
it "should build query params", ->
|
82
|
-
result = Joosy.Router.
|
82
|
+
result = Joosy.Router.__paramsFromQueryArray ["foo=bar", "bar=baz"]
|
83
83
|
|
84
84
|
expect(result).toEqual Object.extended
|
85
85
|
foo: 'bar'
|
86
86
|
bar: 'baz'
|
87
87
|
|
88
88
|
it "should respond routes", ->
|
89
|
-
sinon.stub Joosy.Router, '
|
89
|
+
sinon.stub Joosy.Router, '__respondRoute'
|
90
90
|
sinon.stub Joosy.Application, 'setCurrentPage'
|
91
91
|
|
92
92
|
Joosy.Router.map map
|
93
|
-
Joosy.Router.
|
93
|
+
Joosy.Router.__setupRoutes()
|
94
94
|
|
95
|
-
Joosy.Router.
|
95
|
+
Joosy.Router.__respondRoute.restore()
|
96
96
|
|
97
|
-
Joosy.Router.
|
97
|
+
Joosy.Router.__respondRoute '/'
|
98
98
|
expect(spies.root.callCount).toEqual 1
|
99
99
|
|
100
|
-
Joosy.Router.
|
100
|
+
Joosy.Router.__respondRoute '/page'
|
101
101
|
expect(Joosy.Application.setCurrentPage.callCount).toEqual 1
|
102
102
|
expect(Joosy.Application.setCurrentPage.args.last()).toEqual [TestPage, Object.extended()]
|
103
103
|
|
104
|
-
Joosy.Router.
|
104
|
+
Joosy.Router.__respondRoute '/section/page/1'
|
105
105
|
expect(spies.section.callCount).toEqual 1
|
106
106
|
expect(spies.section.args.last()).toEqual [Object.extended(id: '1')]
|
107
107
|
|
108
|
-
Joosy.Router.
|
108
|
+
Joosy.Router.__respondRoute '/section/page2/1&a=b'
|
109
109
|
expect(Joosy.Application.setCurrentPage.callCount).toEqual 2
|
110
110
|
expect(Joosy.Application.setCurrentPage.args.last()).toEqual [TestPage, Object.extended(more: '1', a: 'b')]
|
111
111
|
|
112
|
-
Joosy.Router.
|
112
|
+
Joosy.Router.__respondRoute '/thiswillneverbefound&a=b'
|
113
113
|
expect(spies.wildcard.callCount).toEqual 1
|
114
114
|
expect(spies.wildcard.args.last()).toEqual ['/thiswillneverbefound', Object.extended(a: 'b')]
|
115
115
|
|