nali 0.1.7 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/nali CHANGED
File without changes
@@ -2,8 +2,8 @@ Nali.extend Application:
2
2
 
3
3
  domEngine: jBone.noConflict()
4
4
  wsServer: 'ws://' + window.location.host
5
- defaultUrl: ''
6
- notFoundUrl: ''
5
+ defaultUrl: 'home'
6
+ notFoundUrl: 'home'
7
7
  htmlContainer: 'body'
8
8
  title: 'Application'
9
9
  keepAliveDelay: 20
@@ -5,36 +5,68 @@ Nali.extend Controller:
5
5
  @prepareActions()
6
6
  @modelSysname = @sysname.replace /s$/, ''
7
7
  @
8
-
8
+
9
+ actions: {}
10
+
9
11
  prepareActions: ->
10
- @routedActions = {}
11
- if @actions?
12
- for action of @actions when action isnt 'default'
13
- [ name, filters... ] = action.split '/'
14
- params = []
15
- for filter in filters[ 0.. ] when /^:/.test filter
16
- filters.splice filters.indexOf( filter ), 1
17
- params.push filter[ 1.. ]
18
- @routedActions[ name ] = name: action, filters: filters, params: params
12
+ @routedActions = {}
13
+ @preparedActions = {}
14
+ for name, action of @actions when not ( name in [ 'default', 'before', 'after' ] )
15
+ [ name, filters... ] = name.split '/'
16
+ params = []
17
+ for filter in filters[ 0.. ] when /^:/.test filter
18
+ filters.splice filters.indexOf( filter ), 1
19
+ params.push filter[ 1.. ]
20
+ @routedActions[ name ] = filters: filters, params: params
21
+ @preparedActions[ name ] = [ action ]
22
+ @prepareBefores()
23
+ @prepareAfters()
24
+ @
25
+
26
+ prepareBefores: ->
27
+ if @actions.before?
28
+ beforeActions = {}
29
+ for names, action of @actions.before
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 ]
19
34
  @
20
-
21
- runAction: ( name, filters, params ) ->
22
- collection = @Model.extensions[ @modelSysname ].where filters
23
- result = @actions[ @routedActions[ name ].name ].call @, collection, params
24
- if result instanceof Object and result.render is false
25
- collection.destroy()
35
+
36
+ prepareAfters: ->
37
+ if @actions.after?
38
+ afterActions = {}
39
+ for names, action of @actions.after
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
44
+ @
45
+
46
+ run: ( action, filters, params ) ->
47
+ controller = @clone
48
+ collection: @Model.extensions[ @modelSysname ].where filters
49
+ params: params
50
+ controller.runAction action
51
+ if controller.defaultPrevented
52
+ controller.collection.destroy()
26
53
  else
27
- collection.show name
28
- @changeUrl name, filters
54
+ controller.collection.show action
55
+ @changeUrl action, filters
56
+ @
57
+
58
+ runAction: ( name ) ->
59
+ action.call @ for action in @preparedActions[ name ] when not @defaultPrevented
29
60
  @
61
+
62
+ preventDefault: ->
63
+ @defaultPrevented = true
64
+ @
30
65
 
31
66
  redirect: ( args... ) ->
32
- @::redirect args...
33
- render: false
34
-
35
- query: ( args... ) ->
36
- @::query args...
37
- render: false
67
+ @Router.go args...
68
+ @preventDefault()
69
+ @
38
70
 
39
71
  changeUrl: ( action, filters ) ->
40
72
  params = ( value for own key, value of filters )
@@ -81,7 +81,7 @@ window.Nali =
81
81
  @
82
82
 
83
83
  removeObservationItem: ( from, obj, event ) ->
84
- for item in @[ from ][ 0.. ] when item[0] is obj and ( item[1] is event or not event )
84
+ for item in @[ from ][..] when item[0] is obj and ( item[1] is event or not event )
85
85
  @[ from ].splice @[ from ].indexOf( item ), 1
86
86
  @
87
87
 
@@ -115,13 +115,13 @@ window.Nali =
115
115
  @
116
116
 
117
117
  unsubscribeAll: ( event ) ->
118
- @unsubscribe item[0], event for item in @observers[ 0.. ]
118
+ @unsubscribe item[0], event for item in @observers[..]
119
119
  @
120
120
 
121
121
  unsubscribeFromAll: ( event ) ->
122
- @unsubscribeTo item[0], event for item in @observables[ 0.. ]
122
+ @unsubscribeTo item[0], event for item in @observables[..]
123
123
  @
124
124
 
125
125
  trigger: ( event, args... ) ->
126
- item[2].call item[0], args... for item in @observers[ 0.. ] when item[1] is event
126
+ item[2].call item[0], args... for item in @observers[..] when item[1] is event
127
127
  @
@@ -32,7 +32,7 @@ Nali.extend Router:
32
32
  if found = @findRoute url
33
33
  { controller, action, filters, params } = found
34
34
  params[ name ] = value for name, value in options
35
- controller.runAction action, filters, params
35
+ controller.run action, filters, params
36
36
  else if @Application.notFoundUrl
37
37
  @go @Application.notFoundUrl
38
38
  else console.warn "Not exists route to the address %s", url
@@ -190,8 +190,8 @@ Nali.extend View:
190
190
  for attribute, index in node.attributes
191
191
  if attribute.name is 'bind'
192
192
  @assistantsMap.push nodepath: path, type: 'Form'
193
- else if /{\s*.+?\s*}/.test attribute.textContent
194
- @assistantsMap.push nodepath: path.concat( 'attributes', index ), type: 'Text'
193
+ else if /{\s*.+?\s*}/.test attribute.value
194
+ @assistantsMap.push nodepath: path.concat( 'attributes', index ), type: 'Attr'
195
195
  @scanAssistants child, path.concat 'childNodes', index for child, index in node.childNodes
196
196
  @
197
197
 
@@ -205,6 +205,11 @@ Nali.extend View:
205
205
  @assistants.push -> node.textContent = @analize initialValue
206
206
  @
207
207
 
208
+ addAttrAssistant: ( node ) ->
209
+ initialValue = node.value
210
+ @assistants.push -> node.value = @analize initialValue
211
+ @
212
+
208
213
  addHtmlAssistant: ( node ) ->
209
214
  parent = node.parentNode
210
215
  initialValue = node.innerHTML
@@ -254,7 +259,7 @@ Nali.extend View:
254
259
 
255
260
  source.subscribe @, "update.#{ property }", =>
256
261
  option.selected = true for option in node when source[ property ] + '' is option.value
257
-
262
+ @
258
263
 
259
264
 
260
265
  analize: ( value ) ->
@@ -2,10 +2,12 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'nali'
4
4
 
5
- gem 'sqlite3'
6
-
7
- gem 'yui-compressor'
8
-
9
- gem 'uglifier'
10
-
11
- gem 'debugger'
5
+ group :development, :test do
6
+ gem 'debugger'
7
+ gem 'sqlite3'
8
+ end
9
+
10
+ group :production do
11
+ gem 'yui-compressor'
12
+ gem 'uglifier'
13
+ end
@@ -1,6 +1,4 @@
1
1
  #= require nali
2
2
  #= require_tree .
3
3
 
4
- Nali.Application.run
5
- defaultUrl: 'home'
6
- notFoundUrl: 'home'
4
+ Nali.Application.run()
@@ -1,11 +1,14 @@
1
+ require 'uglifier'
2
+ require 'yui/compressor'
3
+
1
4
  Nali::Application.configure :production do |config|
2
5
 
3
- config.assets_digest = true
6
+ ActiveRecord::Base.logger = false
4
7
 
5
- # config.assets_debug = true
8
+ config.assets_digest = true
6
9
 
7
10
  config.assets.js_compressor = Uglifier.new( mangle: true )
8
-
11
+
9
12
  config.assets.css_compressor = YUI::CssCompressor.new
10
13
 
11
14
  end
@@ -63,9 +63,8 @@ module Nali
63
63
  end
64
64
 
65
65
  def self.initialize!
66
- Dir[ File.join( root, 'lib/*/**/*.rb' ) ].each { |file| require( file ) }
67
- Dir[ File.join( root, 'app/**/*.rb' ) ].each { |file| require( file ) }
68
- #Dir[ File.join( root, 'vendor/*/**/*.rb' ) ].each { |file| require( file ) }
66
+ Dir[ File.join( root, 'lib/*/**/*.rb' ) ].each { |file| require( file ) }
67
+ Dir[ File.join( root, 'app/**/*.rb' ) ].each { |file| require( file ) }
69
68
  require File.join( root, 'config/application' )
70
69
  self
71
70
  end
data/lib/nali/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Nali
2
2
 
3
- VERSION = '0.1.7'
3
+ VERSION = '0.1.9'
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.1.7
4
+ version: 0.1.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-10-10 00:00:00.000000000 Z
12
+ date: 2014-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin