nali 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,9 @@ Nali.extend View:
|
|
21
21
|
@redrawOn source, "update.#{ property }"
|
22
22
|
source[ property ]
|
23
23
|
|
24
|
+
getMy: ( property ) ->
|
25
|
+
@getOf @model, property
|
26
|
+
|
24
27
|
redrawOn: ( source, event ) ->
|
25
28
|
@subscribeTo source, event, @onSourceUpdated
|
26
29
|
|
@@ -39,10 +42,8 @@ Nali.extend View:
|
|
39
42
|
@runModelCallback 'beforeShow'
|
40
43
|
@draw().bindEvents()
|
41
44
|
@runAssistants 'show'
|
42
|
-
@subscribeTo @model, 'update', @onSourceUpdated
|
43
45
|
@subscribeTo @model, 'destroy', @onSourceDestroyed
|
44
46
|
@element.appendTo insertTo
|
45
|
-
@showRelations()
|
46
47
|
setTimeout ( => @onShow() ), 5 if @onShow?
|
47
48
|
@visible = true
|
48
49
|
@runModelCallback 'afterShow'
|
@@ -75,19 +76,6 @@ Nali.extend View:
|
|
75
76
|
@model[ type ]?[ @_shortName ]?.call @model
|
76
77
|
@
|
77
78
|
|
78
|
-
showRelations: ->
|
79
|
-
for { selector, name, view } in @relationsMap
|
80
|
-
if ( relation = @model[ name ] )?
|
81
|
-
insertTo = @element.find selector
|
82
|
-
if relation.childOf 'Collection'
|
83
|
-
relation.show view, insertTo, true
|
84
|
-
relation.subscribeTo @, 'hide', relation.reset
|
85
|
-
else
|
86
|
-
view = relation.show view, insertTo
|
87
|
-
view.subscribeTo @, 'hide', view.hide
|
88
|
-
else console.warn "Relation %s does not exist of model %O", name, @model
|
89
|
-
@
|
90
|
-
|
91
79
|
runLink: ( event ) ->
|
92
80
|
event.preventDefault()
|
93
81
|
@runUrl event.currentTarget.getAttribute 'href'
|
@@ -181,20 +169,11 @@ Nali.extend View:
|
|
181
169
|
.replace( /{\s*yield\s*}/g, '<div class="yield"></div>' )
|
182
170
|
unless RegExp( "^<[^>]+" + @_name ).test @template
|
183
171
|
@template = "<div class=\"#{ @_name }\">#{ @template }</div>"
|
184
|
-
@
|
172
|
+
@parseAssistants()
|
185
173
|
container.parentNode.removeChild container
|
186
174
|
else console.warn 'Template %s not exists', @_name
|
187
175
|
@
|
188
176
|
|
189
|
-
parseRelations: ->
|
190
|
-
@relationsMap = []
|
191
|
-
@template = @template.replace /{\s*(\w+) of @(\w+)\s*}/g, ( match, view, relation ) =>
|
192
|
-
className = relation.capitalize() + view.capitalize() + 'Relation'
|
193
|
-
@relationsMap.push selector: '.' + className, name: relation, view: view
|
194
|
-
"<div class=\"#{ className }\"></div>"
|
195
|
-
@parseAssistants()
|
196
|
-
@
|
197
|
-
|
198
177
|
parseAssistants: ->
|
199
178
|
@assistantsMap = []
|
200
179
|
if /{\s*.+?\s*}|bind=".+?"/.test @template
|
@@ -204,8 +183,11 @@ Nali.extend View:
|
|
204
183
|
@
|
205
184
|
|
206
185
|
scanAssistants: ( node, path = [] ) ->
|
207
|
-
if node.nodeType is 3
|
208
|
-
|
186
|
+
if node.nodeType is 3
|
187
|
+
if /^{\s*\w+ of @\w*\s*}$/.test( node.textContent.trim() ) and node.parentNode.childNodes.length is 1
|
188
|
+
@assistantsMap.push nodepath: path, type: 'Relation'
|
189
|
+
else if /{\s*.+?\s*}/.test node.textContent
|
190
|
+
@assistantsMap.push nodepath: path, type: 'Text'
|
209
191
|
else if node.nodeName is 'ASSIST'
|
210
192
|
@assistantsMap.push nodepath: path, type: 'Html'
|
211
193
|
else
|
@@ -286,6 +268,19 @@ Nali.extend View:
|
|
286
268
|
_node.off 'change'
|
287
269
|
@
|
288
270
|
|
271
|
+
addRelationAssistant: ( node ) ->
|
272
|
+
[ match, name, chain ] = node.textContent.match /{\s*(\w+) of @(\w*)\s*}/
|
273
|
+
( insertTo = node.parentNode ).removeChild node
|
274
|
+
segments = if chain.length then chain.split '.' else []
|
275
|
+
@assistants[ 'show' ].push ->
|
276
|
+
if relation = @getSource segments
|
277
|
+
if relation.childOf 'Collection'
|
278
|
+
relation.show name, insertTo, true
|
279
|
+
relation.subscribeTo @, 'hide', relation.reset
|
280
|
+
else
|
281
|
+
view = relation.show name, insertTo
|
282
|
+
view.subscribeTo @, 'hide', view.hide
|
283
|
+
|
289
284
|
analize: ( value ) ->
|
290
285
|
value.replace /{\s*(.+?)\s*}/g, ( match, sub ) => @analizeMatch sub
|
291
286
|
|
@@ -293,22 +288,25 @@ Nali.extend View:
|
|
293
288
|
if match = sub.match /^@([\w\.]+)(\?)?$/
|
294
289
|
if result = @analizeChain match[1]
|
295
290
|
[ source, property ] = result
|
296
|
-
source.subscribe? @, "update.#{ property }", @onSourceUpdated
|
291
|
+
source.subscribe? @, "update.#{ property }", @onSourceUpdated
|
297
292
|
if match[2] is '?'
|
298
293
|
if source[ property ] then property else ''
|
299
294
|
else if source[ property ]? then source[ property ] else ''
|
300
295
|
else ''
|
301
296
|
else if match = sub.match /^[=|\+](\w+)$/
|
302
297
|
@helpers?[ match[1] ]?.call @
|
303
|
-
else
|
298
|
+
else sub
|
299
|
+
|
300
|
+
getSource: ( segments, source = @model ) ->
|
301
|
+
for segment in segments
|
302
|
+
if segment of source then source = source[ segment ]
|
303
|
+
else
|
304
|
+
console.warn "%s: chain \"%s\" is invalid, segment \"%s\" not exists in %O", @_name, segments.join( '.' ), segment, source
|
305
|
+
return null
|
306
|
+
source
|
304
307
|
|
305
308
|
analizeChain: ( chain, source = @model ) ->
|
306
309
|
segments = chain.split '.'
|
307
310
|
property = segments.pop()
|
308
|
-
|
309
|
-
if segment of source then source = source[ segment ]
|
310
|
-
else break
|
311
|
-
unless property of source
|
312
|
-
console.warn "%s: chain \"%s\" is invalid", @_name, chain
|
313
|
-
return null
|
311
|
+
return null unless source = @getSource segments, source
|
314
312
|
[ source, property ]
|
data/lib/nali/generator.rb
CHANGED
@@ -53,7 +53,7 @@ module Nali
|
|
53
53
|
actions: {}"
|
54
54
|
)
|
55
55
|
end
|
56
|
-
File.open( File.join( Dir.pwd, "app/models/#{ filename }.rb" ), 'w' ) do |f|
|
56
|
+
File.open( File.join( Dir.pwd, "app/server/models/#{ filename }.rb" ), 'w' ) do |f|
|
57
57
|
f.write(
|
58
58
|
"class #{ classname } < ActiveRecord::Base
|
59
59
|
|
@@ -66,7 +66,7 @@ module Nali
|
|
66
66
|
end"
|
67
67
|
)
|
68
68
|
end
|
69
|
-
File.open( File.join( Dir.pwd, "app/controllers/#{ filename }s_controller.rb" ), 'w' ) do |f|
|
69
|
+
File.open( File.join( Dir.pwd, "app/server/controllers/#{ filename }s_controller.rb" ), 'w' ) do |f|
|
70
70
|
f.write(
|
71
71
|
"class #{ classname }sController < ApplicationController
|
72
72
|
|
@@ -75,7 +75,7 @@ end"
|
|
75
75
|
end"
|
76
76
|
)
|
77
77
|
end
|
78
|
-
File.open( File.join( Dir.pwd, "app/models/access.yml" ), 'a' ) do |f|
|
78
|
+
File.open( File.join( Dir.pwd, "app/server/models/access.yml" ), 'a' ) do |f|
|
79
79
|
f.write(
|
80
80
|
"
|
81
81
|
|
@@ -91,9 +91,9 @@ end"
|
|
91
91
|
FileUtils.rm_rf( File.join( Dir.pwd, "tmp/cache" ) )
|
92
92
|
puts "Created: app/client/javascripts/models/#{ filename }.js.coffee"
|
93
93
|
puts "Created: app/client/javascripts/controllers/#{ filename }s.js.coffee"
|
94
|
-
puts "Created: app/models/#{ filename }.rb"
|
95
|
-
puts "Created: app/controllers/#{ filename }s_controller.rb"
|
96
|
-
puts "Updated: app/models/access.yml"
|
94
|
+
puts "Created: app/server/models/#{ filename }.rb"
|
95
|
+
puts "Created: app/server/controllers/#{ filename }s_controller.rb"
|
96
|
+
puts "Updated: app/server/models/access.yml"
|
97
97
|
else puts 'Please go to the application folder' end
|
98
98
|
end
|
99
99
|
|
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.9
|
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-11-
|
12
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|