nali 0.2.0 → 0.2.1
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/collection.js.coffee +15 -12
- data/lib/assets/javascripts/nali/controller.js.coffee +3 -3
- data/lib/assets/javascripts/nali/model.js.coffee +16 -16
- data/lib/assets/javascripts/nali/nali.js.coffee +18 -16
- data/lib/assets/javascripts/nali/view.js.coffee +51 -48
- data/lib/generator/Gemfile +0 -1
- data/lib/generator/app/assets/javascripts/controllers/homes.js.coffee +1 -1
- data/lib/generator/{app → config}/clients.rb +0 -0
- data/lib/generator/config/environments/development.rb +0 -6
- data/lib/generator/config/environments/production.rb +2 -5
- data/lib/generator/config/environments/test.rb +2 -0
- data/lib/generator/config/routes.rb +7 -0
- data/lib/nali/application.rb +13 -7
- data/lib/nali/generator.rb +8 -7
- data/lib/nali/model.rb +1 -1
- data/lib/nali/tasks.rb +69 -0
- data/lib/nali/version.rb +1 -1
- metadata +5 -3
@@ -5,7 +5,7 @@ Nali.extend Collection:
|
|
5
5
|
length: 0
|
6
6
|
|
7
7
|
cloning: ->
|
8
|
-
@subscribeTo @Model, "create.#{ @model.
|
8
|
+
@subscribeTo @Model, "create.#{ @model._name.lowercase() }", @onModelCreated
|
9
9
|
@adaptations = []
|
10
10
|
@ordering = {}
|
11
11
|
@adaptCollection()
|
@@ -16,7 +16,7 @@ Nali.extend Collection:
|
|
16
16
|
@
|
17
17
|
|
18
18
|
onModelUpdated: ( model ) ->
|
19
|
-
|
19
|
+
if model.isCorrect @filters then @reorder() else @remove model
|
20
20
|
@
|
21
21
|
|
22
22
|
onModelDestroyed: ( model ) ->
|
@@ -78,16 +78,19 @@ Nali.extend Collection:
|
|
78
78
|
if @ordering.by?
|
79
79
|
clearTimeout @ordering.timer if @ordering.timer?
|
80
80
|
@ordering.timer = setTimeout =>
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
one =
|
86
|
-
two =
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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 )
|
91
94
|
@orderViews()
|
92
95
|
delete @ordering.timer
|
93
96
|
, 5
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Nali.extend Controller:
|
2
2
|
|
3
3
|
extension: ->
|
4
|
-
if @
|
4
|
+
if @_name isnt 'Controller'
|
5
5
|
@prepareActions()
|
6
|
-
@modelSysname = @
|
6
|
+
@modelSysname = @_name.replace /s$/, ''
|
7
7
|
@
|
8
8
|
|
9
9
|
actions: {}
|
@@ -70,7 +70,7 @@ Nali.extend Controller:
|
|
70
70
|
|
71
71
|
changeUrl: ( action, filters ) ->
|
72
72
|
params = ( value for own key, value of filters )
|
73
|
-
url = @
|
73
|
+
url = @_name.lowercase().replace /s$/, ''
|
74
74
|
url += if action is @actions.default then '' else '/' + action
|
75
75
|
url += '/' + params.join '/' if params.length
|
76
76
|
@Router.setUrl url
|
@@ -1,8 +1,8 @@
|
|
1
1
|
Nali.extend Model:
|
2
2
|
|
3
3
|
extension: ->
|
4
|
-
if @
|
5
|
-
@table = @tables[ @
|
4
|
+
if @_name isnt 'Model'
|
5
|
+
@table = @tables[ @_name ] ?= []
|
6
6
|
@table.index = {}
|
7
7
|
@adapt()
|
8
8
|
@
|
@@ -53,20 +53,20 @@ Nali.extend Model:
|
|
53
53
|
save: ( success, failure ) ->
|
54
54
|
# отправляет на сервер запрос на сохранение модели, вызывает success в случае успеха и failure при неудаче
|
55
55
|
if @isValid()
|
56
|
-
@query "#{ @
|
56
|
+
@query "#{ @_name.lowercase() }s.save", @attributes,
|
57
57
|
( { attributes, created, updated } ) =>
|
58
58
|
@update( attributes, updated, created ).write()
|
59
59
|
success? @
|
60
60
|
else failure? @
|
61
61
|
@
|
62
62
|
|
63
|
-
sync: ( {
|
63
|
+
sync: ( { _name, attributes, created, updated, destroyed } ) ->
|
64
64
|
# синхронизирует пришедшую с сервера модель с локальной, либо создает новую
|
65
|
-
if model = @extensions[
|
65
|
+
if model = @extensions[ _name ].find attributes.id
|
66
66
|
if destroyed then model.remove()
|
67
67
|
else model.update attributes, updated, created
|
68
68
|
else
|
69
|
-
model = @extensions[
|
69
|
+
model = @extensions[ _name ].build attributes
|
70
70
|
model.updated = updated
|
71
71
|
model.created = created
|
72
72
|
model.write()
|
@@ -74,7 +74,7 @@ Nali.extend Model:
|
|
74
74
|
|
75
75
|
select: ( filters, success, failure ) ->
|
76
76
|
# отправляет на сервер запрос на выборку моделей по фильтру, вызывает success в случае успеха и failure при неудаче
|
77
|
-
@query @
|
77
|
+
@query @_name.lowercase() + 's.select', filters, success, failure if Object.keys( filters ).length
|
78
78
|
|
79
79
|
write: ->
|
80
80
|
# добавляет модель во временную таблицу, генерирует событие create
|
@@ -82,7 +82,7 @@ Nali.extend Model:
|
|
82
82
|
@table.push @
|
83
83
|
@table.index[ @id ] = @
|
84
84
|
@onCreate?()
|
85
|
-
@Model.trigger "create.#{ @
|
85
|
+
@Model.trigger "create.#{ @_name.lowercase() }", @
|
86
86
|
@Model.runNotices()
|
87
87
|
@
|
88
88
|
|
@@ -128,7 +128,7 @@ Nali.extend Model:
|
|
128
128
|
|
129
129
|
destroy: ( success, failure ) ->
|
130
130
|
# отправляет на сервер запрос на удаление модели, вызывает success в случае успеха и failure при неудаче
|
131
|
-
@query @
|
131
|
+
@query @_name.lowercase() + 's.destroy', @attributes, success, failure
|
132
132
|
|
133
133
|
# поиск моделей
|
134
134
|
|
@@ -164,7 +164,7 @@ Nali.extend Model:
|
|
164
164
|
# т.е. строка '123' становится числом 123, '123.5' становится 123.5, а '123abc' остается строкой
|
165
165
|
if typeof value is 'string'
|
166
166
|
value = "#{ value }".trim()
|
167
|
-
if value is ( ( correct =
|
167
|
+
if value is ( ( correct = + value ) + '' ) then correct else value
|
168
168
|
else value
|
169
169
|
|
170
170
|
isCorrect: ( filters = {} ) ->
|
@@ -179,11 +179,11 @@ Nali.extend Model:
|
|
179
179
|
if filter instanceof RegExp
|
180
180
|
filter.test attribute
|
181
181
|
else if typeof filter is 'string'
|
182
|
-
attribute
|
182
|
+
'' + attribute is filter
|
183
183
|
else if typeof filter is 'number'
|
184
|
-
|
184
|
+
+ attribute is filter
|
185
185
|
else if filter instanceof Array
|
186
|
-
attribute
|
186
|
+
'' + attribute in filter or + attribute in filter
|
187
187
|
else false
|
188
188
|
|
189
189
|
# работа со связями
|
@@ -206,7 +206,7 @@ Nali.extend Model:
|
|
206
206
|
# устанавливает геттер типа has_one возвращающий связанную модель
|
207
207
|
@getter name, =>
|
208
208
|
delete @[ name ]
|
209
|
-
( filters = {} )[ "#{ @
|
209
|
+
( filters = {} )[ "#{ @_name.lowercase() }_id" ] = @id
|
210
210
|
relation = @Model.extensions[ name.capitalize() ].where filters
|
211
211
|
@getter name, => relation.first()
|
212
212
|
relation.first()
|
@@ -216,7 +216,7 @@ Nali.extend Model:
|
|
216
216
|
# устанавливает геттер типа has_many возвращающий коллекцию связанных моделей
|
217
217
|
@getter name, =>
|
218
218
|
delete @[ name ]
|
219
|
-
( filters = {} )[ "#{ @
|
219
|
+
( filters = {} )[ "#{ @_name.lowercase() }_id" ] = @id
|
220
220
|
@[ name ] = @Model.extensions[ name[ ...-1 ].capitalize() ].where filters
|
221
221
|
@
|
222
222
|
|
@@ -224,7 +224,7 @@ Nali.extend Model:
|
|
224
224
|
|
225
225
|
view: ( name ) ->
|
226
226
|
# приводит сокращенное имя к полному и возвращает объект вида, либо новый, либо ранее созданный
|
227
|
-
name = @
|
227
|
+
name = @_name + name.camelcase().capitalize() unless @View.extensions[ name ]?
|
228
228
|
unless ( view = ( @views ?= {} )[ name ] )?
|
229
229
|
if ( view = @View.extensions[ name ] )?
|
230
230
|
view = ( ( @views ?= {} )[ name ] = view.clone( model: @ ) )
|
@@ -1,6 +1,6 @@
|
|
1
1
|
window.Nali =
|
2
2
|
|
3
|
-
|
3
|
+
_name: 'Nali'
|
4
4
|
extensions: {}
|
5
5
|
|
6
6
|
starting: ->
|
@@ -10,22 +10,24 @@ window.Nali =
|
|
10
10
|
@starting.call extension
|
11
11
|
@
|
12
12
|
|
13
|
-
extend: (
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@[ sysname ] :: = @
|
20
|
-
@[ sysname ].initObservation()
|
21
|
-
@[ sysname ]
|
13
|
+
extend: ( params ) ->
|
14
|
+
for name, param of params
|
15
|
+
param._name = name
|
16
|
+
@[ name ] = @extensions[ name ] = @child param
|
17
|
+
@[ name ].extensions = {}
|
18
|
+
@[ name ].initObservation()
|
22
19
|
|
23
|
-
clone: (
|
24
|
-
obj
|
25
|
-
obj :: = @
|
26
|
-
obj.initObservation()
|
20
|
+
clone: ( params = {} ) ->
|
21
|
+
obj = @child params
|
27
22
|
obj.cloning?()
|
28
23
|
obj
|
24
|
+
|
25
|
+
child: ( params ) ->
|
26
|
+
obj = Object.create @
|
27
|
+
obj :: = @
|
28
|
+
obj[ name ] = value for name, value of params
|
29
|
+
obj.initObservation()
|
30
|
+
obj
|
29
31
|
|
30
32
|
expand: ( obj ) ->
|
31
33
|
if obj instanceof Object then @[ key ] = value for own key, value of obj
|
@@ -42,8 +44,8 @@ window.Nali =
|
|
42
44
|
return false unless @::?
|
43
45
|
return true if @:: is parent
|
44
46
|
else
|
45
|
-
return false unless @::?.
|
46
|
-
return true if @::
|
47
|
+
return false unless @::?._name?
|
48
|
+
return true if @::_name is parent
|
47
49
|
@::childOf parent
|
48
50
|
|
49
51
|
runExtensions: ( context = @ ) ->
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Nali.extend View:
|
2
2
|
|
3
3
|
extension: ->
|
4
|
-
if @
|
4
|
+
if @_name isnt 'View'
|
5
5
|
@parseTemplate()
|
6
6
|
@parseEvents()
|
7
7
|
@
|
@@ -25,33 +25,35 @@ Nali.extend View:
|
|
25
25
|
else @Application.htmlContainer
|
26
26
|
|
27
27
|
draw: ->
|
28
|
-
|
28
|
+
@runAssistants 'draw'
|
29
29
|
@onDraw?()
|
30
30
|
@
|
31
31
|
|
32
32
|
show: ( insertTo = @insertTo() ) ->
|
33
33
|
@prepareElement().draw().bindEvents()
|
34
34
|
unless @visible
|
35
|
-
@model.beforeShow?[ @
|
35
|
+
@model.beforeShow?[ @_name ]?.call @model
|
36
|
+
@runAssistants 'show'
|
36
37
|
@subscribeTo @model, 'update', @onSourceUpdated
|
37
38
|
@subscribeTo @model, 'destroy', @onSourceDestroyed
|
38
39
|
@element.appendTo insertTo
|
39
40
|
@showRelations()
|
40
41
|
setTimeout ( => @onShow() ), 5 if @onShow?
|
41
42
|
@visible = true
|
42
|
-
@model.afterShow?[ @
|
43
|
+
@model.afterShow?[ @_name ]?.call @model
|
43
44
|
@
|
44
45
|
|
45
46
|
hide: ( delay = 0 ) ->
|
46
47
|
if @visible
|
47
|
-
@model.beforeHide?[ @
|
48
|
+
@model.beforeHide?[ @_name ]?.call @model
|
48
49
|
@hideDelay = delay if typeof( delay ) is 'number' and delay
|
49
50
|
@onHide?()
|
50
51
|
@trigger 'hide'
|
52
|
+
@runAssistants 'hide'
|
51
53
|
@hideElement()
|
52
54
|
@destroyObservation()
|
53
55
|
@visible = false
|
54
|
-
@model.afterHide?[ @
|
56
|
+
@model.afterHide?[ @_name ]?.call @model
|
55
57
|
@
|
56
58
|
|
57
59
|
hideElement: ->
|
@@ -152,15 +154,15 @@ Nali.extend View:
|
|
152
154
|
node
|
153
155
|
|
154
156
|
parseTemplate: ->
|
155
|
-
if container = document.querySelector '#' + @
|
157
|
+
if container = document.querySelector '#' + @_name.underscore()
|
156
158
|
@template = container.innerHTML.trim().replace( /\s+/g, ' ' )
|
157
159
|
.replace( /({\s*\+.+?\s*})/g, ' <assist>$1</assist>' )
|
158
160
|
.replace( /{\s*yield\s*}/g, '<div class="yield"></div>' )
|
159
|
-
unless RegExp( "^<[^>]+" + @
|
160
|
-
@template = "<div class=\"#{ @
|
161
|
+
unless RegExp( "^<[^>]+" + @_name ).test @template
|
162
|
+
@template = "<div class=\"#{ @_name }\">#{ @template }</div>"
|
161
163
|
@parseRelations()
|
162
164
|
container.parentNode.removeChild container
|
163
|
-
else console.warn 'Template %s not exists', @
|
165
|
+
else console.warn 'Template %s not exists', @_name
|
164
166
|
@
|
165
167
|
|
166
168
|
parseRelations: ->
|
@@ -196,18 +198,22 @@ Nali.extend View:
|
|
196
198
|
@
|
197
199
|
|
198
200
|
addAssistants: ->
|
199
|
-
@assistants = []
|
201
|
+
@assistants = show: [], draw: [], hide: []
|
200
202
|
@[ "add#{ type }Assistant" ] @getNode nodepath for { nodepath, type } in @assistantsMap
|
201
203
|
@
|
204
|
+
|
205
|
+
runAssistants: ( type ) ->
|
206
|
+
assistant.call @ for assistant in @assistants[ type ]
|
207
|
+
@
|
202
208
|
|
203
209
|
addTextAssistant: ( node ) ->
|
204
210
|
initialValue = node.textContent
|
205
|
-
@assistants.push -> node.textContent = @analize initialValue
|
211
|
+
@assistants[ 'draw' ].push -> node.textContent = @analize initialValue
|
206
212
|
@
|
207
213
|
|
208
214
|
addAttrAssistant: ( node ) ->
|
209
215
|
initialValue = node.value
|
210
|
-
@assistants.push -> node.value = @analize initialValue
|
216
|
+
@assistants[ 'draw' ].push -> node.value = @analize initialValue
|
211
217
|
@
|
212
218
|
|
213
219
|
addHtmlAssistant: ( node ) ->
|
@@ -216,7 +222,7 @@ Nali.extend View:
|
|
216
222
|
index = Array::indexOf.call parent.childNodes, node
|
217
223
|
after = parent.childNodes[ index - 1 ] or null
|
218
224
|
before = parent.childNodes[ index + 1 ] or null
|
219
|
-
@assistants.push ->
|
225
|
+
@assistants[ 'draw' ].push ->
|
220
226
|
start = if after then Array::indexOf.call( parent.childNodes, after ) + 1 else 0
|
221
227
|
end = if before then Array::indexOf.call parent.childNodes, before else parent.childNodes.length
|
222
228
|
parent.removeChild node for node in Array::slice.call( parent.childNodes, start, end )
|
@@ -226,42 +232,39 @@ Nali.extend View:
|
|
226
232
|
addFormAssistant: ( node ) ->
|
227
233
|
if bind = @analizeChain node.attributes.removeNamedItem( 'bind' ).value
|
228
234
|
[ source, property ] = bind
|
229
|
-
|
230
|
-
node.value = source[ property ]
|
231
|
-
|
232
|
-
@_( node ).on 'change', =>
|
233
|
-
( params = {} )[ property ] = node.value
|
234
|
-
source.update params
|
235
|
-
source.save() unless node.form?
|
236
|
-
|
237
|
-
source.subscribe @, "update.#{ property }", =>
|
238
|
-
node.value = source[ property ] if node.value isnt source[ property ]
|
239
|
-
|
240
|
-
if node.type in [ 'checkbox', 'radio' ]
|
241
|
-
node.checked = source[ property ] + '' is node.value
|
242
|
-
|
243
|
-
@_( node ).on 'change', =>
|
244
|
-
if node.checked is true
|
245
|
-
( params = {} )[ property ] = node.value
|
246
|
-
source.update params
|
247
|
-
source.save() unless node.form?
|
248
|
-
|
249
|
-
source.subscribe @, "update.#{ property }", =>
|
250
|
-
node.checked = source[ property ] + '' is node.value
|
235
|
+
_node = @_ node
|
251
236
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
237
|
+
updateSource = ->
|
238
|
+
( params = {} )[ property ] = node.value
|
239
|
+
source.update params
|
240
|
+
source.save() unless node.form?
|
241
|
+
|
242
|
+
[ setValue, bindChange ] = switch
|
243
|
+
when node.type in [ 'text', 'textarea']
|
244
|
+
[
|
245
|
+
-> node.value = source[ property ]
|
246
|
+
-> _node.on 'change', => updateSource.call @
|
247
|
+
]
|
248
|
+
when node.type in [ 'checkbox', 'radio' ]
|
249
|
+
[
|
250
|
+
-> node.checked = source[ property ] + '' is node.value
|
251
|
+
-> _node.on 'change', => updateSource.call @ if node.checked is true
|
252
|
+
]
|
253
|
+
when node.type is 'select-one'
|
254
|
+
[
|
255
|
+
-> option.selected = true for option in node when source[ property ] + '' is option.value
|
256
|
+
-> _node.on 'change', => updateSource.call @
|
257
|
+
]
|
258
|
+
|
259
|
+
@assistants[ 'show' ].push ->
|
260
|
+
setValue.call @
|
261
|
+
bindChange.call @
|
262
|
+
source.subscribe @, "update.#{ property }", => setValue.call @
|
263
|
+
|
264
|
+
@assistants[ 'hide' ].push ->
|
265
|
+
_node.off 'change'
|
262
266
|
@
|
263
267
|
|
264
|
-
|
265
268
|
analize: ( value ) ->
|
266
269
|
value.replace /{\s*(.+?)\s*}/g, ( match, sub ) => @analizeMatch sub
|
267
270
|
|
@@ -286,6 +289,6 @@ Nali.extend View:
|
|
286
289
|
if segment of source then source = source[ segment ]
|
287
290
|
else break
|
288
291
|
unless property of source
|
289
|
-
console.warn "%s: chain \"%s\" is invalid, \"%s\" is not Object", @
|
292
|
+
console.warn "%s: chain \"%s\" is invalid, \"%s\" is not Object", @_name, chain, segment
|
290
293
|
return null
|
291
294
|
[ source, property ]
|
data/lib/generator/Gemfile
CHANGED
File without changes
|
@@ -1,13 +1,7 @@
|
|
1
1
|
Nali::Application.configure :development do |config|
|
2
2
|
|
3
|
-
# config.assets_digest = true
|
4
|
-
|
5
3
|
config.assets_debug = true
|
6
4
|
|
7
|
-
# config.assets.js_compressor = Uglifier.new( mangle: true )
|
8
|
-
|
9
|
-
# config.assets.css_compressor = YUI::CssCompressor.new
|
10
|
-
|
11
5
|
ActiveRecord::Base.logger = false #Logger.new STDOUT
|
12
6
|
|
13
7
|
end
|
@@ -1,14 +1,11 @@
|
|
1
|
-
require 'uglifier'
|
2
|
-
require 'yui/compressor'
|
3
|
-
|
4
1
|
Nali::Application.configure :production do |config|
|
5
2
|
|
6
3
|
ActiveRecord::Base.logger = false
|
7
4
|
|
8
5
|
config.assets_digest = true
|
9
6
|
|
10
|
-
config.assets.js_compressor =
|
7
|
+
config.assets.js_compressor = :uglify
|
11
8
|
|
12
|
-
config.assets.css_compressor =
|
9
|
+
config.assets.css_compressor = :scss
|
13
10
|
|
14
11
|
end
|
data/lib/nali/application.rb
CHANGED
@@ -41,10 +41,17 @@ module Nali
|
|
41
41
|
content_type asset.content_type
|
42
42
|
params[ :body ] ? asset.body : asset
|
43
43
|
end
|
44
|
+
|
45
|
+
require File.join( root, 'config/routes' )
|
44
46
|
|
45
47
|
get '/*' do
|
46
48
|
if !request.websocket?
|
47
|
-
settings.
|
49
|
+
compiled_path = File.join settings.public_folder, 'assets/application.html'
|
50
|
+
if settings.environment != :development and File.exists?( compiled_path )
|
51
|
+
send_file compiled_path
|
52
|
+
else
|
53
|
+
settings.assets[ 'application.html' ]
|
54
|
+
end
|
48
55
|
else
|
49
56
|
request.websocket do |client|
|
50
57
|
client.onopen { Nali::Clients.on_client_connected client }
|
@@ -66,18 +73,17 @@ module Nali
|
|
66
73
|
Dir[ File.join( root, 'lib/*/**/*.rb' ) ].each { |file| require( file ) }
|
67
74
|
Dir[ File.join( root, 'app/**/*.rb' ) ].each { |file| require( file ) }
|
68
75
|
require File.join( root, 'config/application' )
|
76
|
+
require File.join( root, 'config/clients' )
|
77
|
+
Dir[ File.join( root, 'config/initializers/**/*.rb' ) ].each { |file| require( file ) }
|
69
78
|
self
|
70
79
|
end
|
71
80
|
|
72
81
|
def self.tasks
|
73
82
|
initialize!
|
83
|
+
require 'rake/tasklib'
|
74
84
|
require 'sinatra/activerecord/rake'
|
75
|
-
require '
|
76
|
-
|
77
|
-
task.environment = settings.assets
|
78
|
-
task.output = File.join( public_folder, 'assets' )
|
79
|
-
task.assets = %w( application.html application.js application.css )
|
80
|
-
end
|
85
|
+
require 'nali/tasks'
|
86
|
+
Nali::Tasks.new
|
81
87
|
end
|
82
88
|
|
83
89
|
end
|
data/lib/nali/generator.rb
CHANGED
@@ -20,13 +20,14 @@ 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,
|
24
|
-
dirs << File.join( target_path,
|
25
|
-
dirs << File.join( target_path,
|
26
|
-
dirs << File.join( target_path,
|
27
|
-
dirs << File.join( target_path,
|
28
|
-
dirs << File.join( target_path,
|
29
|
-
dirs << File.join( target_path,
|
23
|
+
dirs << File.join( target_path, 'app/controllers' )
|
24
|
+
dirs << File.join( target_path, 'db' )
|
25
|
+
dirs << File.join( target_path, 'db/migrate' )
|
26
|
+
dirs << File.join( target_path, 'lib' )
|
27
|
+
dirs << File.join( target_path, 'public' )
|
28
|
+
dirs << File.join( target_path, 'tmp' )
|
29
|
+
dirs << File.join( target_path, 'vendor' )
|
30
|
+
dirs << File.join( target_path, 'config/initializers' )
|
30
31
|
dirs.each { |path| Dir.mkdir( path ) unless Dir.exists?( path ) }
|
31
32
|
puts "Application #{ name } created"
|
32
33
|
end
|
data/lib/nali/model.rb
CHANGED
@@ -34,7 +34,7 @@ module Nali
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
params[ :attributes ] = attributes
|
37
|
-
params[ :
|
37
|
+
params[ :_name ] = self.class.name
|
38
38
|
params[ :created ] = self.created_at.to_f
|
39
39
|
params[ :updated ] = self.updated_at.to_f
|
40
40
|
params[ :destroyed ] = self.destroyed?
|
data/lib/nali/tasks.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module Nali
|
2
|
+
|
3
|
+
class Tasks < Rake::TaskLib
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@settings = Nali::Application.settings
|
7
|
+
define
|
8
|
+
end
|
9
|
+
|
10
|
+
def define
|
11
|
+
|
12
|
+
namespace :assets do
|
13
|
+
desc "Compile assets"
|
14
|
+
task :compile do
|
15
|
+
sprockets_tasks
|
16
|
+
|
17
|
+
Rake::Task[ 'assets:clobber' ].invoke
|
18
|
+
Rake::Task[ 'assets:cache:clean' ].invoke
|
19
|
+
Rake::Task[ 'assets' ].invoke
|
20
|
+
|
21
|
+
assets_folder = File.join @settings.public_folder, 'assets/'
|
22
|
+
Dir[ assets_folder + '*' ]
|
23
|
+
.select { |file| file =~ /application.*?\.html/ }
|
24
|
+
.each do |file|
|
25
|
+
filename = File.basename( file ).split '.'
|
26
|
+
filename[0] = 'application'
|
27
|
+
filename = filename.join '.'
|
28
|
+
File.rename file, assets_folder + filename
|
29
|
+
end
|
30
|
+
|
31
|
+
puts 'Assets compiled'
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Remove old assets'
|
36
|
+
task :clean do
|
37
|
+
sprockets_tasks
|
38
|
+
Rake::Task[ 'clean_assets' ].invoke
|
39
|
+
puts 'Old compiled assets removed'
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Remove all assets'
|
43
|
+
task :clobber do
|
44
|
+
FileUtils.rm_rf File.join( @settings.root, 'public/assets' )
|
45
|
+
puts 'Compiled assets removed'
|
46
|
+
end
|
47
|
+
|
48
|
+
namespace :cache do
|
49
|
+
desc 'Remove cached files'
|
50
|
+
task :clean do
|
51
|
+
FileUtils.rm_rf File.join( @settings.root, 'tmp/cache' )
|
52
|
+
puts 'Cached files removed'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def sprockets_tasks
|
60
|
+
require 'rake/sprocketstask'
|
61
|
+
Rake::SprocketsTask.new do |task|
|
62
|
+
task.environment = @settings.assets
|
63
|
+
task.output = File.join( @settings.public_folder, 'assets' )
|
64
|
+
task.assets = %w( application.html application.js application.css )
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
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.2.
|
4
|
+
version: 0.2.1
|
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-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- lib/nali/extensions.rb
|
213
213
|
- lib/nali/model.rb
|
214
214
|
- lib/nali/clients.rb
|
215
|
+
- lib/nali/tasks.rb
|
215
216
|
- lib/nali/controller.rb
|
216
217
|
- lib/nali/generator.rb
|
217
218
|
- lib/nali/connection.rb
|
@@ -229,7 +230,6 @@ files:
|
|
229
230
|
- lib/generator/app/assets/stylesheets/notices/warning.css.sass
|
230
231
|
- lib/generator/app/assets/stylesheets/application.css.sass
|
231
232
|
- lib/generator/app/models/access.yml
|
232
|
-
- lib/generator/app/clients.rb
|
233
233
|
- lib/generator/app/templates/application.html.erb
|
234
234
|
- lib/generator/app/templates/notice/error.html
|
235
235
|
- lib/generator/app/templates/notice/warning.html
|
@@ -242,6 +242,8 @@ files:
|
|
242
242
|
- lib/generator/config/environments/test.rb
|
243
243
|
- lib/generator/config/environments/development.rb~
|
244
244
|
- lib/generator/config/environments/production.rb
|
245
|
+
- lib/generator/config/routes.rb
|
246
|
+
- lib/generator/config/clients.rb
|
245
247
|
- lib/generator/config/database.yml
|
246
248
|
- lib/generator/config/application.rb
|
247
249
|
- lib/generator/Gemfile
|