joosy 1.2.0.alpha.41 → 1.2.0.alpha.51

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gruntfile.coffee +27 -7
  4. data/bin/joosy +1 -1
  5. data/bower.json +3 -2
  6. data/build/joosy/extensions/preloaders.js +189 -0
  7. data/build/joosy/extensions/resources-form.js +588 -0
  8. data/build/joosy/extensions/resources.js +673 -0
  9. data/build/joosy.js +2395 -0
  10. data/{src/joosy/generators → generators}/base.coffee +2 -2
  11. data/{src/joosy/generators → generators/command}/command.coffee +16 -3
  12. data/generators/command/help.coffee +38 -0
  13. data/{src/joosy/generators → generators}/layout.coffee +0 -0
  14. data/{src/joosy/generators → generators}/page.coffee +0 -0
  15. data/{src/joosy/generators → generators}/project/base.coffee +2 -4
  16. data/{src/joosy/generators → generators}/project/standalone.coffee +4 -3
  17. data/{src/joosy/generators → generators}/project.coffee +0 -0
  18. data/generators/templates/application/base/application.coffee +13 -0
  19. data/{templates → generators/templates}/application/base/helpers/application.coffee +0 -0
  20. data/{templates → generators/templates}/application/base/layouts/application.coffee +0 -0
  21. data/{templates → generators/templates}/application/base/pages/application.coffee +0 -0
  22. data/{templates → generators/templates}/application/base/pages/welcome/index.coffee +0 -0
  23. data/{templates → generators/templates}/application/base/routes.coffee +0 -0
  24. data/{templates → generators/templates}/application/base/templates/layouts/application.jst.hamlc +0 -0
  25. data/{templates → generators/templates}/application/base/templates/pages/welcome/index.jst.hamlc +0 -0
  26. data/{templates → generators/templates}/application/standalone/Gruntfile.coffee +1 -0
  27. data/{templates → generators/templates}/application/standalone/Procfile +0 -0
  28. data/{templates → generators/templates}/application/standalone/_gitignore +0 -0
  29. data/generators/templates/application/standalone/bower.json +17 -0
  30. data/{templates → generators/templates}/application/standalone/package.json +0 -0
  31. data/{templates → generators/templates}/application/standalone/source/haml/index.haml +0 -0
  32. data/{templates → generators/templates}/application/standalone/source/stylesheets/application.styl +0 -0
  33. data/{templates → generators/templates}/layout/basic.coffee +0 -0
  34. data/{templates → generators/templates}/layout/namespaced.coffee +0 -0
  35. data/{templates → generators/templates}/page/basic.coffee +0 -0
  36. data/{templates → generators/templates}/page/namespaced.coffee +0 -0
  37. data/{templates → generators/templates}/widget/basic.coffee +0 -0
  38. data/{templates → generators/templates}/widget/namespaced.coffee +0 -0
  39. data/{src/joosy/generators → generators}/widget.coffee +0 -0
  40. data/lib/joosy.rb +3 -3
  41. data/package.json +2 -3
  42. data/source/joosy/application.coffee +95 -0
  43. data/source/joosy/events/namespace.coffee +24 -0
  44. data/{src → source}/joosy/extensions/preloaders/caching.coffee +0 -0
  45. data/{src → source}/joosy/extensions/preloaders/index.coffee +0 -0
  46. data/{src → source}/joosy/extensions/preloaders/inline.coffee +0 -0
  47. data/{src → source}/joosy/extensions/resources/base.coffee +16 -8
  48. data/{src → source}/joosy/extensions/resources/collection.coffee +0 -0
  49. data/{src → source}/joosy/extensions/resources/index.coffee +0 -0
  50. data/{src → source}/joosy/extensions/resources/rest.coffee +0 -0
  51. data/{src → source}/joosy/extensions/resources/rest_collection.coffee +0 -0
  52. data/{src → source}/joosy/extensions/resources-form/form.coffee +18 -18
  53. data/{src → source}/joosy/extensions/resources-form/helpers/form.coffee +6 -6
  54. data/{src → source}/joosy/extensions/resources-form/index.coffee +0 -0
  55. data/source/joosy/helpers/routes.coffee +10 -0
  56. data/source/joosy/helpers/view.coffee +115 -0
  57. data/{src/joosy/core → source/joosy}/helpers/widgets.coffee +1 -1
  58. data/{src/joosy/core → source/joosy}/joosy.coffee +59 -19
  59. data/source/joosy/layout.coffee +73 -0
  60. data/{src/joosy/core → source/joosy}/module.coffee +7 -2
  61. data/{src/joosy/core/modules/container.coffee → source/joosy/modules/dom.coffee} +24 -17
  62. data/source/joosy/modules/events.coffee +156 -0
  63. data/source/joosy/modules/filters.coffee +67 -0
  64. data/{src/joosy/core → source/joosy}/modules/log.coffee +7 -3
  65. data/source/joosy/modules/page/scrolling.coffee +51 -0
  66. data/source/joosy/modules/page/title.coffee +18 -0
  67. data/{src/joosy/core → source/joosy}/modules/renderer.coffee +12 -13
  68. data/{src/joosy/core → source/joosy}/modules/time_manager.coffee +5 -1
  69. data/{src/joosy/core → source/joosy}/modules/widgets_manager.coffee +9 -5
  70. data/source/joosy/page.coffee +68 -0
  71. data/{src/joosy/core → source/joosy}/resources/watcher.coffee +5 -1
  72. data/source/joosy/router.coffee +305 -0
  73. data/{src/joosy/core → source/joosy}/templaters/jst.coffee +10 -7
  74. data/source/joosy/widget.coffee +385 -0
  75. data/source/joosy.coffee +1 -0
  76. data/{src/vendor → source}/metamorph.coffee +0 -0
  77. data/spec/helpers/matchers.coffee +8 -1
  78. data/spec/joosy/core/application_spec.coffee +121 -20
  79. data/spec/joosy/core/helpers/view_spec.coffee +3 -3
  80. data/spec/joosy/core/helpers/widgets_spec.coffee +3 -6
  81. data/spec/joosy/core/joosy_spec.coffee +0 -5
  82. data/spec/joosy/core/layout_spec.coffee +2 -28
  83. data/spec/joosy/core/modules/dom_spec.coffee +133 -0
  84. data/spec/joosy/core/modules/events_spec.coffee +16 -9
  85. data/spec/joosy/core/modules/filters_spec.coffee +232 -89
  86. data/spec/joosy/core/modules/log_spec.coffee +2 -2
  87. data/spec/joosy/core/modules/renderer_spec.coffee +8 -4
  88. data/spec/joosy/core/page_spec.coffee +2 -201
  89. data/spec/joosy/core/router_spec.coffee +295 -233
  90. data/spec/joosy/core/templaters/jst_spec.coffee +1 -1
  91. data/spec/joosy/core/widget_spec.coffee +373 -34
  92. data/spec/joosy/environments/amd_spec.coffee +38 -0
  93. data/spec/joosy/environments/global_spec.coffee +21 -0
  94. data/spec/joosy/extensions/form/form_spec.coffee +18 -18
  95. data/spec/joosy/extensions/form/helpers/forms_spec.coffee +1 -1
  96. data/spec/joosy/extensions/resources/base_spec.coffee +23 -11
  97. data/tasks/joosy.coffee +6 -9
  98. metadata +75 -69
  99. data/lib/extensions/preloaders.js +0 -193
  100. data/lib/extensions/resources-form.js +0 -592
  101. data/lib/extensions/resources.js +0 -675
  102. data/lib/joosy.js +0 -2199
  103. data/spec/joosy/core/modules/container_spec.coffee +0 -153
  104. data/spec/joosy/core/modules/widget_manager_spec.coffee +0 -96
  105. data/src/joosy/core/application.coffee +0 -59
  106. data/src/joosy/core/helpers/view.coffee +0 -52
  107. data/src/joosy/core/layout.coffee +0 -174
  108. data/src/joosy/core/modules/events.coffee +0 -188
  109. data/src/joosy/core/modules/filters.coffee +0 -42
  110. data/src/joosy/core/page.coffee +0 -383
  111. data/src/joosy/core/router.coffee +0 -313
  112. data/src/joosy/core/widget.coffee +0 -88
  113. data/src/joosy.coffee +0 -1
  114. data/templates/application/base/application.coffee +0 -9
  115. data/templates/application/standalone/bower.json +0 -7
@@ -1,313 +0,0 @@
1
- #= require joosy/core/joosy
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
- # @mixin
17
- #
18
- Joosy.Router =
19
- #
20
- # The Object containing route parts in keys and pages/lambdas in values
21
- #
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
- #
28
- routes: Object.extended()
29
-
30
- #
31
- # The regexp to restrict the next loading url. By default set to false and
32
- # therefore no restrictions apply.
33
- #
34
- restrictPattern: false
35
-
36
- #
37
- # TODO: Write readme
38
- #
39
- __namespace: ""
40
- __asNamespace: ""
41
-
42
- #
43
- # Global url prefix
44
- #
45
- prefix: ''
46
-
47
- #
48
- # Set the restriction pattern. If the requested url does not match this it
49
- # will not load. Set `false` to avoid check.
50
- #
51
- restrict: (@restrictPattern) ->
52
-
53
- #
54
- # Clears the routes
55
- #
56
- reset: ->
57
- @rawRoutes = Object.extended()
58
- @routes = Object.extended()
59
- @__namespace = ""
60
- @__asNamespace = ""
61
-
62
-
63
- #
64
- # Draws the routes similar to Ruby on Rails
65
- #
66
- # @param [Function] block callback for child commands
67
- #
68
- draw: (block)->
69
- block.call(this) if Object.isFunction(block)
70
-
71
- #
72
- # Registers the set of raw routes
73
- # This method will only store routes and will not make them act immediately
74
- # Routes get registered only once at system initialization during #__setupRoutes call
75
- #
76
- # @param [Object] routes Set of routes in inner format (see class description)
77
- #
78
- map: (routes) ->
79
- Joosy.Module.merge @rawRoutes, routes
80
-
81
- #
82
- # Changes current hash and therefore triggers new route loading
83
- # to be loaded
84
- #
85
- # @param [String] to Route to navigate to
86
- #
87
- # @option options [Boolean] respond If false just changes hash without responding
88
- # @option options [Boolean] replaceState If true uses replaces history entry instead of adding. Works only in browsers supporting history.pushState
89
- #
90
- navigate: (to, options={}) ->
91
- path = to
92
- path = path.substr(1) if path[0] == '#'
93
- path = @prefix + path unless path.startsWith(@prefix)
94
-
95
- if options.respond != false
96
- location.hash = path
97
- else
98
- if !history.pushState
99
- @__ignoreRequest = to
100
- location.hash = path
101
- setTimeout (=> @__ignoreRequest = false), 0
102
- else
103
- history[if options.replaceState then 'replaceState' else 'pushState'] {}, '', '#'+path
104
-
105
- #
106
- # Match route (ads it to @rawRoutes)
107
- #
108
- # @param [String] route similar to ones sent in map hash
109
- #
110
- # @param options [String] to function to which the route routes
111
- # @option options [String] as name of the route, used for reverse routing
112
- #
113
- match: (route, options={}) ->
114
- if @__asNamespace
115
- as = @__asNamespace + options["as"].capitalize()
116
- else
117
- as = options["as"]
118
-
119
- routeName = @__namespace + route
120
-
121
- map = {}
122
- map[route] = options["to"]
123
-
124
- Joosy.Module.merge @rawRoutes, map
125
-
126
- @__injectReverseUrl(as, routeName)
127
-
128
- #
129
- # Shortcut to match "/"
130
- #
131
- # @param options [String] to function to which the route routes
132
- # @option options [String] as name of the route, used for reverse routing
133
- # default it is "root"
134
- #
135
- root: (options={}) ->
136
- as = options["as"] || "root"
137
- @match("/", to: options["to"], as: as)
138
-
139
- #
140
- # Routes the 404
141
- #
142
- # @param options [String] to function to which the route routes
143
- #
144
- notFound: (options={}) ->
145
- @match(404, to: options["to"])
146
-
147
- #
148
- # Namespaces a match route
149
- #
150
- # @param [String] name name of the namespace, prefixes other commands
151
- #
152
- # @option [Hash] options "as", prefixes all other "as" commands
153
- # @param [Function] block callback for child commands
154
- namespace: (name, options={}, block) ->
155
- if Object.isFunction(options)
156
- block = options
157
- options = {}
158
-
159
- newScope = $.extend({}, this)
160
- newScope.rawRoutes = {}
161
- newScope.__namespace += name
162
- newScope.__asNamespace += "#{options["as"]}" if options["as"]
163
- block.call(newScope) if Object.isFunction(block)
164
- @rawRoutes[name] = newScope.rawRoutes
165
-
166
- #
167
- # Inits the routing system and loads the current route
168
- # Binds the window hashchange event and therefore should only be called once
169
- # during system startup
170
- #
171
- __setupRoutes: ->
172
- $(window).on 'hashchange', =>
173
- unless @__ignoreRequest && location.hash.match(@__ignoreRequest)
174
- @__respondRoute location.hash
175
-
176
- @__prepareRoutes @rawRoutes
177
- @__respondRoute location.hash
178
-
179
- #
180
- # Compiles routes to map object
181
- # Object will contain regexp string as key and lambda/Page to load as value
182
- #
183
- # @param [Object] routes Raw routes to prepare
184
- # @param [String] namespace Inner cursor for recursion
185
- #
186
- __prepareRoutes: (routes, namespace='') ->
187
- if !namespace && routes[404]
188
- @wildcardAction = routes[404]
189
- delete routes[404]
190
-
191
- Object.each routes, (path, response) =>
192
- path = (namespace + path).replace /\/{2,}/, '/'
193
- if response && (Object.isFunction(response) || response.prototype?)
194
- Joosy.Module.merge @routes, @__prepareRoute(path, response)
195
- else
196
- @__prepareRoutes response, path
197
-
198
- #
199
- # Compiles one single route
200
- #
201
- # @param [String] path Full path from raw route
202
- # @param [Joosy.Page] response Page that should be loaded at this route
203
- # @param [Function] response Lambda to call at this route
204
- #
205
- __prepareRoute: (path, response) ->
206
- matchPath = path.replace(/\/:([^\/]+)/g, '/([^/]+)').replace(/^\/?/, '^/?').replace(/\/?$/, '/?$')
207
- result = Object.extended()
208
-
209
- result[matchPath] =
210
- capture: (path.match(/\/:[^\/]+/g) || []).map (str) ->
211
- str.substr 2
212
- action: response
213
- result
214
-
215
- #
216
- # Searches the corresponding route through compiled routes
217
- #
218
- # @param [String] hash Hash value to search route for
219
- #
220
- __respondRoute: (hash) ->
221
- Joosy.Modules.Log.debug "Router> Answering '#{hash}'"
222
- fullPath = hash.replace ///^\#(#{@prefix})?///, ''
223
-
224
- if (@restrictPattern && fullPath.match(@restrictPattern) == null)
225
- @trigger 'restricted', fullPath
226
- return
227
- else
228
- @trigger 'responded', fullPath
229
-
230
- @currentPath = fullPath
231
- found = false
232
- queryArray = fullPath.split '&'
233
- path = queryArray.shift()
234
- urlParams = @__paramsFromQueryArray queryArray
235
-
236
- for regex, route of @routes when @routes.hasOwnProperty regex
237
- if vals = path.match new RegExp(regex)
238
- params = @__paramsFromRouteMatch(vals, route).merge urlParams
239
-
240
- if Joosy.Module.hasAncestor route.action, Joosy.Page
241
- Joosy.Application.setCurrentPage route.action, params
242
- else
243
- route.action.call this, params
244
-
245
- found = true
246
- break
247
-
248
- if !found && @wildcardAction?
249
- if Joosy.Module.hasAncestor @wildcardAction, Joosy.Page
250
- Joosy.Application.setCurrentPage @wildcardAction, urlParams
251
- else
252
- @wildcardAction path, urlParams
253
-
254
- #
255
- # Collects params from route placeholders (/foo/:placeholder)
256
- #
257
- # @param [Array] vals Array of value gathered by regexp
258
- # @param [Object] route Compiled route
259
- # @returns [Object] Hash of params
260
- #
261
- __paramsFromRouteMatch: (vals, route) ->
262
- params = Object.extended()
263
-
264
- vals.shift()
265
- for param in route.capture
266
- params[param] = vals.shift()
267
-
268
- params
269
-
270
- #
271
- # Collects params from query routes (/foo/&a=b)
272
- #
273
- # @param [Array] queryArray Array of query string split by '&' sign
274
- # @returns [Object] Hash of params
275
- #
276
- __paramsFromQueryArray: (queryArray) ->
277
- params = Object.extended()
278
-
279
- if queryArray
280
- $.each queryArray, ->
281
- unless @isBlank()
282
- pair = @split '='
283
- params[pair[0]] = pair[1]
284
-
285
- params
286
-
287
- #
288
- # Injects reverse routing function into global namespace
289
- # @param [String] as The name for the route, ex: for "projects"
290
- # builds "projects_url" and "projects_path" functions
291
- # @param [String] route Entire route, joined by namespaces, ex:
292
- # "/projects/":
293
- # "/:id" :
294
- # "/edit": TestPage
295
- # joins to "/projects/:id/edit"
296
- #
297
- __injectReverseUrl: (as, route) ->
298
- return if as == undefined
299
-
300
- fnc = (options) =>
301
- url = route
302
- (route.match(/\/:[^\/]+/g) || []).each (str) ->
303
- url = url.replace(str.substr(1), options[str.substr(2)])
304
- "##{@prefix}#{url}"
305
-
306
- Joosy.Helpers.Application["#{as}Path"] = (options) ->
307
- fnc(options)
308
-
309
- Joosy.Helpers.Application["#{as}Url"] = (options) ->
310
- url = 'http://' + window.location.host + window.location.pathname
311
- "#{url}#{fnc(options)}"
312
-
313
- Joosy.Module.merge Joosy.Router, Joosy.Modules.Events
@@ -1,88 +0,0 @@
1
- #= require joosy/core/joosy
2
- #= require joosy/core/modules/log
3
- #= require joosy/core/modules/events
4
- #= require joosy/core/modules/container
5
- #= require joosy/core/modules/renderer
6
- #= require joosy/core/modules/filters
7
-
8
- #
9
- # Base class for all of your Joosy Layouts.
10
- #
11
- # @todo Add link to the 5th chapter of guides here.
12
- #
13
- # @example Sample widget
14
- # class @FooWidget extends Joosy.Widget
15
- # @view 'foo'
16
- #
17
- # @include Joosy.Modules.Log
18
- # @include Joosy.Modules.Events
19
- # @include Joosy.Modules.Container
20
- # @include Joosy.Modules.Renderer
21
- # @include Joosy.Modules.Filters
22
- # @include Joosy.Modules.TimeManager
23
- #
24
- class Joosy.Widget extends Joosy.Module
25
- @include Joosy.Modules.Log
26
- @include Joosy.Modules.Events
27
- @include Joosy.Modules.Container
28
- @include Joosy.Modules.Renderer
29
- @include Joosy.Modules.Filters
30
- @include Joosy.Modules.TimeManager
31
- @include Joosy.Modules.WidgetsManager
32
-
33
- #
34
- # By default widget will not render on load
35
- #
36
- __renderDefault: false
37
-
38
- #
39
- # Initial data that will be passed to view on load
40
- # False (and not {}) by default to have a chance to check if data was loaded
41
- #
42
- data: false
43
-
44
- #
45
- # Proxy to Joosy.Router.navigate
46
- #
47
- navigate: (args...) ->
48
- Joosy.Router.navigate args...
49
-
50
- #
51
- # This is required by {Joosy.Modules.Renderer}
52
- # Sets the base template dir to app_name/templates/widgets
53
- #
54
- __renderSection: ->
55
- 'widgets'
56
-
57
- #
58
- # Widget bootstrap proccess
59
- #
60
- # * Rendering (if required)
61
- # * {Joosy.Modules.Container.__assignElements}
62
- # * {Joosy.Modules.Container.__delegateEvents}
63
- #
64
- # @param [Joosy.Page, Joosy.Layout] Page or Layout to attach to
65
- # @param [jQuery] container Container to attach to
66
- #
67
- __load: (@parent, @container, render=true) ->
68
- @__runBeforeLoads()
69
- if render && @__renderDefault
70
- @swapContainer @container, @__renderDefault(@data || {})
71
- @__assignElements()
72
- @__delegateEvents()
73
- @__setupWidgets()
74
- @__runAfterLoads()
75
-
76
- this
77
-
78
- #
79
- # Layout destruction proccess.
80
- #
81
- # * {Joosy.Modules.TimeManager.__clearTime}
82
- # * {Joosy.Modules.Renderer.__removeMetamorphs}
83
- #
84
- __unload: ->
85
- @__clearTime()
86
- @__unloadWidgets()
87
- @__removeMetamorphs()
88
- @__runAfterUnloads()
data/src/joosy.coffee DELETED
@@ -1 +0,0 @@
1
- #= require_tree ./joosy/core
@@ -1,9 +0,0 @@
1
- <%= dependencies %>
2
- #
3
- #= require joosy
4
- #
5
- #= require_tree ./
6
- #= require_self
7
-
8
- $ ->
9
- Joosy.Application.initialize '<%= application %>', 'body'
@@ -1,7 +0,0 @@
1
- {
2
- "dependencies": {
3
- "jquery": "~2.0.2",
4
- "sugar": "~1.3.9",
5
- "jquery-form": "~3.32.0-2013.04.09"
6
- }
7
- }