nali 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/README.md +19 -14
  2. data/lib/client/javascripts/nali/application.js.coffee +59 -0
  3. data/lib/client/javascripts/nali/collection.js.coffee +188 -0
  4. data/lib/{assets → client}/javascripts/nali/connection.js.coffee +32 -32
  5. data/lib/{assets → client}/javascripts/nali/controller.js.coffee +28 -30
  6. data/lib/{assets → client}/javascripts/nali/cookie.js.coffee +5 -5
  7. data/lib/client/javascripts/nali/deferred.js.coffee +16 -0
  8. data/lib/client/javascripts/nali/extensions.js.coffee +18 -0
  9. data/lib/{assets → client}/javascripts/nali/index.js +2 -1
  10. data/lib/{assets → client}/javascripts/nali/jbone.min.js +1 -1
  11. data/lib/{assets → client}/javascripts/nali/model.js.coffee +208 -118
  12. data/lib/{assets → client}/javascripts/nali/nali.js.coffee +32 -32
  13. data/lib/client/javascripts/nali/notice.js.coffee +29 -0
  14. data/lib/{assets → client}/javascripts/nali/router.js.coffee +20 -22
  15. data/lib/{assets → client}/javascripts/nali/view.js.coffee +63 -60
  16. data/lib/generator/Gemfile +8 -8
  17. data/lib/generator/app/{assets → client}/javascripts/application.js.coffee +1 -1
  18. data/lib/generator/app/{assets → client}/javascripts/controllers/homes.js.coffee +4 -4
  19. data/lib/generator/app/client/javascripts/models/home.js.coffee +5 -0
  20. data/lib/generator/app/client/javascripts/views/home/index.js.coffee +9 -0
  21. data/lib/generator/app/{assets → client}/stylesheets/application.css.sass +1 -1
  22. data/lib/generator/app/{assets → client}/stylesheets/home/index.css.sass +5 -5
  23. data/lib/generator/app/{assets → client}/stylesheets/notices/error.css.sass +1 -1
  24. data/lib/generator/app/{assets → client}/stylesheets/notices/info.css.sass +1 -1
  25. data/lib/generator/app/{assets → client}/stylesheets/notices/warning.css.sass +1 -1
  26. data/lib/generator/app/{templates → client/templates}/application.html.erb +1 -1
  27. data/lib/generator/app/{templates → client/templates}/home/index.html +1 -1
  28. data/lib/generator/app/client/templates/notice/error.html +1 -0
  29. data/lib/generator/app/client/templates/notice/info.html +1 -0
  30. data/lib/generator/app/client/templates/notice/warning.html +1 -0
  31. data/lib/generator/app/server/clients.rb +15 -0
  32. data/lib/generator/app/{controllers → server/controllers}/application_controller.rb +2 -2
  33. data/lib/generator/app/{models → server/models}/access.yml +0 -0
  34. data/lib/generator/{config → app/server}/routes.rb +3 -3
  35. data/lib/generator/config/environments/development.rb +2 -2
  36. data/lib/generator/config/environments/production.rb +4 -4
  37. data/lib/generator/config/environments/test.rb +5 -5
  38. data/lib/nali/application.rb +24 -23
  39. data/lib/nali/connection.rb +14 -31
  40. data/lib/nali/controller.rb +36 -16
  41. data/lib/nali/generator.rb +38 -23
  42. data/lib/nali/helpers.rb +3 -3
  43. data/lib/nali/model.rb +36 -22
  44. data/lib/nali/tasks.rb +16 -25
  45. data/lib/nali/version.rb +2 -2
  46. metadata +85 -86
  47. data/lib/assets/javascripts/nali/application.js.coffee +0 -28
  48. data/lib/assets/javascripts/nali/collection.js.coffee +0 -150
  49. data/lib/assets/javascripts/nali/extensions.js.coffee +0 -19
  50. data/lib/assets/javascripts/nali/notice.js.coffee +0 -14
  51. data/lib/generator/app/assets/javascripts/models/home.js.coffee +0 -3
  52. data/lib/generator/app/assets/javascripts/views/home/index.js.coffee +0 -1
  53. data/lib/generator/app/templates/notice/error.html +0 -1
  54. data/lib/generator/app/templates/notice/info.html +0 -1
  55. data/lib/generator/app/templates/notice/warning.html +0 -1
  56. data/lib/generator/config/clients.rb +0 -19
  57. data/lib/generator/config/environments/development.rb~ +0 -32
  58. data/lib/generator/config/environments/production.rb~ +0 -80
@@ -1,28 +0,0 @@
1
- Nali.extend Application:
2
-
3
- domEngine: jBone.noConflict()
4
- wsServer: 'ws://' + window.location.host
5
- defaultUrl: 'home'
6
- notFoundUrl: 'home'
7
- htmlContainer: 'body'
8
- title: 'Application'
9
- keepAliveDelay: 20
10
-
11
- run: ( options ) ->
12
- @::starting()
13
- @[ key ] = value for key, value of options
14
- document.addEventListener 'DOMContentLoaded', =>
15
- document.removeEventListener 'DOMContentLoaded', arguments.callee, false
16
- @::_ = @domEngine
17
- @htmlContainer = @_ @htmlContainer
18
- @setTitle @title
19
- @trigger 'start'
20
- , false
21
-
22
- setTitle: ( @title ) ->
23
- unless @titleBox
24
- @_( '<title>' ).appendTo 'head' unless @_( 'head title' ).lenght
25
- @titleBox = @_ 'head title'
26
- @titleBox[0].innerText = @title
27
- @trigger 'update.title'
28
- @
@@ -1,150 +0,0 @@
1
- Nali.extend Collection:
2
-
3
- toShowViews: []
4
- visibleViews: []
5
- length: 0
6
-
7
- cloning: ->
8
- @subscribeTo @Model, "create.#{ @model._name.lowercase() }", @onModelCreated
9
- @adaptations = []
10
- @ordering = {}
11
- @adaptCollection()
12
- @
13
-
14
- onModelCreated: ( model ) ->
15
- @add model if model.isCorrect @filters
16
- @
17
-
18
- onModelUpdated: ( model ) ->
19
- if model.isCorrect @filters then @reorder() else @remove model
20
- @
21
-
22
- onModelDestroyed: ( model ) ->
23
- @remove model
24
- @
25
-
26
- adaptCollection: ->
27
- for name, method of @model when /^_\w+$/.test( name ) and typeof method is 'function'
28
- do ( name, method ) =>
29
- @[ name = name[ 1.. ] ] = ( args... ) =>
30
- @adaptation ( model ) -> model[ name ] args...
31
- @
32
- @
33
-
34
- adaptModel: ( model ) ->
35
- adaptation.call @, model for adaptation in @adaptations
36
- @
37
-
38
- adaptation: ( callback ) ->
39
- callback.call @, model for model in @
40
- @adaptations.push callback
41
- @
42
-
43
- add: ( model ) ->
44
- Array::push.call @, model
45
- @adaptModel model
46
- @subscribeTo model, 'destroy', @onModelDestroyed
47
- @subscribeTo model, 'update', @onModelUpdated
48
- @reorder()
49
- @trigger 'update'
50
- @trigger 'update.length'
51
- @
52
-
53
- indexOf: ( model ) ->
54
- Array::indexOf.call @, model
55
-
56
- remove: ( model ) ->
57
- Array::splice.call @, @indexOf( model ), 1
58
- @unsubscribeTo model
59
- @reorder()
60
- @trigger 'update'
61
- @trigger 'update.length'
62
- @
63
-
64
- removeAll: ->
65
- delete @[ index ] for model, index in @
66
- @length = 0
67
- @
68
-
69
- sort: ( sorter ) ->
70
- Array::sort.call @, sorter
71
- @
72
-
73
- order: ( @ordering ) ->
74
- @reorder()
75
- @
76
-
77
- reorder: ->
78
- if @ordering.by?
79
- clearTimeout @ordering.timer if @ordering.timer?
80
- @ordering.timer = setTimeout =>
81
- if typeof @ordering.by is 'function'
82
- @sort @ordering.by
83
- else
84
- @sort ( one, two ) =>
85
- one = one[ @ordering.by ]
86
- two = two[ @ordering.by ]
87
- if @ordering.as is 'number'
88
- one = + one
89
- two = + two
90
- if @ordering.as is 'string'
91
- one = '' + one
92
- two = '' + two
93
- ( if one > two then 1 else if one < two then -1 else 0 ) * ( if @ordering.desc then -1 else 1 )
94
- @orderViews()
95
- delete @ordering.timer
96
- , 5
97
- @
98
-
99
- orderViews: ->
100
- if @inside
101
- children = Array::slice.call @inside.children
102
- children.sort ( one, two ) => @indexOf( one.view.model ) - @indexOf( two.view.model )
103
- @inside.appendChild child for child in children
104
- @
105
-
106
- show: ( viewName, insertTo, isRelation = false ) ->
107
- @adaptation ( model ) ->
108
- view = model.view viewName
109
- if isRelation
110
- view.subscribeTo @, 'reset', view.hide
111
- else unless @visible
112
- @visible = true
113
- @prepareViewToShow view
114
- @hideVisibleViews()
115
- else
116
- @::visibleViews.push view
117
- view.show insertTo
118
- @inside ?= view.element[0].parentNode
119
- @
120
-
121
- prepareViewToShow: ( view ) ->
122
- unless view in @::toShowViews
123
- @::toShowViews.push view
124
- @prepareViewToShow layout if ( layout = view.layout() )?.childOf? 'View'
125
- @
126
-
127
- hideVisibleViews: ->
128
- view.hide() for view in @::visibleViews when not( view in @::toShowViews )
129
- @::visibleViews = @::toShowViews
130
- @::toShowViews = []
131
- @
132
-
133
- first: ->
134
- @[0]
135
-
136
- last: ->
137
- @[ @length - 1 ]
138
-
139
- reset: ->
140
- @inside = null
141
- @adaptations.length = 0
142
- @trigger 'reset'
143
- @
144
-
145
- destroy: ->
146
- @trigger 'destroy'
147
- @destroyObservation()
148
- @removeAll()
149
- @reset()
150
- @
@@ -1,19 +0,0 @@
1
- String::uppercase = ->
2
- "#{ @toUpperCase() }"
3
-
4
- String::lowercase = ->
5
- "#{ @toLowerCase() }"
6
-
7
- String::capitalize = ->
8
- @charAt(0).uppercase() + @slice(1)
9
-
10
- String::uncapitalize = ->
11
- @charAt(0).lowercase() + @slice(1)
12
-
13
- String::camelcase = ->
14
- @replace /(_[^_]+)/g, ( match ) -> match[ 1.. ].capitalize()
15
-
16
- String::underscore = ->
17
- str = @replace /([A-Z])/g, ( match ) -> '_' + match.lowercase()
18
- if str[ 0...1 ] is '_' then str[ 1.. ] else str
19
-
@@ -1,14 +0,0 @@
1
- Nali.Model.extend Notice:
2
- initialize: -> @::::Notice = @
3
- info: ( params ) -> @build( params ).show 'info'
4
- warning: ( params ) -> @build( params ).show 'warning'
5
- error: ( params ) -> @build( params ).show 'error'
6
-
7
- Nali.View.extend NoticeInfo:
8
- onShow: -> @hide 3000
9
-
10
- Nali.View.extend NoticeWarning:
11
- onShow: -> @hide 3000
12
-
13
- Nali.View.extend NoticeError:
14
- onShow: -> @hide 3000
@@ -1,3 +0,0 @@
1
- Nali.Model.extend Home:
2
-
3
- forced: true
@@ -1 +0,0 @@
1
- Nali.View.extend HomeIndex: {}
@@ -1 +0,0 @@
1
- { @message }
@@ -1 +0,0 @@
1
- { @message }
@@ -1 +0,0 @@
1
- { @message }
@@ -1,19 +0,0 @@
1
- module Nali
2
-
3
- module Clients
4
-
5
- def client_connected( client )
6
-
7
- end
8
-
9
- def on_message( client, message )
10
-
11
- end
12
-
13
- def client_disconnected( client )
14
-
15
- end
16
-
17
- end
18
-
19
- end
@@ -1,32 +0,0 @@
1
- Evo::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb.
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the web server when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Do not eager load code on boot.
10
- config.eager_load = false
11
-
12
- # Show full error reports and disable caching.
13
- config.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
15
-
16
- config.middleware.delete Rack::Lock
17
-
18
- # Don't care if the mailer can't send.
19
- config.action_mailer.raise_delivery_errors = false
20
-
21
- # Print deprecation notices to the Rails logger.
22
- config.active_support.deprecation = :log
23
-
24
- # Raise an error on page load if there are pending migrations
25
- config.active_record.migration_error = :page_load
26
-
27
- # Debug mode disables concatenation and preprocessing of assets.
28
- # This option may cause significant delays in view rendering with a large
29
- # number of complex assets.
30
- config.assets.debug = true
31
- config.log_level = :error
32
- end
@@ -1,80 +0,0 @@
1
- Evo::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb.
3
-
4
- # Code is not reloaded between requests.
5
- config.cache_classes = true
6
-
7
- # Eager load code on boot. This eager loads most of Rails and
8
- # your application in memory, allowing both thread web servers
9
- # and those relying on copy on write to perform better.
10
- # Rake tasks automatically ignore this option for performance.
11
- config.eager_load = true
12
-
13
- # Full error reports are disabled and caching is turned on.
14
- config.consider_all_requests_local = false
15
- config.action_controller.perform_caching = true
16
-
17
- # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
- # Add `rack-cache` to your Gemfile before enabling this.
19
- # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20
- # config.action_dispatch.rack_cache = true
21
-
22
- # Disable Rails's static asset server (Apache or nginx will already do this).
23
- config.serve_static_assets = false
24
-
25
- # Compress JavaScripts and CSS.
26
- config.assets.js_compressor = :uglifier
27
- # config.assets.css_compressor = :sass
28
-
29
- # Do not fallback to assets pipeline if a precompiled asset is missed.
30
- config.assets.compile = false
31
-
32
- # Generate digests for assets URLs.
33
- config.assets.digest = true
34
-
35
- # Version of your assets, change this if you want to expire all your assets.
36
- config.assets.version = '1.0'
37
-
38
- # Specifies the header that your server uses for sending files.
39
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
40
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
41
-
42
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
43
- # config.force_ssl = true
44
-
45
- # Set to :debug to see everything in the log.
46
- config.log_level = :info
47
-
48
- # Prepend all log lines with the following tags.
49
- # config.log_tags = [ :subdomain, :uuid ]
50
-
51
- # Use a different logger for distributed setups.
52
- # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
53
-
54
- # Use a different cache store in production.
55
- # config.cache_store = :mem_cache_store
56
-
57
- # Enable serving of images, stylesheets, and JavaScripts from an asset server.
58
- # config.action_controller.asset_host = "http://assets.example.com"
59
-
60
- # Precompile additional assets.
61
- # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
62
- # config.assets.precompile += %w( search.js )
63
-
64
- # Ignore bad email addresses and do not raise email delivery errors.
65
- # Set this to true and configure the email server for immediate delivery to raise delivery errors.
66
- # config.action_mailer.raise_delivery_errors = false
67
-
68
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
69
- # the I18n.default_locale when a translation can not be found).
70
- config.i18n.fallbacks = true
71
-
72
- # Send deprecation notices to registered listeners.
73
- config.active_support.deprecation = :notify
74
-
75
- # Disable automatic flushing of the log to improve performance.
76
- # config.autoflush_log = false
77
-
78
- # Use default logging formatter so that PID and timestamp are not suppressed.
79
- config.log_formatter = ::Logger::Formatter.new
80
- end