joosy 0.1.0.RC3 → 0.1.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -2
- data/Gemfile +2 -13
- data/Gemfile.lock +62 -80
- data/Guardfile +15 -21
- data/MIT-LICENSE +2 -2
- data/README.rdoc +3 -0
- data/app/helpers/joosy/sprockets_helper.rb +11 -23
- data/joosy.gemspec +3 -3
- data/lib/joosy/forms.rb +12 -2
- data/lib/joosy/rails/engine.rb +1 -9
- data/lib/joosy/rails/version.rb +2 -2
- data/lib/joosy-rails.rb +5 -0
- data/lib/rails/generators/joosy/application_generator.rb +3 -13
- data/lib/rails/generators/joosy/joosy_base.rb +2 -2
- data/lib/rails/generators/joosy/layout_generator.rb +1 -8
- data/lib/rails/generators/joosy/page_generator.rb +6 -21
- data/lib/rails/generators/joosy/preloader_generator.rb +7 -14
- data/lib/rails/generators/joosy/templates/app/layouts/application.js.coffee +0 -1
- data/lib/rails/generators/joosy/templates/app/layouts/template.js.coffee +1 -1
- data/lib/rails/generators/joosy/templates/app/pages/application.js.coffee +1 -1
- data/lib/rails/generators/joosy/templates/app/pages/template.js.coffee +3 -3
- data/lib/rails/generators/joosy/templates/app/routes.js.coffee +1 -7
- data/lib/rails/generators/joosy/templates/app/widgets/template.js.coffee +2 -2
- data/lib/rails/generators/joosy/templates/app.js.coffee +0 -3
- data/lib/rails/generators/joosy/templates/app_preloader.js.coffee.erb +12 -9
- data/lib/rails/generators/joosy/templates/preload.html.erb +6 -5
- data/lib/rails/generators/joosy/templates/preload.html.haml +5 -3
- data/lib/rails/generators/joosy/templates/preload.html.slim +21 -0
- data/lib/rails/generators/joosy/widget_generator.rb +1 -8
- data/spec/javascripts/helpers/spec_helper.js.coffee +0 -20
- data/spec/javascripts/joosy/core/modules/container_spec.js.coffee +27 -24
- data/spec/javascripts/joosy/core/modules/events_spec.js.coffee +18 -42
- data/spec/javascripts/joosy/core/modules/filters_spec.js.coffee +27 -27
- data/spec/javascripts/joosy/core/modules/log_spec.js.coffee +3 -3
- data/spec/javascripts/joosy/core/modules/module_spec.js.coffee +15 -6
- data/spec/javascripts/joosy/core/modules/time_manager_spec.js.coffee +7 -12
- data/spec/javascripts/joosy/core/modules/widget_manager_spec.js.coffee +17 -31
- data/tmp/javascripts/.gitignore +1 -0
- data/tmp/spec/javascripts/helpers/.gitignore +1 -0
- data/vendor/assets/javascripts/base64.js +135 -0
- data/vendor/assets/javascripts/joosy/core/application.js.coffee +26 -0
- data/vendor/assets/javascripts/joosy/core/form.js.coffee +87 -0
- data/vendor/assets/javascripts/joosy/core/joosy.js.coffee +62 -0
- data/vendor/assets/javascripts/joosy/core/layout.js.coffee +38 -0
- data/vendor/assets/javascripts/joosy/core/modules/container.js.coffee +51 -0
- data/vendor/assets/javascripts/joosy/core/modules/events.js.coffee +17 -0
- data/vendor/assets/javascripts/joosy/core/modules/filters.js.coffee +39 -0
- data/vendor/assets/javascripts/joosy/core/modules/log.js.coffee +12 -0
- data/vendor/assets/javascripts/joosy/core/modules/module.js.coffee +28 -0
- data/vendor/assets/javascripts/joosy/core/modules/time_manager.js.coffee +23 -0
- data/vendor/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +45 -0
- data/vendor/assets/javascripts/joosy/core/page.js.coffee +136 -0
- data/vendor/assets/javascripts/joosy/core/resource/rest.js.coffee +69 -0
- data/vendor/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +42 -0
- data/vendor/assets/javascripts/joosy/core/router.js.coffee +75 -0
- data/vendor/assets/javascripts/joosy/core/widget.js.coffee +35 -0
- data/vendor/assets/javascripts/joosy/preloader/development.js.coffee +27 -0
- data/vendor/assets/javascripts/joosy/preloader/production.js.coffee +84 -0
- data/{app → vendor}/assets/javascripts/joosy.js.coffee +0 -0
- data/vendor/assets/javascripts/jquery.form.js +963 -978
- data/vendor/assets/javascripts/sugar.js +1 -1
- metadata +48 -77
- data/.codoopts +0 -5
- data/README.md +0 -95
- data/app/assets/javascripts/joosy/core/application.js.coffee +0 -50
- data/app/assets/javascripts/joosy/core/form.js.coffee +0 -304
- data/app/assets/javascripts/joosy/core/helpers/view.js.coffee +0 -30
- data/app/assets/javascripts/joosy/core/joosy.js.coffee +0 -129
- data/app/assets/javascripts/joosy/core/layout.js.coffee +0 -162
- data/app/assets/javascripts/joosy/core/modules/container.js.coffee +0 -104
- data/app/assets/javascripts/joosy/core/modules/events.js.coffee +0 -123
- data/app/assets/javascripts/joosy/core/modules/filters.js.coffee +0 -67
- data/app/assets/javascripts/joosy/core/modules/log.js.coffee +0 -36
- data/app/assets/javascripts/joosy/core/modules/module.js.coffee +0 -105
- data/app/assets/javascripts/joosy/core/modules/renderer.js.coffee +0 -195
- data/app/assets/javascripts/joosy/core/modules/time_manager.js.coffee +0 -46
- data/app/assets/javascripts/joosy/core/modules/widgets_manager.js.coffee +0 -84
- data/app/assets/javascripts/joosy/core/page.js.coffee +0 -375
- data/app/assets/javascripts/joosy/core/preloader.js.coffee +0 -13
- data/app/assets/javascripts/joosy/core/resource/collection.js.coffee +0 -174
- data/app/assets/javascripts/joosy/core/resource/generic.js.coffee +0 -254
- data/app/assets/javascripts/joosy/core/resource/rest.js.coffee +0 -197
- data/app/assets/javascripts/joosy/core/resource/rest_collection.js.coffee +0 -125
- data/app/assets/javascripts/joosy/core/router.js.coffee +0 -163
- data/app/assets/javascripts/joosy/core/templaters/rails_jst.js.coffee +0 -36
- data/app/assets/javascripts/joosy/core/widget.js.coffee +0 -80
- data/app/assets/javascripts/joosy/preloaders/caching.js.coffee +0 -169
- data/app/assets/javascripts/joosy/preloaders/inline.js.coffee +0 -56
- data/lib/joosy.rb +0 -9
- data/lib/rails/generators/joosy/resource_generator.rb +0 -29
- data/lib/rails/generators/joosy/templates/app/helpers/application.js.coffee +0 -4
- data/lib/rails/generators/joosy/templates/app/pages/welcome/index.js.coffee +0 -22
- data/lib/rails/generators/joosy/templates/app/resources/template.js.coffee +0 -2
- data/lib/rails/generators/joosy/templates/app/templates/layouts/application.jst.hamlc +0 -2
- data/lib/rails/generators/joosy/templates/app/templates/pages/welcome/index.jst.hamlc +0 -7
- data/spec/javascripts/joosy/core/application_spec.js.coffee +0 -40
- data/spec/javascripts/joosy/core/form_spec.js.coffee +0 -184
- data/spec/javascripts/joosy/core/joosy_spec.js.coffee +0 -72
- data/spec/javascripts/joosy/core/layout_spec.js.coffee +0 -50
- data/spec/javascripts/joosy/core/modules/renderer_spec.js.coffee +0 -185
- data/spec/javascripts/joosy/core/page_spec.js.coffee +0 -178
- data/spec/javascripts/joosy/core/resource/collection_spec.js.coffee +0 -84
- data/spec/javascripts/joosy/core/resource/generic_spec.js.coffee +0 -118
- data/spec/javascripts/joosy/core/resource/rest_collection_spec.js.coffee +0 -58
- data/spec/javascripts/joosy/core/resource/rest_spec.js.coffee +0 -129
- data/spec/javascripts/joosy/core/router_spec.js.coffee +0 -123
- data/spec/javascripts/joosy/core/templaters/rails_jst_spec.js.coffee +0 -25
- data/spec/javascripts/joosy/core/widget_spec.js.coffee +0 -40
- data/spec/javascripts/joosy/preloaders/caching_spec.js.coffee +0 -36
- data/spec/javascripts/joosy/preloaders/inline_spec.js.coffee +0 -16
- data/spec/javascripts/support/assets/coolface.jpg +0 -0
- data/spec/javascripts/support/assets/okay.jpg +0 -0
- data/spec/javascripts/support/assets/test.js +0 -1
- data/spec/javascripts/support/sinon-ie-1.3.1.js +0 -82
- data/vendor/assets/javascripts/metamorph.js +0 -409
@@ -1,104 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# DOM container handling, DOM elements and DOM events bindings
|
3
|
-
#
|
4
|
-
# @note Requires implementor to contain DOM node at @container propert
|
5
|
-
#
|
6
|
-
# @module
|
7
|
-
#
|
8
|
-
Joosy.Modules.Container =
|
9
|
-
events: false
|
10
|
-
elements: false
|
11
|
-
|
12
|
-
eventSplitter: /^(\S+)\s*(.*)$/
|
13
|
-
|
14
|
-
$: (selector) ->
|
15
|
-
$(selector, @container)
|
16
|
-
|
17
|
-
#
|
18
|
-
# Rebinds selectors defined in 'elements' hash to object properties
|
19
|
-
#
|
20
|
-
# @example Sample elements
|
21
|
-
# elements:
|
22
|
-
# foo: '.foo'
|
23
|
-
# bar: '.bar'
|
24
|
-
#
|
25
|
-
refreshElements: ->
|
26
|
-
@__collectElements().each (key, value) =>
|
27
|
-
# TODO: Check for possible collisions?
|
28
|
-
@[key] = @$(value)
|
29
|
-
|
30
|
-
#
|
31
|
-
# Fills container with given data removing all events
|
32
|
-
#
|
33
|
-
# @param [jQuery] container jQuery entity of container to update
|
34
|
-
# @param [String] data HTML to inject
|
35
|
-
#
|
36
|
-
swapContainer: (container, data) ->
|
37
|
-
container.unbind().off()
|
38
|
-
container.html data
|
39
|
-
container
|
40
|
-
|
41
|
-
#
|
42
|
-
# Gathers 'elements' from current and super classes
|
43
|
-
#
|
44
|
-
__collectElements: ->
|
45
|
-
elements = Object.extended @elements || {}
|
46
|
-
|
47
|
-
klass = this
|
48
|
-
while klass = klass.constructor.__super__
|
49
|
-
Joosy.Module.merge elements, klass.elements, false
|
50
|
-
|
51
|
-
elements
|
52
|
-
|
53
|
-
#
|
54
|
-
# Gathers 'events' from current and super classes
|
55
|
-
#
|
56
|
-
__collectEvents: ->
|
57
|
-
events = Object.extended @events || {}
|
58
|
-
|
59
|
-
klass = this
|
60
|
-
while klass = klass.constructor.__super__
|
61
|
-
Joosy.Module.merge events, klass.events, false
|
62
|
-
|
63
|
-
events
|
64
|
-
|
65
|
-
#
|
66
|
-
# Converts '$...' notation to selector from 'elements'
|
67
|
-
#
|
68
|
-
# @param [String] selector Selector to convert
|
69
|
-
#
|
70
|
-
__extractSelector: (selector) ->
|
71
|
-
if r = selector.match /\$([A-z]+)/
|
72
|
-
selector = @__collectElements()[r[1]]
|
73
|
-
|
74
|
-
selector
|
75
|
-
|
76
|
-
#
|
77
|
-
# Bings events defined in 'events' to container
|
78
|
-
#
|
79
|
-
# @example Sample events
|
80
|
-
# events:
|
81
|
-
# 'click': -> # this will raise on container click
|
82
|
-
# 'click .foo': -> # this will raise on .foo click
|
83
|
-
# 'click $foo': -> #this will search for selector of foo element
|
84
|
-
#
|
85
|
-
__delegateEvents: ->
|
86
|
-
module = this
|
87
|
-
events = @__collectEvents()
|
88
|
-
|
89
|
-
events.each (key, method) =>
|
90
|
-
unless Object.isFunction method
|
91
|
-
method = @[method]
|
92
|
-
callback = (event) ->
|
93
|
-
method.call module, this, event
|
94
|
-
|
95
|
-
match = key.match @eventSplitter
|
96
|
-
eventName = match[1]
|
97
|
-
selector = @__extractSelector match[2]
|
98
|
-
|
99
|
-
if selector == ""
|
100
|
-
@container.bind eventName, callback
|
101
|
-
Joosy.Modules.Log.debugAs @, "#{eventName} binded on container"
|
102
|
-
else
|
103
|
-
@container.on eventName, selector, callback
|
104
|
-
Joosy.Modules.Log.debugAs @, "#{eventName} binded on #{selector}"
|
@@ -1,123 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Basic events implementation
|
3
|
-
#
|
4
|
-
# @module
|
5
|
-
#
|
6
|
-
Joosy.Modules.Events =
|
7
|
-
|
8
|
-
#
|
9
|
-
# Waits for the list of given events to happen at least once. Then runs callback.
|
10
|
-
#
|
11
|
-
# @param [String] events List of events to wait for separated by space
|
12
|
-
# @param [Function] callback Action to run when all events were triggered at least once
|
13
|
-
#
|
14
|
-
wait: (events, callback) ->
|
15
|
-
events = events.split /\s+/ if Object.isString events
|
16
|
-
|
17
|
-
@__oneShotEvents ||= []
|
18
|
-
@__oneShotEvents.push [events, callback]
|
19
|
-
|
20
|
-
#
|
21
|
-
# Binds action to run each time any of given even was triggered
|
22
|
-
#
|
23
|
-
# @param [String] events List of events separated by space
|
24
|
-
# @param [Function] callback Action to run on trigger
|
25
|
-
#
|
26
|
-
bind: (events, callback) ->
|
27
|
-
events = events.split /\s+/
|
28
|
-
|
29
|
-
@__boundEvents ||= []
|
30
|
-
@__boundEvents.push [events, callback]
|
31
|
-
|
32
|
-
#
|
33
|
-
# Unbinds action from runing on trigger
|
34
|
-
#
|
35
|
-
# @param [Function] target Action to unbind
|
36
|
-
#
|
37
|
-
unbind: (target) ->
|
38
|
-
for [events, callback], index in @__boundEvents
|
39
|
-
if callback == target
|
40
|
-
@__boundEvents.splice index, 1
|
41
|
-
return
|
42
|
-
|
43
|
-
#
|
44
|
-
# Triggers event for {bind} and {wait}
|
45
|
-
#
|
46
|
-
# @param [String] Name of event to trigger
|
47
|
-
#
|
48
|
-
trigger: (event) ->
|
49
|
-
Joosy.Modules.Log.debugAs @, "Event #{event} triggered"
|
50
|
-
if @__oneShotEvents
|
51
|
-
for [events, callback], index in @__oneShotEvents
|
52
|
-
position = events.indexOf event
|
53
|
-
if position >= 0
|
54
|
-
events.splice position, 1
|
55
|
-
|
56
|
-
if events.length == 0
|
57
|
-
@__oneShotEvents.splice index, 1
|
58
|
-
|
59
|
-
callback()
|
60
|
-
|
61
|
-
if @__boundEvents
|
62
|
-
for [events, callback] in @__boundEvents
|
63
|
-
if events.has event
|
64
|
-
callback()
|
65
|
-
|
66
|
-
#
|
67
|
-
# Runs set of callbacks finializing with result callback
|
68
|
-
#
|
69
|
-
# @example Basic usage
|
70
|
-
# Joosy.Events.synchronize (context) ->
|
71
|
-
# contet.do (done) -> done()
|
72
|
-
# contet.do (done) -> done()
|
73
|
-
# content.after ->
|
74
|
-
# console.log 'Success!'
|
75
|
-
#
|
76
|
-
# @param [Function] block Configuration block (see example)
|
77
|
-
#
|
78
|
-
synchronize: (block) ->
|
79
|
-
context = new Joosy.Modules.Events.SynchronizationContext(this)
|
80
|
-
block.call(this, context)
|
81
|
-
|
82
|
-
@wait context.expectations, => context.after.call(this)
|
83
|
-
|
84
|
-
context.actions.each (data) =>
|
85
|
-
data[0].call this, =>
|
86
|
-
@trigger data[1]
|
87
|
-
|
88
|
-
#
|
89
|
-
# Internal representation of {Joosy.Modules.Events#synchronize} context
|
90
|
-
#
|
91
|
-
# @see Joosy.Modules.Events#synchronize
|
92
|
-
#
|
93
|
-
class Joosy.Modules.Events.SynchronizationContext
|
94
|
-
@uid = 0
|
95
|
-
|
96
|
-
constructor: (@parent) ->
|
97
|
-
@expectations = []
|
98
|
-
@actions = []
|
99
|
-
|
100
|
-
#
|
101
|
-
# Internal simple counter to separate given synchronization actions
|
102
|
-
#
|
103
|
-
uid: ->
|
104
|
-
@constructor.uid += 1
|
105
|
-
|
106
|
-
#
|
107
|
-
# Registeres another async function that should be synchronized
|
108
|
-
#
|
109
|
-
# @param [Function] action `(Function) -> null` to call.
|
110
|
-
# Should call given function to mark itself complete.
|
111
|
-
#
|
112
|
-
do: (action) ->
|
113
|
-
event = "synchro-#{@uid()}"
|
114
|
-
@expectations.push event
|
115
|
-
@actions.push [action, event]
|
116
|
-
|
117
|
-
#
|
118
|
-
# Registers finalizer: the action that will be called when all do-functions
|
119
|
-
# marked themselves as complete.
|
120
|
-
#
|
121
|
-
# @param [Function] after Function to call.
|
122
|
-
#
|
123
|
-
after: (@after) ->
|
@@ -1,67 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Filters registration routines
|
3
|
-
#
|
4
|
-
# @module
|
5
|
-
#
|
6
|
-
Joosy.Modules.Filters =
|
7
|
-
|
8
|
-
#
|
9
|
-
# Defines static registration routines
|
10
|
-
#
|
11
|
-
# @example Set of methods
|
12
|
-
# class Test
|
13
|
-
# @beforeLoad -> # supposed to run before load and control loading queue
|
14
|
-
# @afterLoad -> # supposed to run after load to finalize loading
|
15
|
-
# @afterUnload -> # supposed to run after unload to collect garbage
|
16
|
-
#
|
17
|
-
included: ->
|
18
|
-
@beforeLoad = (callback) ->
|
19
|
-
unless @::hasOwnProperty '__beforeLoads'
|
20
|
-
@::__beforeLoads = [].concat @.__super__.__beforeLoads || []
|
21
|
-
@::__beforeLoads.push callback
|
22
|
-
|
23
|
-
@afterLoad = (callback) ->
|
24
|
-
unless @::hasOwnProperty '__afterLoads'
|
25
|
-
@::__afterLoads = [].concat @.__super__.__afterLoads || []
|
26
|
-
@::__afterLoads.push callback
|
27
|
-
|
28
|
-
@afterUnload = (callback) ->
|
29
|
-
unless @::hasOwnProperty '__afterUnloads'
|
30
|
-
@::__afterUnloads = [].concat @.__super__.__afterUnloads || []
|
31
|
-
@::__afterUnloads.push callback
|
32
|
-
|
33
|
-
#
|
34
|
-
# Runs filters registered as beforeLoad
|
35
|
-
#
|
36
|
-
__runBeforeLoads: (opts...) ->
|
37
|
-
unless @__beforeLoads?.length > 0
|
38
|
-
return true
|
39
|
-
|
40
|
-
flag = true
|
41
|
-
|
42
|
-
for filter in @__beforeLoads
|
43
|
-
unless Object.isFunction filter
|
44
|
-
filter = @[filter]
|
45
|
-
flag = flag && filter.apply @, opts
|
46
|
-
|
47
|
-
return flag
|
48
|
-
|
49
|
-
#
|
50
|
-
# Runs filters registered as afterLoad
|
51
|
-
#
|
52
|
-
__runAfterLoads: (opts...) ->
|
53
|
-
if @__afterLoads?.length > 0
|
54
|
-
for filter in @__afterLoads
|
55
|
-
unless Object.isFunction filter
|
56
|
-
filter = @[filter]
|
57
|
-
filter.apply @, opts
|
58
|
-
|
59
|
-
#
|
60
|
-
# Runs filters registered as afterUnload
|
61
|
-
#
|
62
|
-
__runAfterUnloads: (opts...) ->
|
63
|
-
if @__afterUnloads?.length > 0
|
64
|
-
for filter in @__afterUnloads
|
65
|
-
unless Object.isFunction filter
|
66
|
-
filter = @[filter]
|
67
|
-
filter.apply @, opts
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Wrappers for console.log
|
3
|
-
#
|
4
|
-
# @module
|
5
|
-
#
|
6
|
-
Joosy.Modules.Log =
|
7
|
-
|
8
|
-
#
|
9
|
-
# Checks if console is available and proxies given arguments directly to `console.log`
|
10
|
-
#
|
11
|
-
log: (args...) ->
|
12
|
-
return unless console?
|
13
|
-
|
14
|
-
if console.log.apply?
|
15
|
-
args.unshift "Joosy>"
|
16
|
-
console.log args...
|
17
|
-
else
|
18
|
-
console.log args.first()
|
19
|
-
|
20
|
-
#
|
21
|
-
# Runs `log` if debug is active
|
22
|
-
#
|
23
|
-
debug: (args...) ->
|
24
|
-
return unless Joosy.debug
|
25
|
-
@log args...
|
26
|
-
|
27
|
-
#
|
28
|
-
# Logs given message wrapping it with description of given object (class name)
|
29
|
-
#
|
30
|
-
# @param [Object] context The class required to be described in log message
|
31
|
-
# @param [String] string Message to log
|
32
|
-
#
|
33
|
-
debugAs: (context, string, args...) ->
|
34
|
-
return unless Joosy.debug
|
35
|
-
context = Joosy.Module.__className(context) || 'unknown context'
|
36
|
-
@debug "#{context}> #{string}", args...
|
@@ -1,105 +0,0 @@
|
|
1
|
-
moduleKeywords = ['included', 'extended']
|
2
|
-
|
3
|
-
#
|
4
|
-
# Base Joosy class extending Coffee class with module-like injections
|
5
|
-
# and other tiny stuff.
|
6
|
-
#
|
7
|
-
class Joosy.Module
|
8
|
-
#
|
9
|
-
# Sets the default namespace for all Joosy descendants.
|
10
|
-
# This is used in {Joosy.namespace} magic.
|
11
|
-
#
|
12
|
-
@__namespace__: []
|
13
|
-
|
14
|
-
#
|
15
|
-
# Gets Object/Class class name.
|
16
|
-
#
|
17
|
-
# @note Never use this to make some magical auto-suggestions!!!
|
18
|
-
# Remember: minifcation will rename your classes. Therefore it
|
19
|
-
# is only intended for development debugging purposes.
|
20
|
-
#
|
21
|
-
# @note Go @jashkenas Go! Give us https://github.com/jashkenas/coffee-script/issues/2052.
|
22
|
-
# Please go vote for this feature if you are reading this. It will
|
23
|
-
# give us ability to eleminate a lot of boilerplate for you.
|
24
|
-
#
|
25
|
-
# @return [String]
|
26
|
-
#
|
27
|
-
@__className: (klass) ->
|
28
|
-
unless Object.isFunction(klass)
|
29
|
-
klass = klass.constructor
|
30
|
-
|
31
|
-
if klass.name?
|
32
|
-
klass.name
|
33
|
-
else
|
34
|
-
klass.toString().replace /^function ([a-zA-Z]+)\([\s\S]+/, '$1'
|
35
|
-
|
36
|
-
#
|
37
|
-
# Determines if class A has class B in its ancestors.
|
38
|
-
#
|
39
|
-
# @param [Class] what Class to check againt
|
40
|
-
# @param [Class] klass Possible ancestor to search for
|
41
|
-
#
|
42
|
-
# @return [Boolean]
|
43
|
-
#
|
44
|
-
@hasAncestor: (what, klass) ->
|
45
|
-
unless what? && klass?
|
46
|
-
return false
|
47
|
-
|
48
|
-
[what, klass] = [what.prototype, klass.prototype]
|
49
|
-
|
50
|
-
while what
|
51
|
-
if what == klass
|
52
|
-
return true
|
53
|
-
what = what.constructor?.__super__
|
54
|
-
|
55
|
-
false
|
56
|
-
|
57
|
-
#
|
58
|
-
# Simple and fast shallow merge implementation.
|
59
|
-
#
|
60
|
-
# This is here due to: https://github.com/andrewplummer/Sugar/issues/100.
|
61
|
-
# This bug was closed and we got some performance but this implementation is
|
62
|
-
# still like 10x fater for basic tasks.
|
63
|
-
#
|
64
|
-
# @param [Object] destination Object to extend
|
65
|
-
# @param [Object] source Source of new properties
|
66
|
-
# @param [Boolean] unsafe Determines if we should rewrite destination properties
|
67
|
-
#
|
68
|
-
# @return [Object] The new and mighty destination Object
|
69
|
-
#
|
70
|
-
@merge: (destination, source, unsafe=true) ->
|
71
|
-
for key, value of source
|
72
|
-
if source.hasOwnProperty(key)
|
73
|
-
if unsafe || !destination.hasOwnProperty(key)
|
74
|
-
destination[key] = value
|
75
|
-
destination
|
76
|
-
|
77
|
-
#
|
78
|
-
# Mixes given object as dynamic methods
|
79
|
-
#
|
80
|
-
# @param [Object] object Module object
|
81
|
-
#
|
82
|
-
@include: (object) ->
|
83
|
-
unless object
|
84
|
-
throw new Error 'include(object) requires obj'
|
85
|
-
|
86
|
-
Object.each object, (key, value) =>
|
87
|
-
if key not in moduleKeywords
|
88
|
-
this::[key] = value
|
89
|
-
|
90
|
-
object.included?.apply this
|
91
|
-
null
|
92
|
-
|
93
|
-
#
|
94
|
-
# Mixes given object as static methods
|
95
|
-
#
|
96
|
-
# @param [Object] object Module object
|
97
|
-
#
|
98
|
-
@extend: (object) ->
|
99
|
-
unless object
|
100
|
-
throw new Error 'extend(object) requires object'
|
101
|
-
|
102
|
-
@merge this, object
|
103
|
-
|
104
|
-
object.extended?.apply this
|
105
|
-
null
|
@@ -1,195 +0,0 @@
|
|
1
|
-
#= require_tree ../templaters
|
2
|
-
#= require metamorph
|
3
|
-
|
4
|
-
#
|
5
|
-
# Core DOM rendering mechanics
|
6
|
-
#
|
7
|
-
# @module
|
8
|
-
# @todo Describe this scary thing o_O
|
9
|
-
#
|
10
|
-
Joosy.Modules.Renderer =
|
11
|
-
|
12
|
-
#
|
13
|
-
# Default behavior for non-set renderer (empty template?)
|
14
|
-
#
|
15
|
-
__renderer: ->
|
16
|
-
throw new Error "#{Joosy.Module.__className @constructor} does not have an attached template"
|
17
|
-
|
18
|
-
__helpers: null
|
19
|
-
|
20
|
-
#
|
21
|
-
# Defines class-level helpers: @view and @helpers
|
22
|
-
#
|
23
|
-
# View (@view): Sets the curent template by specifying its name or lambda
|
24
|
-
# Helpers (@helpers): Lists set of helpers' namespaces to include
|
25
|
-
#
|
26
|
-
included: ->
|
27
|
-
@view = (template, options={}) ->
|
28
|
-
if Object.isFunction template
|
29
|
-
@::__renderer = template
|
30
|
-
else
|
31
|
-
@::__renderer = (locals={}) ->
|
32
|
-
if options.dynamic
|
33
|
-
@renderDynamic template, locals
|
34
|
-
else
|
35
|
-
@render template, locals
|
36
|
-
|
37
|
-
@helpers = (helpers...) ->
|
38
|
-
@::__helpers ||= []
|
39
|
-
helpers.map (helper) =>
|
40
|
-
module = Joosy.Helpers[helper]
|
41
|
-
unless module
|
42
|
-
throw new Error "Cannot find helper module #{helper}"
|
43
|
-
|
44
|
-
@::__helpers.push module
|
45
|
-
|
46
|
-
@::__helpers = @::__helpers.unique()
|
47
|
-
|
48
|
-
__instantiateHelpers: ->
|
49
|
-
unless @__helpersInstance
|
50
|
-
@__helpersInstance = Object.extended Joosy.Helpers.Application
|
51
|
-
|
52
|
-
@__helpersInstance.widget = (element, widget) =>
|
53
|
-
@widgets ||= {}
|
54
|
-
|
55
|
-
uuid = Joosy.uuid()
|
56
|
-
element = document.createElement element
|
57
|
-
temp = document.createElement 'div'
|
58
|
-
|
59
|
-
element.id = uuid
|
60
|
-
@widgets['#'+uuid] = widget
|
61
|
-
|
62
|
-
temp.appendChild element
|
63
|
-
temp.innerHTML
|
64
|
-
|
65
|
-
if @__helpers
|
66
|
-
for helper in @__helpers
|
67
|
-
Joosy.Module.merge @__helpersInstance, helper
|
68
|
-
|
69
|
-
@__helpersInstance
|
70
|
-
|
71
|
-
# If we do not have __proto__ available...
|
72
|
-
__proxifyHelpers: (locals) ->
|
73
|
-
if locals.hasOwnProperty '__proto__'
|
74
|
-
locals.__proto__ = @__instantiateHelpers()
|
75
|
-
locals
|
76
|
-
else
|
77
|
-
unless @__helpersProxyInstance
|
78
|
-
@__helpersProxyInstance = (locals) ->
|
79
|
-
Joosy.Module.merge this, locals
|
80
|
-
|
81
|
-
@__helpersProxyInstance.prototype = @__instantiateHelpers()
|
82
|
-
|
83
|
-
new @__helpersProxyInstance locals
|
84
|
-
|
85
|
-
render: (template, locals={}, parentStackPointer=false) ->
|
86
|
-
@__render false, template, locals, parentStackPointer
|
87
|
-
|
88
|
-
renderDynamic: (template, locals={}, parentStackPointer=false) ->
|
89
|
-
@__render true, template, locals, parentStackPointer
|
90
|
-
|
91
|
-
__render: (dynamic, template, locals={}, parentStackPointer=false) ->
|
92
|
-
stack = @__renderingStackChildFor parentStackPointer
|
93
|
-
|
94
|
-
stack.template = template
|
95
|
-
stack.locals = locals
|
96
|
-
|
97
|
-
isResource = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Generic
|
98
|
-
isCollection = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Collection
|
99
|
-
|
100
|
-
if Object.isString template
|
101
|
-
if @__renderSection?
|
102
|
-
template = Joosy.Application.templater.resolveTemplate @__renderSection(), template, this
|
103
|
-
|
104
|
-
template = Joosy.Application.templater.buildView template
|
105
|
-
else if !Object.isFunction template
|
106
|
-
throw new Error "#{Joosy.Module.__className @}> template (maybe @view) does not look like a string or lambda"
|
107
|
-
|
108
|
-
if !Object.isObject(locals) && !isResource && !isCollection
|
109
|
-
throw new Error "#{Joosy.Module.__className @}> locals (maybe @data?) not in: dumb hash, Resource, Collection"
|
110
|
-
|
111
|
-
renderers =
|
112
|
-
render: (template, locals={}) =>
|
113
|
-
@render template, locals, stack
|
114
|
-
renderDynamic: (template, locals={}) =>
|
115
|
-
@renderDynamic template, locals, stack
|
116
|
-
|
117
|
-
context = =>
|
118
|
-
data = {}
|
119
|
-
|
120
|
-
if isResource
|
121
|
-
Joosy.Module.merge data, stack.locals.e
|
122
|
-
else
|
123
|
-
Joosy.Module.merge data, stack.locals
|
124
|
-
|
125
|
-
Joosy.Module.merge data, @__instantiateHelpers(), false
|
126
|
-
Joosy.Module.merge data, renderers
|
127
|
-
data
|
128
|
-
|
129
|
-
if dynamic
|
130
|
-
morph = Metamorph template(context())
|
131
|
-
update = =>
|
132
|
-
for child in stack.children
|
133
|
-
@__removeMetamorphs child
|
134
|
-
stack.children = []
|
135
|
-
morph.html template(context())
|
136
|
-
@refreshElements?()
|
137
|
-
|
138
|
-
# This is here to break stack tree and save from
|
139
|
-
# repeating DOM handling
|
140
|
-
update = update.debounce 0
|
141
|
-
|
142
|
-
if isCollection
|
143
|
-
for resource in locals.data
|
144
|
-
resource.bind 'changed', update
|
145
|
-
stack.metamorphBindings.push [resource, update]
|
146
|
-
if isResource || isCollection
|
147
|
-
locals.bind 'changed', update
|
148
|
-
stack.metamorphBindings.push [locals, update]
|
149
|
-
else
|
150
|
-
for key, object of locals
|
151
|
-
if locals.hasOwnProperty key
|
152
|
-
if object?.bind? && object?.unbind?
|
153
|
-
object.bind 'changed', update
|
154
|
-
stack.metamorphBindings.push [object, update]
|
155
|
-
|
156
|
-
morph.outerHTML()
|
157
|
-
else
|
158
|
-
template context()
|
159
|
-
|
160
|
-
__renderingStackElement: (parent=null) ->
|
161
|
-
metamorphBindings: []
|
162
|
-
locals: null
|
163
|
-
template: null
|
164
|
-
children: []
|
165
|
-
parent: parent
|
166
|
-
|
167
|
-
__renderingStackChildFor: (parentPointer) ->
|
168
|
-
if !@__renderingStack
|
169
|
-
@__renderingStack = []
|
170
|
-
|
171
|
-
if !parentPointer
|
172
|
-
element = @__renderingStackElement()
|
173
|
-
@__renderingStack.push element
|
174
|
-
element
|
175
|
-
else
|
176
|
-
element = @__renderingStackElement parentPointer
|
177
|
-
parentPointer.children.push element
|
178
|
-
element
|
179
|
-
|
180
|
-
__removeMetamorphs: (stackPointer=false) ->
|
181
|
-
remove = (stackPointer) =>
|
182
|
-
if stackPointer?.children
|
183
|
-
for child in stackPointer.children
|
184
|
-
@__removeMetamorphs child
|
185
|
-
|
186
|
-
if stackPointer?.metamorphBindings
|
187
|
-
for [object, callback] in stackPointer.metamorphBindings
|
188
|
-
object.unbind callback
|
189
|
-
stackPointer.metamorphBindings = []
|
190
|
-
|
191
|
-
unless stackPointer
|
192
|
-
@__renderingStack?.each (stackPointer) ->
|
193
|
-
remove stackPointer
|
194
|
-
else
|
195
|
-
remove stackPointer
|
@@ -1,46 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Comfortable and clever wrappers for timeouts management
|
3
|
-
#
|
4
|
-
# @module
|
5
|
-
#
|
6
|
-
Joosy.Modules.TimeManager =
|
7
|
-
|
8
|
-
#
|
9
|
-
# Registeres timeout for current object
|
10
|
-
#
|
11
|
-
# @param [Integer] timeout Miliseconds to wait
|
12
|
-
# @param [Function] action Action to run on timeout
|
13
|
-
#
|
14
|
-
setTimeout: (timeout, action) ->
|
15
|
-
@__timeouts ||= []
|
16
|
-
|
17
|
-
timer = window.setTimeout (=> action()), timeout
|
18
|
-
@__timeouts.push timer
|
19
|
-
|
20
|
-
timer
|
21
|
-
|
22
|
-
#
|
23
|
-
# Registeres interval for current object
|
24
|
-
#
|
25
|
-
# @param [Integer] delay Miliseconds between runs
|
26
|
-
# @param [Function] action Action to run
|
27
|
-
#
|
28
|
-
setInterval: (delay, action) ->
|
29
|
-
@__intervals ||= []
|
30
|
-
|
31
|
-
timer = window.setInterval (=> action()), delay
|
32
|
-
@__intervals.push timer
|
33
|
-
|
34
|
-
timer
|
35
|
-
|
36
|
-
#
|
37
|
-
# Drops all registered timeouts and intervals for this object
|
38
|
-
#
|
39
|
-
__clearTime: ->
|
40
|
-
if @__intervals
|
41
|
-
for entry in @__intervals
|
42
|
-
window.clearInterval entry
|
43
|
-
|
44
|
-
if @__timeouts
|
45
|
-
for entry in @__timeouts
|
46
|
-
window.clearTimeout entry
|