nali 0.3.5 → 0.3.6
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.
- data/lib/client/javascripts/nali/connection.js.coffee +10 -2
- data/lib/client/javascripts/nali/index.js +0 -1
- data/lib/generator/{Gemfile → application/Gemfile} +0 -0
- data/lib/generator/{Rakefile → application/Rakefile} +1 -1
- data/lib/generator/{app → application/app}/client/javascripts/application.js.coffee +0 -0
- data/lib/generator/{app → application/app}/client/javascripts/controllers/homes.js.coffee +0 -0
- data/lib/generator/{app → application/app}/client/javascripts/models/home.js.coffee +0 -0
- data/lib/generator/{app → application/app}/client/javascripts/views/home/index.js.coffee +0 -0
- data/lib/generator/{app → application/app}/client/stylesheets/application.css.sass +0 -0
- data/lib/generator/{app → application/app}/client/stylesheets/home/index.css.sass +0 -0
- data/lib/generator/{app → application/app}/client/stylesheets/notice/error.css.sass +0 -0
- data/lib/generator/{app → application/app}/client/stylesheets/notice/info.css.sass +0 -0
- data/lib/generator/{app → application/app}/client/stylesheets/notice/warning.css.sass +0 -0
- data/lib/generator/{app → application/app}/client/templates/application.html.erb +0 -0
- data/lib/generator/{app → application/app}/client/templates/home/index.html +0 -0
- data/lib/generator/{app → application/app}/client/templates/notice/error.html +0 -0
- data/lib/generator/{app → application/app}/client/templates/notice/info.html +0 -0
- data/lib/generator/{app → application/app}/client/templates/notice/warning.html +0 -0
- data/lib/generator/{app → application/app}/server/clients.rb +0 -0
- data/lib/generator/{app → application/app}/server/controllers/application_controller.rb +0 -0
- data/lib/generator/{app → application/app}/server/models/access.yml +0 -0
- data/lib/generator/{app → application/app}/server/routes.rb +0 -0
- data/lib/generator/application/config.ru +3 -0
- data/lib/generator/{config → application/config}/application.rb +2 -2
- data/lib/generator/{config → application/config}/database.yml +1 -1
- data/lib/generator/{config → application/config}/environments/development.rb +3 -3
- data/lib/generator/{config → application/config}/environments/production.rb +4 -4
- data/lib/generator/{config → application/config}/environments/test.rb +6 -6
- data/lib/generator/templates/client_controller.tpl +3 -0
- data/lib/generator/templates/client_model.tpl +3 -0
- data/lib/generator/templates/client_view.tpl +11 -0
- data/lib/generator/templates/client_view_styles.tpl +1 -0
- data/lib/generator/templates/server_controller.tpl +5 -0
- data/lib/generator/templates/server_model.tpl +9 -0
- data/lib/generator/templates/server_model_access.tpl +6 -0
- data/lib/nali/clients.rb +6 -3
- data/lib/nali/connection.rb +27 -0
- data/lib/nali/generator.rb +48 -102
- data/lib/nali/version.rb +1 -1
- metadata +35 -29
- data/lib/client/javascripts/nali/deferred.js.coffee +0 -16
- data/lib/generator/config.ru +0 -3
@@ -6,7 +6,7 @@ Nali.extend Connection:
|
|
6
6
|
|
7
7
|
open: ->
|
8
8
|
@dispatcher = new WebSocket @Application.wsServer
|
9
|
-
@dispatcher.onopen = ( event ) => @
|
9
|
+
@dispatcher.onopen = ( event ) => @identification()
|
10
10
|
@dispatcher.onclose = ( event ) => @onClose event
|
11
11
|
@dispatcher.onerror = ( event ) => @onError event
|
12
12
|
@dispatcher.onmessage = ( event ) => @onMessage JSON.parse event.data
|
@@ -17,7 +17,7 @@ Nali.extend Connection:
|
|
17
17
|
journal: []
|
18
18
|
reconnectDelay: 0
|
19
19
|
|
20
|
-
onOpen:
|
20
|
+
onOpen: ->
|
21
21
|
@reconnectDelay = 0
|
22
22
|
@trigger 'open'
|
23
23
|
|
@@ -49,10 +49,18 @@ Nali.extend Connection:
|
|
49
49
|
@keepAlive()
|
50
50
|
@
|
51
51
|
|
52
|
+
identification: ->
|
53
|
+
@send nali_browser_id: @Cookie.get( 'nali_browser_id' ) or @Cookie.set 'nali_browser_id', @Model.guid()
|
54
|
+
@
|
55
|
+
|
52
56
|
sync: ( message ) ->
|
53
57
|
@Model.sync message.params
|
54
58
|
@
|
55
59
|
|
60
|
+
appRun: ( { method, params } ) ->
|
61
|
+
@Application[ method ]? params
|
62
|
+
@
|
63
|
+
|
56
64
|
callMethod: ( { model, method, params } ) ->
|
57
65
|
if model is 'Notice' then @Notice[ method ] params
|
58
66
|
else
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,13 +1,13 @@
|
|
1
1
|
Nali::Application.configure :test do |config|
|
2
|
-
|
2
|
+
|
3
3
|
# ActiveRecord::Base.logger = false
|
4
|
-
|
4
|
+
|
5
5
|
# config.client_digest = true
|
6
|
-
|
6
|
+
|
7
7
|
# config.client_debug = true
|
8
|
-
|
8
|
+
|
9
9
|
# config.client.js_compressor = :uglify
|
10
|
-
|
10
|
+
|
11
11
|
# config.client.css_compressor = :scss
|
12
|
-
|
12
|
+
|
13
13
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
.<%= classname %>
|
data/lib/nali/clients.rb
CHANGED
@@ -12,13 +12,16 @@ module Nali
|
|
12
12
|
|
13
13
|
def on_client_connected( client )
|
14
14
|
clients << client
|
15
|
-
client_connected( client ) if respond_to?( :client_connected )
|
16
15
|
end
|
17
16
|
|
18
17
|
def on_received_message( client, message )
|
19
|
-
if message[ :
|
18
|
+
if message[ :nali_browser_id ]
|
19
|
+
client.browser_id = message[ :nali_browser_id ]
|
20
|
+
client_connected( client ) if respond_to?( :client_connected )
|
21
|
+
client.send_json action: :onOpen
|
22
|
+
elsif message[ :ping ]
|
20
23
|
client.send_json action: :pong
|
21
|
-
|
24
|
+
elsif message[ :controller ]
|
22
25
|
name = message[ :controller ].capitalize + 'Controller'
|
23
26
|
if Math.const_defined?( name ) and controller = Object.const_get( name )
|
24
27
|
controller = controller.new( client, message )
|
data/lib/nali/connection.rb
CHANGED
@@ -2,9 +2,24 @@ module EventMachine
|
|
2
2
|
module WebSocket
|
3
3
|
class Connection
|
4
4
|
|
5
|
+
attr_accessor :browser_id
|
6
|
+
|
7
|
+
def all_tabs
|
8
|
+
Nali::Clients.list
|
9
|
+
.select { |client| client.browser_id == self.browser_id }
|
10
|
+
.each{ |client| yield( client ) if block_given? }
|
11
|
+
end
|
12
|
+
|
13
|
+
def other_tabs
|
14
|
+
Nali::Clients.list
|
15
|
+
.select { |client| client != self and client.browser_id == self.browser_id }
|
16
|
+
.each{ |client| yield( client ) if block_given? }
|
17
|
+
end
|
18
|
+
|
5
19
|
def reset
|
6
20
|
@storage = {}
|
7
21
|
@watches = {}
|
22
|
+
self
|
8
23
|
end
|
9
24
|
|
10
25
|
def storage
|
@@ -45,6 +60,7 @@ module EventMachine
|
|
45
60
|
|
46
61
|
def send_json( hash )
|
47
62
|
send hash.to_json
|
63
|
+
self
|
48
64
|
end
|
49
65
|
|
50
66
|
def sync( *models )
|
@@ -56,27 +72,38 @@ module EventMachine
|
|
56
72
|
send_json action: :sync, params: params
|
57
73
|
end
|
58
74
|
end
|
75
|
+
self
|
59
76
|
end
|
60
77
|
|
61
78
|
def call_method( method, model, params = nil )
|
62
79
|
model = "#{ model.class.name }.#{ model.id }" if model.is_a?( ActiveRecord::Base )
|
63
80
|
send_json action: 'callMethod', model: model, method: method, params: params
|
81
|
+
self
|
64
82
|
end
|
65
83
|
|
66
84
|
def notice( method, params = nil )
|
67
85
|
call_method method, 'Notice', params
|
86
|
+
self
|
68
87
|
end
|
69
88
|
|
70
89
|
def info( params )
|
71
90
|
notice :info, params
|
91
|
+
self
|
72
92
|
end
|
73
93
|
|
74
94
|
def warning( params )
|
75
95
|
notice :warning, params
|
96
|
+
self
|
76
97
|
end
|
77
98
|
|
78
99
|
def error( params )
|
79
100
|
notice :error, params
|
101
|
+
self
|
102
|
+
end
|
103
|
+
|
104
|
+
def app_run( method, params = nil )
|
105
|
+
send_json action: 'appRun', method: method, params: params
|
106
|
+
self
|
80
107
|
end
|
81
108
|
|
82
109
|
end
|
data/lib/nali/generator.rb
CHANGED
@@ -16,90 +16,55 @@ module Nali
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def create_application( name )
|
19
|
-
|
20
|
-
|
21
|
-
FileUtils.cp_r
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
19
|
+
source = File.join Nali.path, 'generator/application/.'
|
20
|
+
target = File.join Dir.pwd, name
|
21
|
+
FileUtils.cp_r source, target
|
22
|
+
%w(
|
23
|
+
db
|
24
|
+
db/migrate
|
25
|
+
lib
|
26
|
+
lib/client
|
27
|
+
lib/client/javascripts
|
28
|
+
lib/client/stylesheets
|
29
|
+
public
|
30
|
+
public/client
|
31
|
+
tmp
|
32
|
+
vendor
|
33
|
+
vendor/client
|
34
|
+
vendor/client/javascripts
|
35
|
+
vendor/client/stylesheets
|
36
|
+
config/initializers
|
37
|
+
).each { |dir| unless Dir.exists?( path = File.join( target, dir ) ) then Dir.mkdir( path ) end }
|
38
38
|
puts "Application #{ name } created"
|
39
39
|
end
|
40
|
+
|
41
|
+
def render( name, classname )
|
42
|
+
require 'erb'
|
43
|
+
ERB.new( File.read( File.join( Nali.path, 'generator/templates', "#{ name }.tpl" ) ) ).result binding
|
44
|
+
end
|
45
|
+
|
46
|
+
def write( path, content, mode = 'w' )
|
47
|
+
File.open( File.join( Dir.pwd, path ), mode ) { |file| file.write( content ) }
|
48
|
+
puts ( mode == 'a' ? 'Updated: ' : 'Created: ' ) + path
|
49
|
+
end
|
50
|
+
|
51
|
+
def clean_cache
|
52
|
+
FileUtils.rm_rf File.join( Dir.pwd, 'tmp/cache' )
|
53
|
+
end
|
40
54
|
|
41
55
|
def create_model( name )
|
42
56
|
if Dir.exists?( File.join( Dir.pwd, 'app' ) )
|
43
57
|
if name.scan( '_' ).size > 0
|
44
58
|
return puts 'Please don\'t use the underscore'
|
45
59
|
end
|
60
|
+
clean_cache
|
46
61
|
filename = name.downcase
|
47
62
|
classname = name.camelize
|
48
|
-
|
49
|
-
|
50
|
-
"
|
51
|
-
|
52
|
-
|
53
|
-
)
|
54
|
-
end
|
55
|
-
File.open( File.join( Dir.pwd, "app/client/javascripts/controllers/#{ filename }s.js.coffee" ), 'w' ) do |f|
|
56
|
-
f.write(
|
57
|
-
"Nali.Controller.extend #{ classname }s:
|
58
|
-
|
59
|
-
actions: {}"
|
60
|
-
)
|
61
|
-
end
|
62
|
-
File.open( File.join( Dir.pwd, "app/server/models/#{ filename }.rb" ), 'w' ) do |f|
|
63
|
-
f.write(
|
64
|
-
"class #{ classname } < ActiveRecord::Base
|
65
|
-
|
66
|
-
include Nali::Model
|
67
|
-
|
68
|
-
def access_level( client )
|
69
|
-
:unknown
|
70
|
-
end
|
71
|
-
|
72
|
-
end"
|
73
|
-
)
|
74
|
-
end
|
75
|
-
File.open( File.join( Dir.pwd, "app/server/controllers/#{ filename }s_controller.rb" ), 'w' ) do |f|
|
76
|
-
f.write(
|
77
|
-
"class #{ classname }sController < ApplicationController
|
78
|
-
|
79
|
-
include Nali::Controller
|
80
|
-
|
81
|
-
end"
|
82
|
-
)
|
83
|
-
end
|
84
|
-
File.open( File.join( Dir.pwd, "app/server/models/access.yml" ), 'a' ) do |f|
|
85
|
-
f.write(
|
86
|
-
"
|
87
|
-
|
88
|
-
#{ classname }:
|
89
|
-
create:
|
90
|
-
read:
|
91
|
-
update:
|
92
|
-
destroy:
|
93
|
-
|
94
|
-
"
|
95
|
-
)
|
96
|
-
end
|
97
|
-
FileUtils.rm_rf( File.join( Dir.pwd, "tmp/cache" ) )
|
98
|
-
puts "Created: app/client/javascripts/models/#{ filename }.js.coffee"
|
99
|
-
puts "Created: app/client/javascripts/controllers/#{ filename }s.js.coffee"
|
100
|
-
puts "Created: app/server/models/#{ filename }.rb"
|
101
|
-
puts "Created: app/server/controllers/#{ filename }s_controller.rb"
|
102
|
-
puts "Updated: app/server/models/access.yml"
|
63
|
+
write "app/client/javascripts/models/#{ filename }.js.coffee", render( 'client_model', classname )
|
64
|
+
write "app/client/javascripts/controllers/#{ filename }s.js.coffee", render( 'client_controller', classname )
|
65
|
+
write "app/server/models/#{ filename }.rb", render( 'server_model', classname )
|
66
|
+
write "app/server/controllers/#{ filename }s_controller.rb", render( 'server_controller', classname )
|
67
|
+
write "app/server/models/access.yml", render( 'server_model_access', classname ), 'a'
|
103
68
|
else puts 'Please go to the application folder' end
|
104
69
|
end
|
105
70
|
|
@@ -109,34 +74,15 @@ end"
|
|
109
74
|
filename = filename.join( '_' )
|
110
75
|
classname = name.underscore.camelize
|
111
76
|
if not dirname.empty? and not filename.empty? and not classname.empty?
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
"
|
120
|
-
|
121
|
-
events: []
|
122
|
-
|
123
|
-
helpers: {}
|
124
|
-
|
125
|
-
onDraw: ->
|
126
|
-
|
127
|
-
onShow: ->
|
128
|
-
|
129
|
-
onHide: ->"
|
130
|
-
)
|
131
|
-
end
|
132
|
-
File.open( File.join( Dir.pwd, "app/client/stylesheets/#{ dirname }/#{ filename }.css.sass" ), 'w' ) do |f|
|
133
|
-
f.write( ".#{ classname }" )
|
134
|
-
end
|
135
|
-
File.open( File.join( Dir.pwd, "app/client/templates/#{ dirname }/#{ filename }.html" ), 'w' ) {}
|
136
|
-
FileUtils.rm_rf( File.join( Dir.pwd, "tmp/cache" ) )
|
137
|
-
puts "Created: app/client/javascripts/views/#{ dirname }/#{ filename }.js.coffee"
|
138
|
-
puts "Created: app/client/stylesheets/#{ dirname }/#{ filename }.css.sass"
|
139
|
-
puts "Created: app/client/templates/#{ dirname }/#{ filename }.html"
|
77
|
+
clean_cache
|
78
|
+
[
|
79
|
+
"app/client/javascripts/views/#{ dirname }",
|
80
|
+
"app/client/stylesheets/#{ dirname }",
|
81
|
+
"app/client/templates/#{ dirname }"
|
82
|
+
].each { |dir| unless Dir.exists?( path = File.join( Dir.pwd, dir ) ) then Dir.mkdir( path ) end }
|
83
|
+
write "app/client/javascripts/views/#{ dirname }/#{ filename }.js.coffee", render( 'client_view', classname )
|
84
|
+
write "app/client/stylesheets/#{ dirname }/#{ filename }.css.sass", render( 'client_view_styles', classname )
|
85
|
+
write "app/client/templates/#{ dirname }/#{ filename }.html", ''
|
140
86
|
else puts 'Invalid view name' end
|
141
87
|
else puts 'Please go to the application folder' end
|
142
88
|
end
|
data/lib/nali/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nali
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|
@@ -198,7 +198,6 @@ files:
|
|
198
198
|
- lib/client/javascripts/nali/view.js.coffee
|
199
199
|
- lib/client/javascripts/nali/cookie.js.coffee
|
200
200
|
- lib/client/javascripts/nali/nali.js.coffee
|
201
|
-
- lib/client/javascripts/nali/deferred.js.coffee
|
202
201
|
- lib/client/javascripts/nali/notice.js.coffee
|
203
202
|
- lib/client/javascripts/nali/controller.js.coffee
|
204
203
|
- lib/client/javascripts/nali/jbone.min.js
|
@@ -222,32 +221,39 @@ files:
|
|
222
221
|
- lib/nali/helpers.rb
|
223
222
|
- lib/nali/path.rb
|
224
223
|
- lib/nali/application.rb
|
225
|
-
- lib/generator/
|
226
|
-
- lib/generator/
|
227
|
-
- lib/generator/
|
228
|
-
- lib/generator/
|
229
|
-
- lib/generator/
|
230
|
-
- lib/generator/
|
231
|
-
- lib/generator/
|
232
|
-
- lib/generator/app/client/
|
233
|
-
- lib/generator/app/client/
|
234
|
-
- lib/generator/app/client/
|
235
|
-
- lib/generator/app/client/
|
236
|
-
- lib/generator/app/client/
|
237
|
-
- lib/generator/app/client/
|
238
|
-
- lib/generator/app/client/
|
239
|
-
- lib/generator/app/
|
240
|
-
- lib/generator/app/
|
241
|
-
- lib/generator/app/
|
242
|
-
- lib/generator/app/
|
243
|
-
- lib/generator/
|
244
|
-
- lib/generator/
|
245
|
-
- lib/generator/
|
246
|
-
- lib/generator/
|
247
|
-
- lib/generator/
|
248
|
-
- lib/generator/
|
249
|
-
- lib/generator/
|
250
|
-
- lib/generator/
|
224
|
+
- lib/generator/templates/server_model.tpl
|
225
|
+
- lib/generator/templates/client_model.tpl
|
226
|
+
- lib/generator/templates/client_view.tpl
|
227
|
+
- lib/generator/templates/client_view_styles.tpl
|
228
|
+
- lib/generator/templates/server_controller.tpl
|
229
|
+
- lib/generator/templates/server_model_access.tpl
|
230
|
+
- lib/generator/templates/client_controller.tpl
|
231
|
+
- lib/generator/application/app/client/javascripts/models/home.js.coffee
|
232
|
+
- lib/generator/application/app/client/javascripts/views/home/index.js.coffee
|
233
|
+
- lib/generator/application/app/client/javascripts/controllers/homes.js.coffee
|
234
|
+
- lib/generator/application/app/client/javascripts/application.js.coffee
|
235
|
+
- lib/generator/application/app/client/templates/application.html.erb
|
236
|
+
- lib/generator/application/app/client/templates/notice/error.html
|
237
|
+
- lib/generator/application/app/client/templates/notice/warning.html
|
238
|
+
- lib/generator/application/app/client/templates/notice/info.html
|
239
|
+
- lib/generator/application/app/client/templates/home/index.html
|
240
|
+
- lib/generator/application/app/client/stylesheets/notice/info.css.sass
|
241
|
+
- lib/generator/application/app/client/stylesheets/notice/error.css.sass
|
242
|
+
- lib/generator/application/app/client/stylesheets/notice/warning.css.sass
|
243
|
+
- lib/generator/application/app/client/stylesheets/home/index.css.sass
|
244
|
+
- lib/generator/application/app/client/stylesheets/application.css.sass
|
245
|
+
- lib/generator/application/app/server/models/access.yml
|
246
|
+
- lib/generator/application/app/server/routes.rb
|
247
|
+
- lib/generator/application/app/server/clients.rb
|
248
|
+
- lib/generator/application/app/server/controllers/application_controller.rb
|
249
|
+
- lib/generator/application/Rakefile
|
250
|
+
- lib/generator/application/config.ru
|
251
|
+
- lib/generator/application/config/environments/development.rb
|
252
|
+
- lib/generator/application/config/environments/test.rb
|
253
|
+
- lib/generator/application/config/environments/production.rb
|
254
|
+
- lib/generator/application/config/database.yml
|
255
|
+
- lib/generator/application/config/application.rb
|
256
|
+
- lib/generator/application/Gemfile
|
251
257
|
- bin/nali
|
252
258
|
- LICENSE.txt
|
253
259
|
- Rakefile
|
@@ -1,16 +0,0 @@
|
|
1
|
-
#Nali.extend Deferred:
|
2
|
-
#
|
3
|
-
# new: ( callback ) ->
|
4
|
-
# obj = Object.create @
|
5
|
-
# obj.defer = callback
|
6
|
-
# obj.awaits = []
|
7
|
-
# obj.results = []
|
8
|
-
# obj
|
9
|
-
#
|
10
|
-
# await: ( callback ) ->
|
11
|
-
# wrapper = ( args... ) =>
|
12
|
-
# @results.push callback args...
|
13
|
-
# @awaits.splice @awaits.indexOf( wrapper ), 1
|
14
|
-
# @defer @results unless @awaits.length
|
15
|
-
# @awaits.push wrapper
|
16
|
-
# wrapper
|
data/lib/generator/config.ru
DELETED