nali 0.2.1 → 0.2.2
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/assets/javascripts/nali/controller.js.coffee +23 -30
- data/lib/assets/javascripts/nali/extensions.js.coffee +3 -0
- data/lib/assets/javascripts/nali/model.js.coffee +21 -7
- data/lib/assets/javascripts/nali/nali.js.coffee +10 -5
- data/lib/assets/javascripts/nali/router.js.coffee +14 -14
- data/lib/assets/javascripts/nali/view.js.coffee +9 -4
- data/lib/generator/app/controllers/application_controller.rb +3 -0
- data/lib/generator/config/clients.rb +3 -3
- data/lib/nali.rb +1 -1
- data/lib/nali/application.rb +6 -3
- data/lib/nali/clients.rb +14 -19
- data/lib/nali/controller.rb +77 -10
- data/lib/nali/extensions.rb +3 -3
- data/lib/nali/generator.rb +33 -21
- data/lib/nali/helpers.rb +2 -2
- data/lib/nali/model.rb +1 -1
- data/lib/nali/tasks.rb +2 -2
- data/lib/nali/version.rb +1 -1
- metadata +4 -3
@@ -9,69 +9,62 @@ Nali.extend Controller:
|
|
9
9
|
actions: {}
|
10
10
|
|
11
11
|
prepareActions: ->
|
12
|
-
@
|
13
|
-
@preparedActions = {}
|
12
|
+
@_actions = {}
|
14
13
|
for name, action of @actions when not ( name in [ 'default', 'before', 'after' ] )
|
15
14
|
[ name, filters... ] = name.split '/'
|
16
15
|
params = []
|
17
16
|
for filter in filters[ 0.. ] when /^:/.test filter
|
18
17
|
filters.splice filters.indexOf( filter ), 1
|
19
18
|
params.push filter[ 1.. ]
|
20
|
-
@
|
21
|
-
@preparedActions[ name ] = [ action ]
|
19
|
+
@_actions[ name ] = filters: filters, params: params, methods: [ action ]
|
22
20
|
@prepareBefores()
|
23
21
|
@prepareAfters()
|
24
22
|
@
|
25
23
|
|
26
24
|
prepareBefores: ->
|
27
25
|
if @actions.before?
|
28
|
-
|
29
|
-
for
|
30
|
-
for name in names.split /\s*,\s*/
|
31
|
-
( beforeActions[ name ] ?= [] ).push action
|
32
|
-
for name, actions of beforeActions
|
33
|
-
@preparedActions[ name ] = actions.concat @preparedActions[ name ]
|
26
|
+
list = @analizeFilters 'before'
|
27
|
+
@_actions[ name ].methods = actions.concat @_actions[ name ].methods for name, actions of list
|
34
28
|
@
|
35
29
|
|
36
30
|
prepareAfters: ->
|
37
31
|
if @actions.after?
|
38
|
-
|
39
|
-
for
|
40
|
-
for name in names.split /\s*,\s*/
|
41
|
-
( afterActions[ name ] ?= [] ).push action
|
42
|
-
for name, actions of afterActions
|
43
|
-
@preparedActions[ name ] = @preparedActions[ name ].concat actions
|
32
|
+
list = @analizeFilters 'after'
|
33
|
+
@_actions[ name ].methods = @_actions[ name ].methods.concat actions for name, actions of list
|
44
34
|
@
|
45
35
|
|
36
|
+
analizeFilters: ( type ) ->
|
37
|
+
list = {}
|
38
|
+
for names, action of @actions[ type ]
|
39
|
+
[ invert, names ] = switch
|
40
|
+
when /^!\s*/.test names then [ true, names.replace( /^!\s*/, '' ).split /\s*,\s*/ ]
|
41
|
+
when names is '*' then [ true, [] ]
|
42
|
+
else [ false, names.split /\s*,\s*/ ]
|
43
|
+
for name of @_actions when ( invert and not ( name in names ) ) or ( not invert and name in names )
|
44
|
+
( list[ name ] ?= [] ).push action
|
45
|
+
list
|
46
|
+
|
46
47
|
run: ( action, filters, params ) ->
|
47
48
|
controller = @clone
|
48
49
|
collection: @Model.extensions[ @modelSysname ].where filters
|
49
50
|
params: params
|
50
51
|
controller.runAction action
|
51
|
-
if controller.
|
52
|
+
if controller.stopped
|
52
53
|
controller.collection.destroy()
|
53
54
|
else
|
54
55
|
controller.collection.show action
|
55
|
-
@
|
56
|
+
@Router.setUrl()
|
56
57
|
@
|
57
58
|
|
58
59
|
runAction: ( name ) ->
|
59
|
-
|
60
|
+
method.call @ for method in @_actions[ name ].methods when not @stopped
|
60
61
|
@
|
61
62
|
|
62
|
-
|
63
|
-
@
|
63
|
+
stop: ->
|
64
|
+
@stopped = true
|
64
65
|
@
|
65
66
|
|
66
67
|
redirect: ( args... ) ->
|
67
68
|
@Router.go args...
|
68
|
-
@
|
69
|
-
@
|
70
|
-
|
71
|
-
changeUrl: ( action, filters ) ->
|
72
|
-
params = ( value for own key, value of filters )
|
73
|
-
url = @_name.lowercase().replace /s$/, ''
|
74
|
-
url += if action is @actions.default then '' else '/' + action
|
75
|
-
url += '/' + params.join '/' if params.length
|
76
|
-
@Router.setUrl url
|
69
|
+
@stop()
|
77
70
|
@
|
@@ -6,6 +6,9 @@ Nali.extend Model:
|
|
6
6
|
@table.index = {}
|
7
7
|
@adapt()
|
8
8
|
@
|
9
|
+
|
10
|
+
cloning: ->
|
11
|
+
@views = {}
|
9
12
|
|
10
13
|
tables: {}
|
11
14
|
hasOne: []
|
@@ -19,6 +22,18 @@ Nali.extend Model:
|
|
19
22
|
do ( name, method ) =>
|
20
23
|
if typeof method is 'function'
|
21
24
|
@[ name[ 1.. ] ] = ( args... ) -> @[ name ] args...
|
25
|
+
@adaptViews()
|
26
|
+
@
|
27
|
+
|
28
|
+
adaptViews: ->
|
29
|
+
@views = {}
|
30
|
+
for name, view of @View.extensions when name.indexOf( @_name ) >= 0
|
31
|
+
do ( name, view ) =>
|
32
|
+
@views[ short = view._shortName ] = view
|
33
|
+
unless @[ short ]?
|
34
|
+
@[ short ] = ->
|
35
|
+
@show short
|
36
|
+
@
|
22
37
|
@
|
23
38
|
|
24
39
|
notice: ( params ) ->
|
@@ -223,11 +238,10 @@ Nali.extend Model:
|
|
223
238
|
# работа с видами
|
224
239
|
|
225
240
|
view: ( name ) ->
|
226
|
-
#
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
view = ( ( @views ?= {} )[ name ] = view.clone( model: @ ) )
|
241
|
+
# возвращает объект вида, либо новый, либо ранее созданный
|
242
|
+
unless ( view = @views[ name ] )?
|
243
|
+
if ( view = @::views[ name ] )?
|
244
|
+
view = @views[ name ] = view.clone model: @
|
231
245
|
else console.error "View %s of model %O does not exist", name, @
|
232
246
|
view
|
233
247
|
|
@@ -236,12 +250,12 @@ Nali.extend Model:
|
|
236
250
|
# вставка произойдет в элемент указанный в самом виде либо в элемент приложения )
|
237
251
|
# функция возвращает объект вида при успехе либо null при неудаче
|
238
252
|
if ( view = @view( name ) )? then view.show insertTo else null
|
239
|
-
|
253
|
+
|
240
254
|
hide: ( name ) ->
|
241
255
|
# удаляет html-код вида со страницы
|
242
256
|
# функция возвращает объект вида при успехе либо null при неудаче
|
243
257
|
if ( view = @view( name ) )? then view.hide() else null
|
244
|
-
|
258
|
+
|
245
259
|
# валидации
|
246
260
|
|
247
261
|
validations:
|
@@ -1,6 +1,8 @@
|
|
1
|
+
window.__ = ( args... ) -> console.log args...
|
2
|
+
|
1
3
|
window.Nali =
|
2
4
|
|
3
|
-
_name:
|
5
|
+
_name: 'Nali'
|
4
6
|
extensions: {}
|
5
7
|
|
6
8
|
starting: ->
|
@@ -15,11 +17,10 @@ window.Nali =
|
|
15
17
|
param._name = name
|
16
18
|
@[ name ] = @extensions[ name ] = @child param
|
17
19
|
@[ name ].extensions = {}
|
18
|
-
@[ name ].initObservation()
|
19
20
|
|
20
21
|
clone: ( params = {} ) ->
|
21
22
|
obj = @child params
|
22
|
-
obj.
|
23
|
+
obj.runCloning()
|
23
24
|
obj
|
24
25
|
|
25
26
|
child: ( params ) ->
|
@@ -51,6 +52,10 @@ window.Nali =
|
|
51
52
|
runExtensions: ( context = @ ) ->
|
52
53
|
@::?.runExtensions context
|
53
54
|
@extension.call context if @hasOwnProperty 'extension'
|
55
|
+
|
56
|
+
runCloning: ( context = @ ) ->
|
57
|
+
@::?.runCloning context
|
58
|
+
@cloning.call context if @hasOwnProperty 'cloning'
|
54
59
|
|
55
60
|
getter: ( property, callback ) ->
|
56
61
|
@__defineGetter__ property, callback
|
@@ -68,8 +73,8 @@ window.Nali =
|
|
68
73
|
@
|
69
74
|
|
70
75
|
initObservation: ->
|
71
|
-
@observers = []
|
72
|
-
@observables = []
|
76
|
+
@observers = []
|
77
|
+
@observables = []
|
73
78
|
@
|
74
79
|
|
75
80
|
destroyObservation: ->
|
@@ -20,16 +20,15 @@ Nali.extend Router:
|
|
20
20
|
scanRoutes: ->
|
21
21
|
for name, controller of @Controller.extensions when controller.actions?
|
22
22
|
route = '^'
|
23
|
-
route += name.lowercase().replace /s$/, ''
|
23
|
+
route += name.lowercase().replace /s$/, 's*(\/|$)'
|
24
24
|
route += '('
|
25
|
-
route += Object.keys( controller.
|
25
|
+
route += Object.keys( controller._actions ).join '|'
|
26
26
|
route += ')?'
|
27
27
|
@routes[ route ] = controller
|
28
28
|
@
|
29
29
|
|
30
30
|
go: ( url = window.location.pathname, options = {} ) ->
|
31
|
-
|
32
|
-
if found = @findRoute url
|
31
|
+
if found = @findRoute @prepare( url ) or @prepare( @Application.defaultUrl )
|
33
32
|
{ controller, action, filters, params } = found
|
34
33
|
params[ name ] = value for name, value in options
|
35
34
|
controller.run action, filters, params
|
@@ -46,29 +45,30 @@ Nali.extend Router:
|
|
46
45
|
|
47
46
|
findRoute: ( url ) ->
|
48
47
|
for route, controller of @routes when match = url.match new RegExp route, 'i'
|
49
|
-
segments = url.split( '/' )[ 1... ]
|
50
|
-
if segments[0] in Object.keys( controller.
|
48
|
+
segments = ( @routedUrl = url ).split( '/' )[ 1... ]
|
49
|
+
if segments[0] in Object.keys( controller._actions )
|
51
50
|
action = segments.shift()
|
52
51
|
else unless action = controller.actions.default
|
53
52
|
console.error 'Unspecified controller action'
|
54
53
|
filters = {}
|
55
|
-
for name in controller.
|
54
|
+
for name in controller._actions[ action ].filters when segments[0]?
|
56
55
|
filters[ name ] = segments.shift()
|
57
56
|
params = {}
|
58
|
-
for name in controller.
|
57
|
+
for name in controller._actions[ action ].params when segments[0]?
|
59
58
|
params[ name ] = segments.shift()
|
60
59
|
return controller: controller, action: action, filters: filters, params: params
|
61
60
|
false
|
62
61
|
|
63
62
|
saveHistory: ( value ) ->
|
64
|
-
@
|
63
|
+
@_saveHistory ?= true
|
65
64
|
if value in [ true, false ]
|
66
|
-
@
|
65
|
+
@_saveHistory = value
|
67
66
|
@
|
68
|
-
else @
|
69
|
-
|
70
|
-
setUrl: ( url ) ->
|
67
|
+
else @_saveHistory
|
68
|
+
|
69
|
+
setUrl: ( url = null ) ->
|
71
70
|
if @saveHistory()
|
72
|
-
|
71
|
+
@routedUrl = url if url?
|
72
|
+
history.pushState null, null, '/' + ( @url = @routedUrl ) if @routedUrl isnt @url
|
73
73
|
else @saveHistory true
|
74
74
|
@
|
@@ -2,6 +2,7 @@ Nali.extend View:
|
|
2
2
|
|
3
3
|
extension: ->
|
4
4
|
if @_name isnt 'View'
|
5
|
+
@_shortName = @_name.underscore().split( '_' )[ 1.. ].join '_'
|
5
6
|
@parseTemplate()
|
6
7
|
@parseEvents()
|
7
8
|
@
|
@@ -32,7 +33,7 @@ Nali.extend View:
|
|
32
33
|
show: ( insertTo = @insertTo() ) ->
|
33
34
|
@prepareElement().draw().bindEvents()
|
34
35
|
unless @visible
|
35
|
-
@
|
36
|
+
@runModelCallback 'beforeShow'
|
36
37
|
@runAssistants 'show'
|
37
38
|
@subscribeTo @model, 'update', @onSourceUpdated
|
38
39
|
@subscribeTo @model, 'destroy', @onSourceDestroyed
|
@@ -40,12 +41,12 @@ Nali.extend View:
|
|
40
41
|
@showRelations()
|
41
42
|
setTimeout ( => @onShow() ), 5 if @onShow?
|
42
43
|
@visible = true
|
43
|
-
@
|
44
|
+
@runModelCallback 'afterShow'
|
44
45
|
@
|
45
46
|
|
46
47
|
hide: ( delay = 0 ) ->
|
47
48
|
if @visible
|
48
|
-
@
|
49
|
+
@runModelCallback 'beforeHide'
|
49
50
|
@hideDelay = delay if typeof( delay ) is 'number' and delay
|
50
51
|
@onHide?()
|
51
52
|
@trigger 'hide'
|
@@ -53,7 +54,7 @@ Nali.extend View:
|
|
53
54
|
@hideElement()
|
54
55
|
@destroyObservation()
|
55
56
|
@visible = false
|
56
|
-
@
|
57
|
+
@runModelCallback 'afterHide'
|
57
58
|
@
|
58
59
|
|
59
60
|
hideElement: ->
|
@@ -64,6 +65,10 @@ Nali.extend View:
|
|
64
65
|
@element[0].parentNode.removeChild @element[0]
|
65
66
|
@
|
66
67
|
|
68
|
+
runModelCallback: ( type ) ->
|
69
|
+
@model[ type ]?[ @_shortName ]?.call @model
|
70
|
+
@
|
71
|
+
|
67
72
|
showRelations: ->
|
68
73
|
for { selector, name, view } in @relationsMap
|
69
74
|
if ( relation = @model[ name ] )?
|
@@ -2,15 +2,15 @@ module Nali
|
|
2
2
|
|
3
3
|
module Clients
|
4
4
|
|
5
|
-
def
|
5
|
+
def client_connected( client )
|
6
6
|
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def on_message( client, message )
|
10
10
|
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def client_disconnected( client )
|
14
14
|
|
15
15
|
end
|
16
16
|
|
data/lib/nali.rb
CHANGED
data/lib/nali/application.rb
CHANGED
@@ -43,6 +43,8 @@ module Nali
|
|
43
43
|
end
|
44
44
|
|
45
45
|
require File.join( root, 'config/routes' )
|
46
|
+
|
47
|
+
include Nali::Clients
|
46
48
|
|
47
49
|
get '/*' do
|
48
50
|
if !request.websocket?
|
@@ -54,9 +56,9 @@ module Nali
|
|
54
56
|
end
|
55
57
|
else
|
56
58
|
request.websocket do |client|
|
57
|
-
client.onopen {
|
58
|
-
client.onmessage { |message|
|
59
|
-
client.onclose {
|
59
|
+
client.onopen { on_client_connected client }
|
60
|
+
client.onmessage { |message| on_received_message( client, JSON.parse( message ).keys_to_sym! ) }
|
61
|
+
client.onclose { on_client_disconnected client }
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -71,6 +73,7 @@ module Nali
|
|
71
73
|
|
72
74
|
def self.initialize!
|
73
75
|
Dir[ File.join( root, 'lib/*/**/*.rb' ) ].each { |file| require( file ) }
|
76
|
+
require File.join( root, 'app/controllers/application_controller.rb' )
|
74
77
|
Dir[ File.join( root, 'app/**/*.rb' ) ].each { |file| require( file ) }
|
75
78
|
require File.join( root, 'config/application' )
|
76
79
|
require File.join( root, 'config/clients' )
|
data/lib/nali/clients.rb
CHANGED
@@ -2,41 +2,36 @@ module Nali
|
|
2
2
|
|
3
3
|
module Clients
|
4
4
|
|
5
|
-
def self.
|
6
|
-
@@
|
5
|
+
def self.list
|
6
|
+
@@list ||= []
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def clients
|
10
|
+
Nali::Clients.list
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_client_connected( client )
|
10
14
|
clients << client
|
11
|
-
client_connected client
|
15
|
+
client_connected( client ) if respond_to?( :client_connected )
|
12
16
|
end
|
13
17
|
|
14
|
-
def
|
18
|
+
def on_received_message( client, message )
|
15
19
|
if message[ :ping ]
|
16
20
|
client.send_json action: :pong
|
17
21
|
else
|
18
22
|
if controller = Object.const_get( message[ :controller ].capitalize + 'Controller' )
|
19
23
|
controller = controller.new( client, message )
|
20
|
-
if controller.
|
21
|
-
controller.
|
24
|
+
if controller.respond_to?( action = message[ :action ].to_sym )
|
25
|
+
controller.runAction action
|
22
26
|
else puts "Action #{ action } not exists in #{ controller }" end
|
23
27
|
else puts "Controller #{ controller } not exists" end
|
24
|
-
on_message client, message
|
28
|
+
on_message( client, message ) if respond_to?( :on_message )
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
32
|
+
def on_client_disconnected( client )
|
29
33
|
clients.delete client
|
30
|
-
client_disconnected client
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.client_connected( client )
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.on_message( client, message )
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.client_disconnected( client )
|
34
|
+
client_disconnected( client ) if respond_to?( :client_disconnected )
|
40
35
|
end
|
41
36
|
|
42
37
|
end
|
data/lib/nali/controller.rb
CHANGED
@@ -4,6 +4,20 @@ module Nali
|
|
4
4
|
|
5
5
|
attr_reader :client, :params, :message
|
6
6
|
|
7
|
+
def self.included( base )
|
8
|
+
base.extend self
|
9
|
+
base.class_eval do
|
10
|
+
self.class_variable_set :@@befores, []
|
11
|
+
self.class_variable_set :@@afters, []
|
12
|
+
def self.befores
|
13
|
+
self.class_variable_get :@@befores
|
14
|
+
end
|
15
|
+
def self.afters
|
16
|
+
self.class_variable_get :@@afters
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
7
21
|
def initialize( client, message )
|
8
22
|
@client = client
|
9
23
|
@message = message
|
@@ -11,7 +25,7 @@ module Nali
|
|
11
25
|
end
|
12
26
|
|
13
27
|
def clients
|
14
|
-
Nali::Clients.
|
28
|
+
Nali::Clients.list
|
15
29
|
end
|
16
30
|
|
17
31
|
def save
|
@@ -64,21 +78,74 @@ module Nali
|
|
64
78
|
client.send_json( { action: 'failure', params: params, journal_id: message[ :journal_id ] } )
|
65
79
|
end
|
66
80
|
|
67
|
-
|
81
|
+
def before( &closure )
|
82
|
+
register_before closure: closure, except: []
|
83
|
+
end
|
68
84
|
|
69
|
-
def
|
70
|
-
|
71
|
-
params
|
85
|
+
def before_only( *methods, &closure )
|
86
|
+
register_before closure: closure, only: methods
|
72
87
|
end
|
73
88
|
|
74
|
-
def
|
75
|
-
|
89
|
+
def before_except( *methods, &closure )
|
90
|
+
register_before closure: closure, except: methods
|
76
91
|
end
|
77
|
-
|
78
|
-
def
|
79
|
-
|
92
|
+
|
93
|
+
def after( &closure )
|
94
|
+
register_after closure: closure, except: []
|
95
|
+
end
|
96
|
+
|
97
|
+
def after_only( *methods, &closure )
|
98
|
+
register_after closure: closure, only: methods
|
99
|
+
end
|
100
|
+
|
101
|
+
def after_except( *methods, &closure )
|
102
|
+
register_after closure: closure, except: methods
|
103
|
+
end
|
104
|
+
|
105
|
+
def runAction( name )
|
106
|
+
self.runFilters name
|
107
|
+
self.send( name ) unless @stopped
|
108
|
+
self.runFilters name, :after
|
109
|
+
end
|
110
|
+
|
111
|
+
def stop
|
112
|
+
@stopped = true
|
80
113
|
end
|
81
114
|
|
115
|
+
protected
|
116
|
+
|
117
|
+
def runFilters( name, type = :before )
|
118
|
+
filters = if type == :before then self.class.befores else self.class.afters end
|
119
|
+
filters.each do |obj|
|
120
|
+
if !@stopped and ( ( obj[ :only ] and obj[ :only ].include?( name ) ) or ( obj[ :except ] and !obj[ :except ].include?( name ) ) )
|
121
|
+
instance_eval( &obj[ :closure ] )
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def register_before( obj )
|
129
|
+
befores.push obj
|
130
|
+
end
|
131
|
+
|
132
|
+
def register_after( obj )
|
133
|
+
afters.push obj
|
134
|
+
end
|
135
|
+
|
136
|
+
def permit_params( filter )
|
137
|
+
params.keys.each { |key| params.delete( key ) unless filter.include?( key ) }
|
138
|
+
params
|
139
|
+
end
|
140
|
+
|
141
|
+
def model_class
|
142
|
+
Object.const_get model_name
|
143
|
+
end
|
144
|
+
|
145
|
+
def model_name
|
146
|
+
self.class.name.gsub( 'sController', '' ).to_sym
|
147
|
+
end
|
148
|
+
|
82
149
|
end
|
83
150
|
|
84
151
|
end
|
data/lib/nali/extensions.rb
CHANGED
@@ -13,7 +13,7 @@ end
|
|
13
13
|
class String
|
14
14
|
|
15
15
|
def underscore!
|
16
|
-
gsub!(/(.)([A-Z])/,'\1_\2')
|
16
|
+
gsub!( /(.)([A-Z])/, '\1_\2' )
|
17
17
|
downcase!
|
18
18
|
end
|
19
19
|
|
@@ -21,8 +21,8 @@ class String
|
|
21
21
|
dup.tap { |s| s.underscore! }
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
24
|
+
def camelize
|
25
|
+
self.split( '_' ).collect( &:capitalize ).join
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
data/lib/nali/generator.rb
CHANGED
@@ -20,7 +20,6 @@ module Nali
|
|
20
20
|
target_path = File.join( Dir.pwd, name )
|
21
21
|
FileUtils.cp_r source_path, target_path
|
22
22
|
dirs = []
|
23
|
-
dirs << File.join( target_path, 'app/controllers' )
|
24
23
|
dirs << File.join( target_path, 'db' )
|
25
24
|
dirs << File.join( target_path, 'db/migrate' )
|
26
25
|
dirs << File.join( target_path, 'lib' )
|
@@ -34,8 +33,11 @@ module Nali
|
|
34
33
|
|
35
34
|
def create_model( name )
|
36
35
|
if Dir.exists?( File.join( Dir.pwd, 'app' ) )
|
37
|
-
|
38
|
-
|
36
|
+
if name.scan( '_' ).size > 0
|
37
|
+
return puts 'Please don\'t use the underscore'
|
38
|
+
end
|
39
|
+
filename = name.downcase
|
40
|
+
classname = name.camelize
|
39
41
|
File.open( File.join( Dir.pwd, "app/assets/javascripts/models/#{ filename }.js.coffee" ), 'w' ) do |f|
|
40
42
|
f.write( "Nali.Model.extend #{ classname }: {}" )
|
41
43
|
end
|
@@ -48,12 +50,16 @@ module Nali
|
|
48
50
|
|
49
51
|
include Nali::Model
|
50
52
|
|
53
|
+
def access_level( client )
|
54
|
+
:unknown
|
55
|
+
end
|
56
|
+
|
51
57
|
end"
|
52
58
|
)
|
53
59
|
end
|
54
60
|
File.open( File.join( Dir.pwd, "app/controllers/#{ filename }s_controller.rb" ), 'w' ) do |f|
|
55
61
|
f.write(
|
56
|
-
"class #{ classname }sController
|
62
|
+
"class #{ classname }sController < ApplicationController
|
57
63
|
|
58
64
|
include Nali::Controller
|
59
65
|
|
@@ -64,9 +70,13 @@ end"
|
|
64
70
|
f.write(
|
65
71
|
"#{ classname }:
|
66
72
|
create:
|
73
|
+
unknown:
|
67
74
|
read:
|
75
|
+
unknown:
|
68
76
|
update:
|
77
|
+
unknown:
|
69
78
|
destroy:
|
79
|
+
unknown:
|
70
80
|
|
71
81
|
|
72
82
|
"
|
@@ -85,23 +95,25 @@ end"
|
|
85
95
|
if Dir.exists?( File.join( Dir.pwd, 'app' ) )
|
86
96
|
dirname, *filename = name.underscore.split( '_' )
|
87
97
|
filename = filename.join( '_' )
|
88
|
-
classname = name.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
98
|
+
classname = name.underscore.camelize
|
99
|
+
if not dirname.empty? and not filename.empty? and not classname.empty?
|
100
|
+
dirs = []
|
101
|
+
dirs << File.join( Dir.pwd, "app/assets/javascripts/views/#{ dirname }" )
|
102
|
+
dirs << File.join( Dir.pwd, "app/assets/stylesheets/#{ dirname }" )
|
103
|
+
dirs << File.join( Dir.pwd, "app/templates/#{ dirname }" )
|
104
|
+
dirs.each { |path| Dir.mkdir( path ) unless Dir.exists?( path ) }
|
105
|
+
File.open( File.join( Dir.pwd, "app/assets/javascripts/views/#{ dirname }/#{ filename }.js.coffee" ), 'w' ) do |f|
|
106
|
+
f.write( "Nali.View.extend #{ classname }: {}" )
|
107
|
+
end
|
108
|
+
File.open( File.join( Dir.pwd, "app/assets/stylesheets/#{ dirname }/#{ filename }.css.sass" ), 'w' ) do |f|
|
109
|
+
f.write( ".#{ classname }" )
|
110
|
+
end
|
111
|
+
File.open( File.join( Dir.pwd, "app/templates/#{ dirname }/#{ filename }.html" ), 'w' ) {}
|
112
|
+
FileUtils.rm_rf( File.join( Dir.pwd, "tmp/cache" ) )
|
113
|
+
puts "Created: app/assets/javascripts/views/#{ dirname }/#{ filename }.js.coffee"
|
114
|
+
puts "Created: app/assets/stylesheets/#{ dirname }/#{ filename }.css.sass"
|
115
|
+
puts "Created: app/templates/#{ dirname }/#{ filename }.html"
|
116
|
+
else puts 'Invalid view name' end
|
105
117
|
else puts 'Please go to the application folder' end
|
106
118
|
end
|
107
119
|
|
data/lib/nali/helpers.rb
CHANGED
@@ -7,8 +7,8 @@ module Sprockets
|
|
7
7
|
arr = path.split( '/' ).reverse
|
8
8
|
id = arr[1] + '_' + arr[0].split( '.' )[0]
|
9
9
|
asset = environment[ path ]
|
10
|
-
template = asset.body.force_encoding 'UTF-8'
|
11
|
-
result += %Q(\n<script type=\"text/template\" id=\"#{ id }\">\n#{ template }\n</script>)
|
10
|
+
template = asset.body.force_encoding( 'UTF-8' ).strip.gsub( "\n", "\n " )
|
11
|
+
result += %Q(\n <script type=\"text/template\" id=\"#{ id }\">\n #{ template }\n </script>)
|
12
12
|
depend_on asset.pathname
|
13
13
|
end
|
14
14
|
result
|
data/lib/nali/model.rb
CHANGED
data/lib/nali/tasks.rb
CHANGED
@@ -36,13 +36,13 @@ module Nali
|
|
36
36
|
task :clean do
|
37
37
|
sprockets_tasks
|
38
38
|
Rake::Task[ 'clean_assets' ].invoke
|
39
|
-
puts 'Old
|
39
|
+
puts 'Old assets removed'
|
40
40
|
end
|
41
41
|
|
42
42
|
desc 'Remove all assets'
|
43
43
|
task :clobber do
|
44
44
|
FileUtils.rm_rf File.join( @settings.root, 'public/assets' )
|
45
|
-
puts '
|
45
|
+
puts 'All assets removed'
|
46
46
|
end
|
47
47
|
|
48
48
|
namespace :cache do
|
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.2.
|
4
|
+
version: 0.2.2
|
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-10-
|
12
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|
@@ -230,6 +230,7 @@ files:
|
|
230
230
|
- lib/generator/app/assets/stylesheets/notices/warning.css.sass
|
231
231
|
- lib/generator/app/assets/stylesheets/application.css.sass
|
232
232
|
- lib/generator/app/models/access.yml
|
233
|
+
- lib/generator/app/controllers/application_controller.rb
|
233
234
|
- lib/generator/app/templates/application.html.erb
|
234
235
|
- lib/generator/app/templates/notice/error.html
|
235
236
|
- lib/generator/app/templates/notice/warning.html
|
@@ -273,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
273
274
|
version: '0'
|
274
275
|
requirements: []
|
275
276
|
rubyforge_project:
|
276
|
-
rubygems_version: 1.8.
|
277
|
+
rubygems_version: 1.8.23
|
277
278
|
signing_key:
|
278
279
|
specification_version: 3
|
279
280
|
summary: Framework for developing async web applications
|