nali 0.2.7 → 0.2.8

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.
@@ -16,3 +16,5 @@ String::camel = ->
16
16
  String::underscore = ->
17
17
  str = @replace /([A-Z])/g, ( match ) -> '_' + match.lower()
18
18
  if str[ 0...1 ] is '_' then str[ 1.. ] else str
19
+
20
+ window.__ = ( args... ) -> console.log args...
@@ -34,7 +34,7 @@ Nali.extend Model:
34
34
  @views[ short = view._shortName ] = view
35
35
  shortCap = short.capitalize()
36
36
  unless @[ viewMethod = 'view' + shortCap ]? then @[ viewMethod ] = -> @view short
37
- unless @[ showMethod = 'show' + shortCap ]? then @[ showMethod ] = -> @show short
37
+ unless @[ showMethod = 'show' + shortCap ]? then @[ showMethod ] = ( insertTo ) -> @show short, insertTo
38
38
  unless @[ hideMethod = 'hide' + shortCap ]? then @[ hideMethod ] = -> @hide short
39
39
  @
40
40
 
@@ -156,6 +156,11 @@ Nali.extend Model:
156
156
  true
157
157
  else false
158
158
 
159
+ upgrade: ( attributes, success, failure ) ->
160
+ # обновляет атрибуты модели и сохраняет её на сервер
161
+ @update( attributes ).save success, failure
162
+ @
163
+
159
164
  destroy: ( success, failure ) ->
160
165
  # отправляет на сервер запрос на удаление модели, вызывает success в случае успеха и failure при неудаче
161
166
  @query @_name.lower() + 's.destroy', @attributes, success, failure
@@ -1,5 +1,3 @@
1
- window.__ = ( args... ) -> console.log args...
2
-
3
1
  window.Nali =
4
2
 
5
3
  _name: 'Nali'
@@ -98,19 +98,29 @@ Nali.extend View:
98
98
  @runUrl event.currentTarget.getAttribute( 'action' ), @formToHash event.currentTarget
99
99
  @
100
100
 
101
- runUrl: ( url, params = {} ) ->
101
+ runUrl: ( url, params ) ->
102
102
  if match = url.match /^(@@?)(.+)/
103
- [ method, data ] = match[2].split '?'
104
- if data
105
- for specification in data.split /&|&/ when specification
106
- [ name, value ] = specification.split '='
107
- params[ name ] = value
108
- obj = if match[1].length is 1 then @ else @model
109
- if obj[ method ]? and typeof obj[ method ] is 'function' then obj[ method ] params
110
- else console.warn "Method %s not exists", method
103
+ [ chain, segments... ] = match[2].split '/'
104
+ if result = @analizeChain chain, ( if match[1].length is 1 then @ else @model )
105
+ [ source, method ] = result
106
+ args = @parseUrlSegments segments
107
+ args.unshift params if params
108
+ source[ method ] args...
109
+ else console.warn "Method %s not exists", chain
111
110
  else @redirect url, params
112
111
  @
113
112
 
113
+ parseUrlSegments: ( segments ) ->
114
+ params = []
115
+ for segment in segments
116
+ [ name, value ] = segment.split ':'
117
+ if value
118
+ last = params[ params.length - 1 ]
119
+ params.push last = {} if typeof last isnt 'object'
120
+ last[ name ] = value
121
+ else params.push name
122
+ params
123
+
114
124
  formToHash: ( form ) ->
115
125
  params = {}
116
126
  for element in form.elements
@@ -286,20 +296,19 @@ Nali.extend View:
286
296
  source.subscribe? @, "update.#{ property }", @onSourceUpdated if source isnt @model
287
297
  if match[2] is '?'
288
298
  if source[ property ] then property else ''
289
- else source[ property ]
299
+ else if source[ property ]? then source[ property ] else ''
290
300
  else ''
291
301
  else if match = sub.match /^[=|\+](\w+)$/
292
302
  @helpers?[ match[1] ]?.call @
293
303
  else undefined
294
304
 
295
- analizeChain: ( chain ) ->
305
+ analizeChain: ( chain, source = @model ) ->
296
306
  segments = chain.split '.'
297
307
  property = segments.pop()
298
- source = @model
299
308
  for segment in segments
300
309
  if segment of source then source = source[ segment ]
301
310
  else break
302
311
  unless property of source
303
- console.warn "%s: chain \"%s\" is invalid, \"%s\" is not Object", @_name, chain, segment
312
+ console.warn "%s: chain \"%s\" is invalid", @_name, chain
304
313
  return null
305
314
  [ source, property ]
@@ -8,9 +8,7 @@ module Nali
8
8
 
9
9
  configure do |config|
10
10
 
11
- # Your configure settings
12
- # config.client.append_path 'public/client/images'
13
- # Add folder to sprockets
11
+ #Your configure settings for all environments
14
12
 
15
13
  end
16
14
 
@@ -1,5 +1,5 @@
1
1
  module Nali
2
2
 
3
- VERSION = '0.2.7'
3
+ VERSION = '0.2.8'
4
4
 
5
5
  end
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.7
4
+ version: 0.2.8
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-14 00:00:00.000000000 Z
12
+ date: 2014-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin