joosy 0.1.0.alpha → 1.0.0.RC1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/.codoopts +5 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile +15 -2
  4. data/Gemfile.lock +102 -81
  5. data/Guardfile +16 -16
  6. data/LICENSE +22 -0
  7. data/MIT-LICENSE +2 -2
  8. data/README.md +118 -0
  9. data/app/assets/javascripts/joosy/core/application.js.coffee +53 -0
  10. data/app/assets/javascripts/joosy/core/form.js.coffee +338 -0
  11. data/app/assets/javascripts/joosy/core/helpers/form.js.coffee +72 -0
  12. data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +42 -0
  13. data/app/assets/javascripts/joosy/core/helpers/widgets.js.coffee +14 -0
  14. data/app/assets/javascripts/joosy/core/joosy.js.coffee +184 -0
  15. data/app/assets/javascripts/joosy/core/layout.js.coffee +168 -0
  16. data/app/assets/javascripts/joosy/core/modules/container.js.coffee +124 -0
  17. data/app/assets/javascripts/joosy/core/modules/events.js.coffee +122 -0
  18. data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +39 -0
  19. data/app/assets/javascripts/joosy/core/modules/log.js.coffee +36 -0
  20. data/app/assets/javascripts/joosy/core/modules/module.js.coffee +117 -0
  21. data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +200 -0
  22. data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +46 -0
  23. data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +87 -0
  24. data/app/assets/javascripts/joosy/core/page.js.coffee +387 -0
  25. data/app/assets/javascripts/joosy/core/preloader.js.coffee +13 -0
  26. data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +175 -0
  27. data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +303 -0
  28. data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +244 -0
  29. data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +24 -0
  30. data/app/assets/javascripts/joosy/core/router.js.coffee +201 -0
  31. data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +37 -0
  32. data/app/assets/javascripts/joosy/core/widget.js.coffee +85 -0
  33. data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +169 -0
  34. data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +56 -0
  35. data/{vendor → app}/assets/javascripts/joosy.js.coffee +0 -1
  36. data/app/helpers/joosy/sprockets_helper.rb +39 -12
  37. data/joosy.gemspec +4 -3
  38. data/lib/joosy/rails/engine.rb +12 -1
  39. data/lib/joosy/rails/version.rb +2 -2
  40. data/lib/joosy.rb +9 -0
  41. data/lib/rails/generators/joosy/application_generator.rb +15 -3
  42. data/lib/rails/generators/joosy/joosy_base.rb +2 -2
  43. data/lib/rails/generators/joosy/layout_generator.rb +8 -1
  44. data/lib/rails/generators/joosy/page_generator.rb +21 -6
  45. data/lib/rails/generators/joosy/preloader_generator.rb +14 -7
  46. data/lib/rails/generators/joosy/resource_generator.rb +29 -0
  47. data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +4 -0
  48. data/lib/rails/generators/joosy/templates/app/layouts/application.js.coffee +1 -0
  49. data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +1 -1
  50. data/lib/rails/generators/joosy/templates/app/pages/application.js.coffee +1 -1
  51. data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +3 -3
  52. data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +22 -0
  53. data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +2 -0
  54. data/lib/rails/generators/joosy/templates/app/routes.js.coffee +7 -1
  55. data/lib/rails/generators/joosy/templates/app/templates/layouts/application.jst.hamlc +2 -0
  56. data/lib/rails/generators/joosy/templates/app/templates/pages/welcome/index.jst.hamlc +7 -0
  57. data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +2 -2
  58. data/lib/rails/generators/joosy/templates/app.js.coffee +4 -0
  59. data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +9 -12
  60. data/lib/rails/generators/joosy/templates/app_resources_predefiner.js.coffee.erb +11 -0
  61. data/lib/rails/generators/joosy/templates/preload.html.erb +5 -6
  62. data/lib/rails/generators/joosy/templates/preload.html.haml +3 -5
  63. data/lib/rails/generators/joosy/widget_generator.rb +8 -1
  64. data/lib/rails/resources_with_joosy.rb +11 -0
  65. data/spec/javascripts/helpers/spec_helper.js.coffee +25 -0
  66. data/spec/javascripts/joosy/core/application_spec.js.coffee +40 -0
  67. data/spec/javascripts/joosy/core/form_spec.js.coffee +200 -0
  68. data/spec/javascripts/joosy/core/helpers/forms_spec.js.coffee +103 -0
  69. data/spec/javascripts/joosy/core/helpers/view_spec.js.coffee +10 -0
  70. data/spec/javascripts/joosy/core/joosy_spec.js.coffee +97 -0
  71. data/spec/javascripts/joosy/core/layout_spec.js.coffee +50 -0
  72. data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +32 -27
  73. data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +55 -18
  74. data/spec/javascripts/joosy/core/modules/filters_spec.js.coffee +28 -27
  75. data/spec/javascripts/joosy/core/modules/log_spec.js.coffee +3 -3
  76. data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +6 -15
  77. data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +203 -0
  78. data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +12 -7
  79. data/spec/javascripts/joosy/core/modules/widget_manager_spec.js.coffee +31 -17
  80. data/spec/javascripts/joosy/core/page_spec.js.coffee +178 -0
  81. data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +84 -0
  82. data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +149 -0
  83. data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +31 -0
  84. data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +171 -0
  85. data/spec/javascripts/joosy/core/router_spec.js.coffee +143 -0
  86. data/spec/javascripts/joosy/core/templaters/rails_jst_spec.js.coffee +25 -0
  87. data/spec/javascripts/joosy/core/widget_spec.js.coffee +40 -0
  88. data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +36 -0
  89. data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +16 -0
  90. data/spec/javascripts/support/assets/coolface.jpg +0 -0
  91. data/spec/javascripts/support/assets/okay.jpg +0 -0
  92. data/spec/javascripts/support/assets/test.js +1 -0
  93. data/spec/javascripts/support/sinon-ie-1.3.1.js +82 -0
  94. data/vendor/assets/javascripts/jquery.form.js +978 -963
  95. data/vendor/assets/javascripts/metamorph.js +409 -0
  96. data/vendor/assets/javascripts/sugar.js +1057 -366
  97. metadata +95 -50
  98. data/README.rdoc +0 -3
  99. data/lib/joosy/forms.rb +0 -47
  100. data/lib/joosy-rails.rb +0 -5
  101. data/lib/rails/generators/joosy/templates/preload.html.slim +0 -21
  102. data/tmp/javascripts/.gitignore +0 -1
  103. data/tmp/spec/javascripts/helpers/.gitignore +0 -1
  104. data/vendor/assets/javascripts/base64.js +0 -135
  105. data/vendor/assets/javascripts/inflection.js +0 -656
  106. data/vendor/assets/javascripts/joosy/core/application.js.coffee +0 -26
  107. data/vendor/assets/javascripts/joosy/core/form.js.coffee +0 -87
  108. data/vendor/assets/javascripts/joosy/core/joosy.js.coffee +0 -62
  109. data/vendor/assets/javascripts/joosy/core/layout.js.coffee +0 -38
  110. data/vendor/assets/javascripts/joosy/core/modules/container.js.coffee +0 -51
  111. data/vendor/assets/javascripts/joosy/core/modules/events.js.coffee +0 -17
  112. data/vendor/assets/javascripts/joosy/core/modules/filters.js.coffee +0 -39
  113. data/vendor/assets/javascripts/joosy/core/modules/log.js.coffee +0 -12
  114. data/vendor/assets/javascripts/joosy/core/modules/module.js.coffee +0 -28
  115. data/vendor/assets/javascripts/joosy/core/modules/time_manager.js.coffee +0 -23
  116. data/vendor/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +0 -45
  117. data/vendor/assets/javascripts/joosy/core/page.js.coffee +0 -136
  118. data/vendor/assets/javascripts/joosy/core/resource/rest.js.coffee +0 -69
  119. data/vendor/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +0 -42
  120. data/vendor/assets/javascripts/joosy/core/router.js.coffee +0 -75
  121. data/vendor/assets/javascripts/joosy/core/widget.js.coffee +0 -35
  122. data/vendor/assets/javascripts/joosy/preloader/development.js.coffee +0 -27
  123. data/vendor/assets/javascripts/joosy/preloader/production.js.coffee +0 -84
@@ -1,75 +0,0 @@
1
- #= require joosy/core/joosy
2
-
3
- Joosy.Router =
4
- rawRoutes: Object.extended()
5
- routes: Object.extended()
6
-
7
- map: (routes) ->
8
- @rawRoutes.merge routes
9
-
10
- setupRoutes: ->
11
- @prepareRoutes @rawRoutes
12
-
13
- @respondRoute(location.hash)
14
- $(window).hashchange => @respondRoute(location.hash)
15
-
16
- prepareRoutes: (routes, namespace='') ->
17
- if !namespace && routes[404]
18
- @wildcardAction = routes[404]
19
- delete routes[404]
20
- routes.each (path, response) =>
21
- path = (namespace+path).replace(/\/{2,}/, '/')
22
- if response && (typeof(response) == 'function' || response.prototype?)
23
- @prepareRoute path, response
24
- else
25
- @prepareRoutes Object.extended(response), path
26
-
27
- prepareRoute: (path, response) ->
28
- matchPath = path.replace(/\/:([^\/]+)/g, '/([^/]+)').replace(/^\/?/, '^/?').replace(/\/?$/, '/?$')
29
- @routes[matchPath] =
30
- capture : (path.match(/\/:[^\/]+/g) || []).map((str) -> str.substr(2))
31
- action : response
32
-
33
- respondRoute: (hash) ->
34
- fullPath = hash.replace(/^#!?/, '')
35
-
36
- if @currentPath != fullPath
37
- @currentPath = fullPath
38
- found = false
39
-
40
- paramStr = fullPath.split('&')
41
- path = paramStr.shift()
42
- urlParams = @getUrlParams(paramStr)
43
-
44
- for regex, route of @routes when @routes.hasOwnProperty(regex)
45
- if vals = path.match(new RegExp(regex))
46
- params = @getRouteParams(vals, route).merge urlParams
47
-
48
- if !Joosy.Module.hasAncestor(route.action, Joosy.Page)
49
- route.action.call(this, params)
50
- else
51
- Joosy.Application.setCurrentPage(route.action, params)
52
- found = true
53
- break
54
-
55
- if !found && @wildcardAction
56
- @wildcardAction(path, urlParams)
57
-
58
- getRouteParams: (vals, route) ->
59
- params = Object.extended()
60
- vals.shift()
61
- for param in route.capture
62
- params[param] = vals.shift()
63
- return params
64
-
65
- getUrlParams: (paramStr) ->
66
- params = {}
67
- if paramStr
68
- $.each paramStr, () ->
69
- if @ != ''
70
- pair = @.split '='
71
- params[pair[0]] = pair[1]
72
- return params
73
-
74
- navigate: (to) ->
75
- location.hash = '!'+to
@@ -1,35 +0,0 @@
1
- #= require joosy/core/joosy
2
- #= require joosy/core/modules/module
3
- #= require joosy/core/modules/log
4
- #= require joosy/core/modules/events
5
- #= require joosy/core/modules/container
6
- #= require joosy/core/modules/filters
7
-
8
- class Joosy.Widget extends Joosy.Module
9
- @include Joosy.Modules.Log
10
- @include Joosy.Modules.Events
11
- @include Joosy.Modules.Container
12
- @include Joosy.Modules.Filters
13
-
14
- __render: false
15
-
16
- @render: (callback) ->
17
- @::__render = callback
18
-
19
- setInterval: (args...) ->
20
- @parent.setInterval(args...)
21
-
22
- setTimeout: (args...) ->
23
- @parent.setTimeout(args...)
24
-
25
- navigate: (args...) -> Joosy.Router.navigate(args...)
26
-
27
- __load: (@parent, @container) ->
28
- @__render?()
29
- @refreshElements()
30
- @__delegateEvents()
31
- @__runAfterLoads()
32
- return @
33
-
34
- __unload: ->
35
- @__runAfterUnloads()
@@ -1,27 +0,0 @@
1
- @Preloader =
2
- receive: (url, callback) ->
3
- head = document.getElementsByTagName("head")[0]
4
- script = document.createElement("script")
5
- script.src = url# + (if url.match(/\?/) then '&' else '?') + "rand=" + Math.random()
6
-
7
- done = false
8
-
9
- proceed = ->
10
- if ( !done && (!this.readyState ||
11
- this.readyState == "loaded" || this.readyState == "complete") )
12
-
13
- done = true and callback() if callback
14
- script.onload = script.onreadystatechange = null
15
-
16
- script.onload = script.onreadystatechange = proceed
17
-
18
- head.appendChild(script)
19
- return undefined
20
-
21
- load: (libraries) ->
22
- @start?.call window
23
-
24
- if libraries.length > 0
25
- @receive libraries.shift()[0], => @load(libraries)
26
- else
27
- @complete?.call window
@@ -1,84 +0,0 @@
1
- #= require base64
2
-
3
- window.globalEval = (src) ->
4
- if window.execScript
5
- window.execScript src
6
- else
7
- fn = ->
8
- window.eval.call window,src
9
- fn()
10
-
11
- @Preloader =
12
- force: false
13
- prefix: "cache:"
14
-
15
- libraries: []
16
- counter: 0
17
-
18
- complete: false
19
-
20
- ajax: (url, size, callback) ->
21
- x = this.ActiveXObject
22
- x = new (if x then x else XMLHttpRequest)('Microsoft.XMLHTTP')
23
-
24
- x.open('GET', url, 1)
25
- x.setRequestHeader('Content-type','application/x-www-form-urlencoded')
26
-
27
- if @progress
28
- x.onprogress = (event) =>
29
- total = if size then size else event.total
30
- @progress.call window, Math.round(event.loaded / total * 100 * @counter / @libraries.length), event
31
-
32
- x.onreadystatechange = () -> callback(x) if callback? && x.readyState > 3
33
- x.send()
34
-
35
- restore: ->
36
- for name, i in @libraries
37
- code = window.localStorage.getItem(name)
38
- window.globalEval if window.navigator.appName == "Microsoft Internet Explorer" then Base64.decode(code) else code
39
- @complete?.call window, (true)
40
-
41
- download: (libraries) ->
42
- if libraries.length > 0
43
- @counter += 1
44
-
45
- lib = libraries.shift()
46
- url = lib[0]
47
- size = lib[1]
48
-
49
- @ajax url, size, (xhr) =>
50
- code = xhr.responseText
51
- window.localStorage.setItem @prefix+url, (if window.navigator.appName == "Microsoft Internet Explorer" then Base64.encode(code) else code)
52
- window.globalEval xhr.responseText
53
- @download(libraries)
54
- else
55
- @clean()
56
- @complete?.call window, false
57
-
58
- load: (libraries) ->
59
- @libraries = libraries.slice()
60
-
61
- for lib, i in @libraries
62
- @libraries[i] = @prefix+lib[0]
63
-
64
- if !@force && @check()
65
- @restore()
66
- else
67
- @start?.call window
68
- @download(libraries)
69
-
70
- check: ->
71
- flag = true
72
- for name, i in @libraries
73
- flag &&= window.localStorage.getItem(name)?
74
- flag
75
-
76
- clean: ->
77
- removed = 0
78
-
79
- for element, i in window.localStorage
80
- key = window.localStorage.key(i-removed)
81
-
82
- if key.indexOf(@prefix) == 0 && @libraries.indexOf(key) < 0
83
- window.localStorage.removeItem(key)
84
- removed += 1