app/assets/javascripts/joosy/core/joosy.js.coffee in joosy-0.1.0.RC2 vs app/assets/javascripts/joosy/core/joosy.js.coffee in joosy-0.1.0.RC3
- old
+ new
@@ -1,70 +1,129 @@
-@Joosy = Object.extended
- debug: false
+#
+# All the tiny core stuff
+#
+# @module
+#
+@Joosy =
+ #
+ # Core modules container
+ #
Modules: {}
+
+ #
+ # Resources container
+ #
Resource: {}
+
+ #
+ # Templaters container
+ #
Templaters: {}
-Joosy.namespace = (name, generator=false) ->
- name = name.split '.'
- space = window
- for part in name
- space = space[part] ?= {}
+ #
+ # If enabled Joosy will log to console a lot of 'in progress' stuff
+ #
+ debug: false
- if generator
- generator = generator.apply space
- for key, klass of space
- if space.hasOwnProperty(key) &&
- Joosy.Module.hasAncestor klass, Joosy.Module
- klass.__namespace__ = name
+ #
+ # Registeres anything inside specified namespace (objects chain starting from `window`)
+ #
+ # @example Basic usage
+ # Joosy.namespace 'foobar', ->
+ # class @RealThing
+ #
+ # foo = new foobar.RealThing
+ #
+ # @param [String] name Namespace keyword
+ # @param [Boolean] generator Namespace content
+ #
+ namespace: (name, generator=false) ->
+ name = name.split '.'
+ space = window
+ for part in name
+ space = space[part] ?= {}
-Joosy.helpers = (name, generator) ->
- Joosy.namespace "Joosy.Helpers.#{name}", generator
+ if generator
+ generator = generator.apply space
+ for key, klass of space
+ if space.hasOwnProperty(key) &&
+ Joosy.Module.hasAncestor klass, Joosy.Module
+ klass.__namespace__ = name
-Joosy.test = ->
- text = "Hi :). I'm Joosy. And everything is just fine!"
+ #
+ # Registeres given methods as a helpers inside a given set
+ #
+ # @param [String] name Helpers set keyword
+ # @param [Boolean] generator Helpers content
+ #
+ helpers: (name, generator) ->
+ Joosy.namespace "Joosy.Helpers.#{name}", generator
- if console
- console.log text
- else
- alert text
+ #
+ # Scary `hello world`
+ #
+ test: ->
+ text = "Hi :). I'm Joosy. And everything is just fine!"
-Joosy.uuid = ->
- 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) ->
- r = Math.random() * 16 | 0
- v = if c is 'x' then r else r & 3 | 8
- v.toString 16
- .toUpperCase()
+ if console
+ console.log text
+ else
+ alert text
-Joosy.preloadImages = (images, callback) ->
- unless Object.isArray(images)
- images = [images]
- if images.length == 0
- callback()
+ #
+ # Generates UUID
+ #
+ uuid: ->
+ 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) ->
+ r = Math.random() * 16 | 0
+ v = if c is 'x' then r else r & 3 | 8
+ v.toString 16
+ .toUpperCase()
- ticks = images.length
- result = []
- checker = ->
- if (ticks -= 1) == 0
- callback?()
+ #
+ # Preloads sets of images then runs callback
+ #
+ # @param [Array<String>] images Images paths
+ # @param [Function] callback Action to run when every picture was loaded (or triggered an error)
+ #
+ preloadImages: (images, callback) ->
+ unless Object.isArray(images)
+ images = [images]
+ if images.length == 0
+ callback()
- for p in images
- result.push $('<img/>').load(checker).attr('src', p)
+ ticks = images.length
+ result = []
+ checker = ->
+ if (ticks -= 1) == 0
+ callback?()
- result
+ for p in images
+ result.push $('<img/>').load(checker).error(checker).attr('src', p)
-Joosy.buildUrl = (url, params) ->
- paramsString = []
+ result
- Object.each params, (key, value) ->
- paramsString.push "#{key}=#{value}"
+ #
+ # Basic URI builder. Joins base path with params hash
+ #
+ # @param [String] url Base url
+ # @param [Hash] params Parameters to join
+ #
+ # @example Basic usage
+ # Joosy.buildUrl 'http://joosy.ws/#!/test', {foo: 'bar'} # http://joosy.ws/?foo=bar#!/test
+ #
+ buildUrl: (url, params) ->
+ paramsString = []
- hash = url.match(/(\#.*)?$/)[0]
- url = url.replace /\#.*$/, ''
- if !paramsString.isEmpty() && !url.has(/\?/)
- url = url + "?"
+ Object.each params, (key, value) ->
+ paramsString.push "#{key}=#{value}"
- paramsString = paramsString.join '&'
- if !paramsString.isBlank() && url.last() != '?'
- paramsString = '&' + paramsString
+ hash = url.match(/(\#.*)?$/)[0]
+ url = url.replace /\#.*$/, ''
+ if !paramsString.isEmpty() && !url.has(/\?/)
+ url = url + "?"
- url + paramsString + hash
+ paramsString = paramsString.join '&'
+ if !paramsString.isBlank() && url.last() != '?'
+ paramsString = '&' + paramsString
+
+ url + paramsString + hash
\ No newline at end of file