lol_framework 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +4 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +30 -0
  6. data/Rakefile +1 -0
  7. data/lib/generators/lol_framework/setup/lol_framework.rb +27 -0
  8. data/lib/generators/lol_framework/setup/setup_generator.rb +17 -0
  9. data/lib/lol_framework.rb +8 -0
  10. data/lib/lol_framework/common.rb +20 -0
  11. data/lib/lol_framework/config.rb +17 -0
  12. data/lib/lol_framework/config/components.rb +16 -0
  13. data/lib/lol_framework/config/components/css.rb +44 -0
  14. data/lib/lol_framework/config/components/js.rb +75 -0
  15. data/lib/lol_framework/railtie.rb +14 -0
  16. data/lib/lol_framework/version.rb +3 -0
  17. data/lol_framework.gemspec +28 -0
  18. data/spec/lol_framework/config/components/css_spec.rb +5 -0
  19. data/spec/lol_framework/config/components/js_spec.rb +11 -0
  20. data/spec/lol_framework/config/components_spec.rb +24 -0
  21. data/spec/lol_framework/config_spec.rb +19 -0
  22. data/spec/lol_framework/lol_framework_spec.rb +13 -0
  23. data/spec/spec_helper.rb +20 -0
  24. data/vendor/assets/images/lol_framework/datatable/sorting_bg.png +0 -0
  25. data/vendor/assets/images/lol_framework/glyphicons-lol-origin-white.png +0 -0
  26. data/vendor/assets/images/lol_framework/glyphicons-lol-origin.png +0 -0
  27. data/vendor/assets/images/lol_framework/glyphicons-lol.png +0 -0
  28. data/vendor/assets/javascripts/.gitkeep +0 -0
  29. data/vendor/assets/javascripts/Jasmine/jasmine-html.js +616 -0
  30. data/vendor/assets/javascripts/Jasmine/jasmine.js +2529 -0
  31. data/vendor/assets/javascripts/lol.js +18 -0
  32. data/vendor/assets/javascripts/lol_framework/Ajax.coffee +183 -0
  33. data/vendor/assets/javascripts/lol_framework/Alert.coffee +113 -0
  34. data/vendor/assets/javascripts/lol_framework/Button.coffee +268 -0
  35. data/vendor/assets/javascripts/lol_framework/Core.coffee +85 -0
  36. data/vendor/assets/javascripts/lol_framework/Datatable.coffee +340 -0
  37. data/vendor/assets/javascripts/lol_framework/Date.coffee +0 -0
  38. data/vendor/assets/javascripts/lol_framework/Debug.coffee +45 -0
  39. data/vendor/assets/javascripts/lol_framework/I18n.coffee +81 -0
  40. data/vendor/assets/javascripts/lol_framework/Lang/en-us.coffee +54 -0
  41. data/vendor/assets/javascripts/lol_framework/Lang/pt-br.coffee +57 -0
  42. data/vendor/assets/javascripts/lol_framework/Library/date-functions.js +409 -0
  43. data/vendor/assets/javascripts/lol_framework/Library/jquery.dataTables.min.js +157 -0
  44. data/vendor/assets/javascripts/lol_framework/Library/jquery.mobile.js +14 -0
  45. data/vendor/assets/javascripts/lol_framework/Loader.coffee +83 -0
  46. data/vendor/assets/javascripts/lol_framework/Lol.coffee +4 -0
  47. data/vendor/assets/javascripts/lol_framework/Modal.coffee +221 -0
  48. data/vendor/assets/javascripts/lol_framework/Model.coffee +71 -0
  49. data/vendor/assets/javascripts/lol_framework/Model/Rest.coffee +15 -0
  50. data/vendor/assets/javascripts/lol_framework/Tests/Alert.coffee +83 -0
  51. data/vendor/assets/javascripts/lol_framework/Tests/Core.coffee +35 -0
  52. data/vendor/assets/javascripts/lol_framework/Tests/Debug.coffee +14 -0
  53. data/vendor/assets/javascripts/lol_framework/Tests/I18n.coffee +7 -0
  54. data/vendor/assets/javascripts/lol_framework/Tests/Lang.coffee +130 -0
  55. data/vendor/assets/javascripts/lol_framework/Tests/Library.coffee +13 -0
  56. data/vendor/assets/javascripts/lol_framework/Tests/Lol.coffee +4 -0
  57. data/vendor/assets/javascripts/lol_framework/Tests/Utils.coffee +22 -0
  58. data/vendor/assets/javascripts/lol_framework/Utils.coffee +42 -0
  59. data/vendor/assets/javascripts/lol_main_tests.js +43 -0
  60. data/vendor/assets/stylesheets/.gitkeep +0 -0
  61. data/vendor/assets/stylesheets/jasmine.css +81 -0
  62. data/vendor/assets/stylesheets/lol_framework/_mixin.scss +650 -0
  63. data/vendor/assets/stylesheets/lol_framework/_variable.scss +107 -0
  64. data/vendor/assets/stylesheets/lol_framework/components/_alert.scss +46 -0
  65. data/vendor/assets/stylesheets/lol_framework/components/_datatable.scss +172 -0
  66. data/vendor/assets/stylesheets/lol_framework/components/_loader.scss +15 -0
  67. data/vendor/assets/stylesheets/lol_framework/components/_modal.scss +68 -0
  68. metadata +222 -0
@@ -0,0 +1,71 @@
1
+ ###
2
+ @summary Lol Framework
3
+ @description Framework of RIAs applications
4
+ @version 1.0.0
5
+ @file Model.js
6
+ @author Welington Sampaio (http://welington.zaez.net/)
7
+ @contact http://welington.zaez.net/site/contato
8
+
9
+ @copyright Copyright 2012 Welington Sampaio, all rights reserved.
10
+
11
+ This source file is free software, under the license MIT, available at:
12
+ http://lolframework.zaez.net/license
13
+
14
+ This source file is distributed in the hope that it will be useful, but
15
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
+ or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
17
+
18
+ For details please refer to: http://welington.zaez.net
19
+ ###
20
+
21
+ ###
22
+ Create a new instance of Model.
23
+
24
+ @classDescription This class creates a new Model.
25
+ @param {Object} Receives configuration to create the Model, @see Lol.model.defaults
26
+ @return {Model}    Returns a new Model.
27
+ @type {Object}
28
+ ###
29
+ class Lol.Model extends Lol.Core
30
+ # declaration of variables
31
+ id : null
32
+ debugIndex : 1
33
+ debugPrefix : 'Lol_Model'
34
+ namespace : '.model'
35
+ # the methods
36
+ constructor: (args={})->
37
+ return false unless @verifyJQuery()
38
+ @settings = jQuery.extend true, {}, Lol.model.defaults, args
39
+ @generateId()
40
+
41
+
42
+ Lol.model =
43
+ defaults :
44
+ ###
45
+ Defines whether the class should print
46
+ debug messages
47
+ ###
48
+ debug : true
49
+ ###
50
+ Name of table on ralational database or
51
+ name of module to rest applications
52
+ @type String
53
+ ###
54
+ name : null
55
+ ###
56
+ Fields of relational model
57
+ @type object
58
+ @example
59
+ fields : {
60
+ {name: "id" , type: 'integer' , hide: true , dateFormat: null},
61
+ {name: "fullname" , type: 'string' , hide: false, dateFormat: null},
62
+ {name: "password" , type: 'password', hide: false, dateFormat: null},
63
+ {name: "create_at", type: 'date' , hide: false, dataFormat: 'Y-m-d H:i:s'}
64
+ }
65
+ ###
66
+ fields : {}
67
+ ###
68
+ Specifies whether the class will use
69
+ the rest of the standard application
70
+ ###
71
+ useRest : true
@@ -0,0 +1,15 @@
1
+
2
+ class Lol.model.Rest extends Lol.Core
3
+ update: (model,id)->
4
+ delete: (model,id)->
5
+ insert: (model,data)->
6
+
7
+ @destroy: (url)->
8
+
9
+ new Lol.Ajax
10
+ method: 'delete'
11
+ url : url
12
+ callbacks:
13
+ success: (data, textStatus, jqXHR)->
14
+ new Lol.Alert
15
+ message: Lol.t 'rest_registry_destroy_ok'
@@ -0,0 +1,83 @@
1
+ describe 'Lol.Alert', ->
2
+ alert = null
3
+
4
+ beforeEach ->
5
+ alert = new Lol.Alert
6
+ message: 'My Alert'
7
+
8
+ it 'should be a function', ->
9
+ expect(Lol.Alert).toEqual(jasmine.any Function)
10
+
11
+ it 'should be able to calling Lol.Core methods', ->
12
+ expect(alert.generateId).toBeDefined()
13
+ expect(alert.debug).toBeDefined()
14
+ expect(alert.destroy).toBeDefined()
15
+
16
+ it 'should have a standard settings', ->
17
+ expect(alert.debugPrefix).toEqual('Lol_Alert')
18
+ expect(alert.namespace).toEqual('.alert')
19
+
20
+ it 'should be able a methods', ->
21
+ expect(alert.appendClose).toBeDefined()
22
+ expect(alert.createAlert).toBeDefined()
23
+ expect(alert.setContainer).toBeDefined()
24
+ expect(alert.setInterval).toBeDefined()
25
+ expect(alert.setEvents).toBeDefined()
26
+
27
+ it 'should be able to create a close button', ->
28
+ expect(alert.appendClose()).toEqual(alert.close)
29
+
30
+ it 'should be able to create a alert object', ->
31
+ expect(alert.createAlert()).toEqual(alert.alert)
32
+
33
+
34
+
35
+ # createAlert: ->
36
+ # @debug 'Create an object Alert'
37
+ # @alert = jQuery '<div></div>'
38
+ # @alert.addClass "alert #{@settings.objects.classes[@settings.type]}"
39
+ # @alert.append @settings.message
40
+ # @appendClose()
41
+ # @alert.appendTo @container
42
+ # destroy: ->
43
+ # @debug 'Initializing the destroy method'
44
+ # @alert.slideUp ->
45
+ # jQuery(@).remove()
46
+ # clearInterval(@interval) if @settings.autoRemove
47
+ # super
48
+ # setContainer: ->
49
+ # @debug 'Setting a container object'
50
+ # if not jQuery( @settings.objects.containerID )
51
+ # throw "Required container Alert: #{@settings.objects.containerID}"
52
+ # return false
53
+ # @container = jQuery @settings.objects.containerID
54
+ # setInterval: ->
55
+ # @debug 'Setting interval?',@settings.autoRemove, 'With delay:',@settings.delayRemove
56
+ # _this = @
57
+ # @interval = setInterval(->
58
+ # _this.destroy()
59
+ # , @settings.delayRemove) if @settings.autoRemove
60
+ # setEvents: ->
61
+ # @debug 'Setting all events'
62
+ # _this = @
63
+ # @close.bind "click#{@namespace}", ->
64
+ # _this.debug 'Dispatch event clickon close button'
65
+ # _this.destroy()
66
+ #
67
+ # Lol.alert =
68
+ # # private:
69
+ # # dataset:
70
+ #
71
+ # defaults:
72
+ # autoRemove : true
73
+ # type : 'success' # Options success | error | warning | info
74
+ # message : null
75
+ # delayRemove: 7000
76
+ # objects :
77
+ # containerID: '#alerts'
78
+ # classes:
79
+ # container: 'alerts'
80
+ # success : 'alert-success'
81
+ # error : 'alert-error'
82
+ # warning : 'alert-warning'
83
+ # info : 'alert-info'
@@ -0,0 +1,35 @@
1
+ describe 'Lol.Core', ->
2
+ core = null
3
+
4
+ beforeEach ->
5
+ core = new Lol.Core()
6
+
7
+ it 'should have standards settings', ->
8
+ expect(core.id).toEqual(null)
9
+ expect(core.debugIndex).toEqual(1)
10
+ expect(core.debugPrefix).toEqual(null)
11
+
12
+ it 'should be able to verify if there is a library jQuery', ->
13
+ expect(core.verifyJQuery()).toEqual(true)
14
+
15
+ it 'should generate its ID', ->
16
+ id = core.id
17
+ core.generateId()
18
+ expect(core.id).not.toEqual(id)
19
+
20
+ it 'should be able to create an unique ID', ->
21
+ id = core.id
22
+ core.generateId()
23
+ expect(core.id).not.toEqual(id)
24
+
25
+ it 'should be able to treat a object', ->
26
+ core.generateId()
27
+ expect(Lol.Utils.getObject core.id).toEqual(core)
28
+ core.destroy()
29
+ expect(Lol.Utils.getObject core.id).toEqual(null)
30
+
31
+ it 'should be able to print messages on console', ->
32
+ index = core.debugIndex
33
+ core.debug()
34
+ expect(core.debugIndex).not.toEqual(index)
35
+
@@ -0,0 +1,14 @@
1
+ describe 'Lol.Debug', ->
2
+
3
+ it 'should be an object', ->
4
+ expect(Lol.Debug).toEqual(jasmine.any Object)
5
+
6
+ it 'should have set standards', ->
7
+ expect(Lol.Debug.paramsDefault.debug).toEqual(false)
8
+ expect(Lol.Debug.paramsDefault.prefix).toEqual('Lol_Debug')
9
+ expect(Lol.Debug.paramsDefault.object_id).toEqual('')
10
+ expect(Lol.Debug.paramsDefault.index).toEqual(1)
11
+ expect(Lol.Debug.paramsDefault.messages).toEqual([])
12
+
13
+ it 'should have a function of impression', ->
14
+ expect(typeof Lol.Debug.print).toEqual('function')
@@ -0,0 +1,7 @@
1
+ describe 'Lol.I18n', ->
2
+
3
+ it 'should have a function translate', ->
4
+ expect(Lol.I18n.translate).toEqual(jasmine.any Function)
5
+
6
+ it 'should be an alias of the function of translation', ->
7
+ expect(Lol.t 'search').toEqual(Lol.I18n.translate 'search')
@@ -0,0 +1,130 @@
1
+ describe 'Lol.Lang', ->
2
+
3
+ it 'should have a translation function', ->
4
+ expect(Lol.t).toBeDefined()
5
+
6
+ describe 'Lol.Lang.en-us', ->
7
+
8
+ beforeEach ->
9
+ Lol.I18n.language = 'en-us'
10
+
11
+ it 'should have a standard for the common', ->
12
+ expect(Lol.t 'search').toEqual('search')
13
+
14
+ it 'should have a standard for the buttons', ->
15
+ expect(Lol.t 'OK').toEqual('OK')
16
+ expect(Lol.t 'CANCEL').toEqual('CANCEL')
17
+ expect(Lol.t 'YES').toEqual('YES')
18
+ expect(Lol.t 'NO').toEqual('NO')
19
+
20
+ it 'should have a standard for the datatable', ->
21
+ expect(Lol.t 'datatable_oAria_sSortAscending').toEqual(': activate to sort column ascending')
22
+ expect(Lol.t 'datatable_oAria_sSortDescending').toEqual(': activate to sort column descending')
23
+ expect(Lol.t 'datatable_oPaginate_sFirst').toEqual('First')
24
+ expect(Lol.t 'datatable_oPaginate_sLast').toEqual('Last')
25
+ expect(Lol.t 'datatable_oPaginate_sNext').toEqual('Next')
26
+ expect(Lol.t 'datatable_oPaginate_sPrevious').toEqual('Previous')
27
+ expect(Lol.t 'datatable_sEmptyTable').toEqual('No data available in table')
28
+ expect(Lol.t 'datatable_sInfo').toEqual('Showing _START_ to _END_ of _TOTAL_ entries')
29
+ expect(Lol.t 'datatable_sInfoEmpty').toEqual('Showing 0 to 0 of 0 entries')
30
+ expect(Lol.t 'datatable_sInfoFiltered').toEqual('(filtered from _MAX_ total entries)')
31
+ expect(Lol.t 'datatable_sInfoPostFix').toEqual('')
32
+ expect(Lol.t 'datatable_sInfoThousands').toEqual(',')
33
+ expect(Lol.t 'datatable_sLengthMenu').toEqual('Show _MENU_ entries')
34
+ expect(Lol.t 'datatable_sLoadingRecords').toEqual('Loading...')
35
+ expect(Lol.t 'datatable_sProcessing').toEqual('Processing...')
36
+ expect(Lol.t 'datatable_sSearch').toEqual("<i class='icon-search'></i>")
37
+ expect(Lol.t 'datatable_search').toEqual('search...')
38
+ expect(Lol.t 'datatable_sUrl').toEqual('')
39
+ expect(Lol.t 'datatable_sZeroRecords').toEqual('No matching records found')
40
+ expect(Lol.t 'datatable_view').toEqual('view')
41
+ expect(Lol.t 'datatable_edit').toEqual('edit')
42
+ expect(Lol.t 'datatable_delete').toEqual('delete')
43
+ expect(Lol.t 'datatable_confirm_delete').toEqual('Are you sure you want to delete this record?<br />This operation can not be undone.')
44
+ expect(Lol.t 'datatable_confirm_delete_title').toEqual('Lol Framework')
45
+
46
+ it 'should have a standard for the buttons', ->
47
+ expect(Lol.t 'date_months_january').toEqual('January')
48
+ expect(Lol.t 'date_months_february').toEqual('February')
49
+ expect(Lol.t 'date_months_march').toEqual('March')
50
+ expect(Lol.t 'date_months_april').toEqual('April')
51
+ expect(Lol.t 'date_months_may').toEqual('May')
52
+ expect(Lol.t 'date_months_june').toEqual('June')
53
+ expect(Lol.t 'date_months_july').toEqual('July')
54
+ expect(Lol.t 'date_months_august').toEqual('August')
55
+ expect(Lol.t 'date_months_september').toEqual('September')
56
+ expect(Lol.t 'date_months_october').toEqual('October')
57
+ expect(Lol.t 'date_months_november').toEqual('November')
58
+ expect(Lol.t 'date_months_december').toEqual('December')
59
+ expect(Lol.t 'date_days_sunday').toEqual('Sunday')
60
+ expect(Lol.t 'date_days_monday').toEqual('Monday')
61
+ expect(Lol.t 'date_days_tuesday').toEqual('Tuesday')
62
+ expect(Lol.t 'date_days_wednesday').toEqual('Wednesday')
63
+ expect(Lol.t 'date_days_thursday').toEqual('Thursday')
64
+ expect(Lol.t 'date_days_friday').toEqual('Friday')
65
+ expect(Lol.t 'date_days_saturday').toEqual('Saturday')
66
+
67
+ describe 'Lol.Lang.pt-br', ->
68
+
69
+ beforeEach ->
70
+ Lol.I18n.language = 'pt-br'
71
+
72
+ it 'should have an identical alias', ->
73
+ expect(Lol.i18n['pt-br']).toEqual(Lol.i18n['pt'])
74
+
75
+ it 'should have a standard for the common', ->
76
+ expect(Lol.t 'search').toEqual('pesquisa')
77
+
78
+ it 'should have a standard for the buttons', ->
79
+ expect(Lol.t 'OK').toEqual('OK')
80
+ expect(Lol.t 'CANCEL').toEqual('CANCELAR')
81
+ expect(Lol.t 'YES').toEqual('SIM')
82
+ expect(Lol.t 'NO').toEqual('NÃO')
83
+
84
+ it 'should have a standard for the datatable', ->
85
+ expect(Lol.t 'datatable_oAria_sSortAscending').toEqual(": ativar para classificar coluna ascendente")
86
+ expect(Lol.t 'datatable_oAria_sSortDescending').toEqual(": ativar para classificar coluna descendente")
87
+ expect(Lol.t 'datatable_oPaginate_sFirst').toEqual("Primeiro")
88
+ expect(Lol.t 'datatable_oPaginate_sLast').toEqual("Último")
89
+ expect(Lol.t 'datatable_oPaginate_sNext').toEqual("Seguinte")
90
+ expect(Lol.t 'datatable_oPaginate_sPrevious').toEqual("Anterior")
91
+ expect(Lol.t 'datatable_sEmptyTable').toEqual("Não há dados disponíveis na tabela")
92
+ expect(Lol.t 'datatable_sInfo').toEqual("Mostrando de _START_ até _END_ de _TOTAL_ registros")
93
+ expect(Lol.t 'datatable_sInfoEmpty').toEqual("Mostrando de 0 até 0 de 0 registros")
94
+ expect(Lol.t 'datatable_sInfoFiltered').toEqual("(filtrado de _MAX_ registros no total)")
95
+ expect(Lol.t 'datatable_sInfoPostFix').toEqual("")
96
+ expect(Lol.t 'datatable_sInfoThousands').toEqual(",")
97
+ expect(Lol.t 'datatable_sLengthMenu').toEqual("Mostrar _MENU_ registros")
98
+ expect(Lol.t 'datatable_sLoadingRecords').toEqual("Carregando...")
99
+ expect(Lol.t 'datatable_sProcessing').toEqual("Processando...")
100
+ expect(Lol.t 'datatable_sSearch').toEqual("<i class='icon-search'></i>")
101
+ expect(Lol.t 'datatable_search').toEqual("buscar")
102
+ expect(Lol.t 'datatable_sUrl').toEqual("")
103
+ expect(Lol.t 'datatable_sZeroRecords').toEqual("Não foram encontrados resultados")
104
+ expect(Lol.t 'datatable_view').toEqual('visualizar')
105
+ expect(Lol.t 'datatable_edit').toEqual('editar')
106
+ expect(Lol.t 'datatable_delete').toEqual('remover')
107
+ expect(Lol.t 'datatable_confirm_delete').toEqual('Você tem certeza que deseja excluir este registro?<br />Esta operação não poderá ser desfeita.')
108
+ expect(Lol.t 'datatable_confirm_delete_title').toEqual('Lol Framework')
109
+
110
+ it 'should have a standard for the buttons', ->
111
+ expect(Lol.t 'date_months_january').toEqual('Janeiro')
112
+ expect(Lol.t 'date_months_february').toEqual('Fevereiro')
113
+ expect(Lol.t 'date_months_march').toEqual('Março')
114
+ expect(Lol.t 'date_months_april').toEqual('Abril')
115
+ expect(Lol.t 'date_months_may').toEqual('Maio')
116
+ expect(Lol.t 'date_months_june').toEqual('Junho')
117
+ expect(Lol.t 'date_months_july').toEqual('Julho')
118
+ expect(Lol.t 'date_months_august').toEqual('Agosto')
119
+ expect(Lol.t 'date_months_september').toEqual('Setembro')
120
+ expect(Lol.t 'date_months_october').toEqual('Outubro')
121
+ expect(Lol.t 'date_months_november').toEqual('Novembro')
122
+ expect(Lol.t 'date_months_december').toEqual('Dezembro')
123
+ expect(Lol.t 'date_days_sunday').toEqual('Domingo')
124
+ expect(Lol.t 'date_days_monday').toEqual('Segunda')
125
+ expect(Lol.t 'date_days_tuesday').toEqual('Terça')
126
+ expect(Lol.t 'date_days_wednesday').toEqual('Quarta')
127
+ expect(Lol.t 'date_days_thursday').toEqual('Quinta')
128
+ expect(Lol.t 'date_days_friday').toEqual('Sexta')
129
+ expect(Lol.t 'date_days_saturday').toEqual('Sábado')
130
+
@@ -0,0 +1,13 @@
1
+ describe 'Requirements framework', ->
2
+
3
+ it 'should have a modification of the Date object', ->
4
+ expect(Date.parseDate).toBeDefined()
5
+
6
+ it 'should have the jquery library', ->
7
+ expect(jQuery).toBeDefined()
8
+
9
+ it 'should have the datatable jquery plugin', ->
10
+ expect(jQuery.fn.dataTable).toBeDefined()
11
+
12
+ it 'should have the browser mobile jquery plugin', ->
13
+ expect(jQuery.browser.mobile).toBeDefined()
@@ -0,0 +1,4 @@
1
+ describe 'Lol', ->
2
+
3
+ it "should be an object", ->
4
+ expect(Lol).toEqual(jasmine.any Object)
@@ -0,0 +1,22 @@
1
+ describe 'Lol.Utils', ->
2
+
3
+ it 'should be an object', ->
4
+ expect(typeof Lol.Utils).toEqual('object')
5
+
6
+ it 'should generate unique ids', ->
7
+ expect(Lol.Utils.uniqid).toBeDefined()
8
+ expect(Lol.Utils.uniqid()).not.toEqual(Lol.Utils.uniqid())
9
+
10
+ it 'should be able to convert objects to string', ->
11
+ expect(Lol.Utils.toString 123 ).toEqual(jasmine.any String)
12
+
13
+ it 'should be able to treat the objects framework', ->
14
+ obj =
15
+ id: Lol.Utils.uniqid()
16
+ expect(Lol.Utils.addObject obj ).toEqual(obj)
17
+ expect(Lol.Utils.getObject obj.id ).toEqual(obj)
18
+ expect(Lol.Utils._object_id.hasOwnProperty obj.id ).toEqual(true)
19
+ expect(Lol.Utils.removeObject obj.id ).toEqual(null)
20
+
21
+ it 'should redirect a function', ->
22
+ expect(Lol.Utils.redirector).toBeDefined()
@@ -0,0 +1,42 @@
1
+ Lol.Utils =
2
+ uniqidSeed: 1
3
+ uniqid: (prefix='', more_entropy)->
4
+ # + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
5
+ # + revised by: Kankrelune (http://www.webfaktory.info/)
6
+ # % note 1: Uses an internal counter (in php_js global) to avoid collision
7
+ # * example 1: uniqid();
8
+ # * returns 1: 'a30285b160c14'
9
+ # * example 2: uniqid('foo');
10
+ # * returns 2: 'fooa30285b1cd361'
11
+ # * example 3: uniqid('bar', true);
12
+ # * returns 3: 'bara20285b23dfd1.31879087'
13
+ formatSeed = (seed, reqWidth)->
14
+ seed = parseInt(seed, 10).toString(16)
15
+ return seed.slice(seed.length - reqWidth) if reqWidth < seed.length
16
+ return Array(1 + (reqWidth - seed.length)).join('0') + seed if reqWidth > seed.length
17
+ seed
18
+
19
+ @uniqidSeed = Math.floor(Math.random() * 0x75bcd15) if not @uniqidSeed
20
+ @uniqidSeed++
21
+
22
+ retId = prefix
23
+ retId += formatSeed(parseInt(new Date().getTime() / 1000, 10), 8)
24
+ retId += formatSeed(@uniqidSeed, 5)
25
+ retId += (Math.random() * 10).toFixed(8).toString() if more_entropy
26
+ retId
27
+
28
+ # Convert to string
29
+ toString: (obj)->
30
+ new String(obj)
31
+
32
+ # Add references objects
33
+ _object_id: {}
34
+ addObject: (obj)->
35
+ @_object_id[obj.id] = obj
36
+ getObject: (id)->
37
+ @_object_id[id]
38
+ removeObject: (id)->
39
+ @_object_id[id] = null
40
+ redirector: (url)->
41
+ window.location = url
42
+