zfben_libjs 0.0.21 → 0.0.22

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.
@@ -1,7 +1,7 @@
1
1
  module Zfben_libjs::Helpers
2
2
  Lib_version = Time.now.strftime('?%s')
3
3
  def lib *opts
4
- html = lib_js 'lib.js'
4
+ html = ''
5
5
  unless opts.blank?
6
6
  preload = []
7
7
  lib_preload = []
@@ -24,6 +24,8 @@ module Zfben_libjs::Helpers
24
24
  end
25
25
  end
26
26
 
27
+ html << lib_js('lib.js')
28
+
27
29
  if lib_preload.length > 0
28
30
  html << "<script>lib('#{lib_preload.join(' ')}')</script>"
29
31
  end
@@ -177,29 +177,36 @@ lib.defaults = {}
177
177
  routes = {}
178
178
  last_location = ''
179
179
 
180
- path2regex = (path)->
180
+ path2regexp = (path)->
181
+ if typeof path['test'] is 'function'
182
+ return path
181
183
  if path[0] is '/' && path[path.length - 1] is '/'
182
184
  path = path[1..(path.length - 2)]
183
- return path
185
+ return RegExp(path)
184
186
 
185
187
  lib.routes = (method, args)->
186
188
  switch method
187
189
  when 'add'
188
190
  for path, lib_name of args
189
- routes[path2regex(path)] = lib_name
191
+ routes[path2regexp(path).toString()] = lib_name
190
192
  last_location = ''
191
193
  when 'del'
192
194
  for path, lib_name of args
193
- delete(routes[path2regex(path)])
195
+ delete(routes[path2regexp(path).toString()])
194
196
  return routes
195
197
 
196
198
  Location_watch = ->
197
199
  location_path = location.hostname + location.pathname + location.hash
198
200
  if location_path isnt last_location
199
201
  libs_name = []
200
- for path, lib_name of routes
201
- if RegExp(path).test location_path
202
- libs_name.push lib_name
202
+ for regexp, lib_name of routes
203
+ test = location_path.match(path2regexp(regexp))
204
+ if test isnt null
205
+ if typeof libs_name is 'string'
206
+ libs_name.push lib_name
207
+ else
208
+ if typeof lib_name is 'function'
209
+ lib_name test
203
210
  if libs_name.length > 0
204
211
  lib(libs_name.join(' '))
205
212
  last_location = location_path
data/zfben_libjs.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'zfben_libjs'
6
- s.version = '0.0.21'
6
+ s.version = '0.0.22'
7
7
  s.authors = ["Ben"]
8
8
  s.email = ["ben@zfben.com"]
9
9
  s.homepage = "https://github.com/benz303/zfben_libjs"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zfben_libjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-14 00:00:00.000000000Z
12
+ date: 2011-09-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
16
- requirement: &9812340 !ruby/object:Gem::Requirement
16
+ requirement: &6040240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9812340
24
+ version_requirements: *6040240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &9811500 !ruby/object:Gem::Requirement
27
+ requirement: &6039100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9811500
35
+ version_requirements: *6039100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: compass
38
- requirement: &9810300 !ruby/object:Gem::Requirement
38
+ requirement: &5960500 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *9810300
46
+ version_requirements: *5960500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: coffee-script
49
- requirement: &9809840 !ruby/object:Gem::Requirement
49
+ requirement: &5959440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *9809840
57
+ version_requirements: *5959440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: uglifier
60
- requirement: &9809340 !ruby/object:Gem::Requirement
60
+ requirement: &5958880 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *9809340
68
+ version_requirements: *5958880
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
- requirement: &9808180 !ruby/object:Gem::Requirement
71
+ requirement: &5958340 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *9808180
79
+ version_requirements: *5958340
80
80
  description: ''
81
81
  email:
82
82
  - ben@zfben.com