zfben_libjs 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  .bundle
3
3
  *.lock
4
+ .sass-cache
4
5
  pkg/*
5
6
  src/*
6
7
  test/javascript/tmp
@@ -1,5 +1,5 @@
1
1
  class Zfben_libjs::Collection
2
- attr_accessor :name, :sources, :options, :css, :js, :images, :css_path, :js_path, :images_path
2
+ attr_accessor :name, :sources, :options, :libs, :css, :js, :images, :css_path, :js_path, :images_path
3
3
 
4
4
  def initialize name, sources, libs, options
5
5
  sources = [sources] unless sources.class.to_s != 'Array'
@@ -9,6 +9,7 @@ class Zfben_libjs::Collection
9
9
 
10
10
  @options = options
11
11
 
12
+ @libs = []
12
13
  @css = []
13
14
  @js = []
14
15
  @images = []
@@ -60,8 +61,12 @@ class Zfben_libjs::Collection
60
61
  else
61
62
  @js_path = nil
62
63
  end
64
+
65
+ if @libs.length > 0
66
+ @libs = @libs.flatten.uniq
67
+ end
63
68
 
64
- return [@css_path, @js_path].compact
69
+ return @libs + [@css_path, @js_path].compact
65
70
  end
66
71
 
67
72
  private
@@ -69,7 +74,7 @@ class Zfben_libjs::Collection
69
74
  def process_sources sources, libs
70
75
  sources.each do |source|
71
76
  if libs.has_key?(source)
72
- process_sources libs[source], libs
77
+ @libs.push(libs[source])
73
78
  elsif source.respond_to?(:to_css)
74
79
  @css.push source
75
80
  @images = @images + source.images if source.respond_to?(:images)
@@ -202,7 +202,7 @@ Location_watch = ->
202
202
  for regexp, lib_name of routes
203
203
  test = location_path.match(path2regexp(regexp))
204
204
  if test isnt null
205
- if typeof libs_name is 'string'
205
+ if typeof lib_name is 'string'
206
206
  libs_name.push lib_name
207
207
  else
208
208
  if typeof lib_name is 'function'
@@ -2,7 +2,7 @@ class Zfben_libjs::Scss < Zfben_libjs::Source
2
2
  def after_initialize
3
3
  @options = @options.merges({ :syntax => :scss, :cache => false }, Compass.sass_engine_options)
4
4
  @options[:load_paths].push File.dirname(@filepath)
5
- @source = "@import compass\n" + @source
5
+ @source = "@import \"compass\";\n" + @source
6
6
  end
7
7
 
8
8
  def to_css
data/lib/zfben_libjs.rb CHANGED
@@ -38,128 +38,128 @@ class Zfben_libjs::Libjs
38
38
  end
39
39
  tip '== [1/2] Starting Progress Source =='
40
40
  length = @libs.length
41
- num = 0
42
- @libs.each do |name, urls|
43
- num = num + 1
44
- tip "[#{num}/#{length}] #{name}"
45
- urls = [urls] unless urls.class == Array
46
- urls = urls.map{ |url|
47
- if url.include?('*')
48
- url = Dir[url]
49
- end
50
- url
51
- }.flatten.uniq.compact
52
- lib = []
53
- urls.each do |url|
54
- if @libs.has_key?(url) && name != url
55
- lib.push(url)
56
- else
57
- source = Zfben_libjs.get_source(url, @opts[:config])
58
- lib.push(source)
59
- end
41
+ num = 0
42
+ @libs.each do |name, urls|
43
+ num = num + 1
44
+ tip "[#{num}/#{length}] #{name}"
45
+ urls = [urls] unless urls.class == Array
46
+ urls = urls.map{ |url|
47
+ if url.include?('*')
48
+ url = Dir[url]
49
+ end
50
+ url
51
+ }.flatten.uniq.compact
52
+ lib = []
53
+ urls.each do |url|
54
+ if @libs.has_key?(url) && name != url
55
+ lib.push(url)
56
+ else
57
+ source = Zfben_libjs.get_source(url, @opts[:config])
58
+ lib.push(source)
60
59
  end
61
- lib = lib.flatten.uniq.compact
62
-
63
- @libs[name] = Zfben_libjs::Collection.new(name, lib, @libs, @opts[:config]).write_files!
64
60
  end
61
+ lib = lib.flatten.uniq.compact
62
+
63
+ @libs[name] = Zfben_libjs::Collection.new(name, lib, @libs, @opts[:config]).write_files!
64
+ end
65
65
 
66
- tip '== [2/2] Generate lib.js =='
66
+ tip '== [2/2] Generate lib.js =='
67
67
 
68
- libjs = File.read(@libs['lazyload'][0]) << ";\n"
68
+ libjs = File.read(@libs['lazyload'][0]) << ";\n"
69
69
 
70
- libjs_core = File.read(File.join(@path_gem, 'lib.coffee'))
70
+ libjs_core = File.read(File.join(@path_gem, 'lib.coffee'))
71
71
 
72
- libjs_core = CoffeeScript.compile(libjs_core)
72
+ libjs_core = CoffeeScript.compile(libjs_core)
73
73
 
74
- libjs << libjs_core << ";\n"
74
+ libjs << libjs_core << ";\n"
75
75
 
76
- @urls = {}
76
+ @urls = {}
77
77
 
78
- @libs.each do |lib, path|
79
- path = [path] unless path.class == Array
80
- path = path.map{ |url|
81
- case File.extname(url)
82
- when '.css'
83
- url = @opts[:config]['url/stylesheets'] + '/' + File.basename(url)
84
- when '.js'
85
- url = @opts[:config]['url/javascripts'] + '/' + File.basename(url)
86
- else
87
- url = nil
88
- end
89
- url
90
- }.compact.uniq
91
- @urls[lib] = path
92
- end
93
-
94
- libjs << "\n/* libs */\nlib.libs(#{@urls.to_json});lib.loaded('add', 'lazyload');\n"
95
- libjs << Time.now.strftime("lib.defaults.version = '?%s';\n")
96
-
97
- if @opts.has_key?(:bundle)
98
- bundle = {}
99
- @opts[:bundle].each do |name, libs|
100
- css = ''
101
- js = ''
102
- files = []
103
- libs.each do |lib|
104
- lib = @libs[lib] if @libs.has_key?(lib)
105
- lib = [lib] unless lib.class == Array
106
- lib.each do |file|
107
- files.push(file)
108
- case File.extname(file)
109
- when '.css'
110
- css << File.read(file)
111
- when '.js'
112
- js << File.read(file) << ";\n"
113
- end
78
+ @libs.each do |lib, path|
79
+ path = [path] unless path.class == Array
80
+ path = path.map{ |url|
81
+ case File.extname(url)
82
+ when '.css'
83
+ url = @opts[:config]['url/stylesheets'] + '/' + File.basename(url)
84
+ when '.js'
85
+ url = @opts[:config]['url/javascripts'] + '/' + File.basename(url)
86
+ else
87
+ url = nil
88
+ end
89
+ url
90
+ }.compact.uniq
91
+ @urls[lib] = path
92
+ end
93
+
94
+ libjs << "\n/* libs */\nlib.libs(#{@urls.to_json});lib.loaded('add', 'lazyload');\n"
95
+ libjs << Time.now.strftime("lib.defaults.version = '?%s';\n")
96
+
97
+ if @opts.has_key?(:bundle)
98
+ bundle = {}
99
+ @opts[:bundle].each do |name, libs|
100
+ css = ''
101
+ js = ''
102
+ files = []
103
+ libs.each do |lib|
104
+ lib = @libs[lib] if @libs.has_key?(lib)
105
+ lib = [lib] unless lib.class == Array
106
+ lib.each do |file|
107
+ files.push(file)
108
+ case File.extname(file)
109
+ when '.css'
110
+ css << File.read(file)
111
+ when '.js'
112
+ js << File.read(file) << ";\n"
114
113
  end
115
114
  end
116
-
117
- path = []
118
-
119
- if css != ''
120
- file = File.join(@opts[:config]['src/stylesheets'], name + '.css')
121
- File.open(file, 'w'){ |f| f.write(css) }
122
- path.push(@opts[:config]['url/stylesheets'] + '/' + File.basename(file))
123
- end
124
-
125
- if js != ''
126
- files_url = files.map{ |f| @opts[:config]['url/javascripts'] + '/' + File.basename(f) }.join("','")
127
- js << "\nif(typeof lib === 'function'){lib.loaded('add', '#{files_url}');}"
128
- file = File.join(@opts[:config]['src/javascripts'], name + '.js')
129
- File.open(file, 'w'){ |f| f.write(js) }
130
- path.push(@opts[:config]['url/javascripts'] + '/' + File.basename(file))
131
- end
132
-
133
- if path.length > 0
134
- path = path[0] if path.length == 0
135
- bundle[name] = path
136
- end
137
115
  end
138
-
139
- libjs << "\n/* bundle */\nlib.libs(#{bundle.to_json});\n"
140
- end
141
-
142
- if @opts.has_key?(:routes)
143
- routes = {}
144
- @opts[:routes].each do |path, lib_name|
145
- lib_name = lib_name.join ' ' if lib_name.class == Array
146
- routes[path] = lib_name
116
+
117
+ path = []
118
+
119
+ if css != ''
120
+ file = File.join(@opts[:config]['src/stylesheets'], name + '.css')
121
+ File.open(file, 'w'){ |f| f.write(css) }
122
+ path.push(@opts[:config]['url/stylesheets'] + '/' + File.basename(file))
123
+ end
124
+
125
+ if js != ''
126
+ files_url = files.map{ |f| @opts[:config]['url/javascripts'] + '/' + File.basename(f) }.join("','")
127
+ js << "\nif(typeof lib === 'function'){lib.loaded('add', '#{files_url}');}"
128
+ file = File.join(@opts[:config]['src/javascripts'], name + '.js')
129
+ File.open(file, 'w'){ |f| f.write(js) }
130
+ path.push(@opts[:config]['url/javascripts'] + '/' + File.basename(file))
131
+ end
132
+
133
+ if path.length > 0
134
+ path = path[0] if path.length == 0
135
+ bundle[name] = path
147
136
  end
148
- libjs << "\n/* routes */\nlib.routes('add', #{routes.to_json});\n"
149
- end
150
-
151
- if @opts.has_key?(:preload)
152
- preload = @opts[:preload].class == Array ? @opts[:preload] : [ @opts[:preload] ]
153
- libjs << "\n/* preload */\nlib('#{preload.join(' ')}');\n"
154
137
  end
155
-
156
- libjs = minify(libjs, :js) if @opts[:config]['minify']
157
- File.open(File.join(@opts[:config]['src/javascripts'], 'lib.js'), 'w'){ |f| f.write(libjs) }
158
-
159
- if @opts[:config].has_key?('after')
160
- load @opts[:config]['after']
138
+
139
+ libjs << "\n/* bundle */\nlib.libs(#{bundle.to_json});\n"
140
+ end
141
+
142
+ if @opts.has_key?(:routes)
143
+ routes = {}
144
+ @opts[:routes].each do |path, lib_name|
145
+ lib_name = lib_name.join ' ' if lib_name.class == Array
146
+ routes[path] = lib_name
161
147
  end
162
-
163
- tip '== End Build =='
148
+ libjs << "\n/* routes */\nlib.routes('add', #{routes.to_json});\n"
149
+ end
150
+
151
+ if @opts.has_key?(:preload)
152
+ preload = @opts[:preload].class == Array ? @opts[:preload] : [ @opts[:preload] ]
153
+ libjs << "\n/* preload */\nlib('#{preload.join(' ')}');\n"
164
154
  end
155
+
156
+ libjs = minify(libjs, :js) if @opts[:config]['minify']
157
+ File.open(File.join(@opts[:config]['src/javascripts'], 'lib.js'), 'w'){ |f| f.write(libjs) }
158
+
159
+ if @opts[:config].has_key?('after')
160
+ load @opts[:config]['after']
161
+ end
162
+
163
+ tip '== End Build =='
164
+ end
165
165
  end
@@ -16,8 +16,8 @@ test('lib.loaded', 3, function(){
16
16
  'http://code.jquery.com/jquery.min.js': true,
17
17
  'http://code.jquery.com/qunit/qunit-git.css': true,
18
18
  'http://code.jquery.com/qunit/qunit-git.js': true,
19
- 'http://localhost:4711/callback.js': true,
20
- 'http://localhost:4711/javascripts/lib.js': true,
19
+ '/callback.js': true,
20
+ '/javascripts/lib.js': true,
21
21
  '/javascripts/lazyload.js': true
22
22
  }, 'lib.loaded files are ok');
23
23
 
@@ -25,8 +25,8 @@ test('lib.loaded', 3, function(){
25
25
  'http://code.jquery.com/jquery.min.js': true,
26
26
  'http://code.jquery.com/qunit/qunit-git.css': true,
27
27
  'http://code.jquery.com/qunit/qunit-git.js': true,
28
- 'http://localhost:4711/callback.js': true,
29
- 'http://localhost:4711/javascripts/lib.js': true,
28
+ '/callback.js': true,
29
+ '/javascripts/lib.js': true,
30
30
  '/javascripts/lazyload.js': true,
31
31
  'test': true
32
32
  }, "lib.loaded('add', 'test') has been added");
@@ -35,8 +35,8 @@ test('lib.loaded', 3, function(){
35
35
  'http://code.jquery.com/jquery.min.js': true,
36
36
  'http://code.jquery.com/qunit/qunit-git.css': true,
37
37
  'http://code.jquery.com/qunit/qunit-git.js': true,
38
- 'http://localhost:4711/callback.js': true,
39
- 'http://localhost:4711/javascripts/lib.js': true,
38
+ '/callback.js': true,
39
+ '/javascripts/lib.js': true,
40
40
  '/javascripts/lazyload.js': true
41
41
  }, "lib.loaded('del', 'test') has been deleted");
42
42
 
@@ -55,7 +55,7 @@ test('lib.libs', 6, function(){
55
55
  route_string: [ '/javascripts/route_string.js' ],
56
56
  route_regexp: [ '/javascripts/route_regexp.js' ],
57
57
  jquery: [ '/javascripts/jquery.js' ],
58
- jqueryui: [ '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
58
+ jqueryui: [ '/javascripts/jquery.js', '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
59
59
  }, 'lib.libs is ok');
60
60
 
61
61
  equal(typeof lib.lazyload, 'function', 'lib.lazyload is a function');
@@ -71,7 +71,7 @@ test('lib.libs', 6, function(){
71
71
  route_string: [ '/javascripts/route_string.js' ],
72
72
  route_regexp: [ '/javascripts/route_regexp.js' ],
73
73
  jquery: [ '/javascripts/jquery.js' ],
74
- jqueryui: [ '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ],
74
+ jqueryui: [ '/javascripts/jquery.js', '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ],
75
75
  test: 'test'
76
76
  }, "lib.libs({test: 'test'}) has been added");
77
77
 
@@ -88,7 +88,7 @@ test('lib.libs', 6, function(){
88
88
  route_string: [ '/javascripts/route_string.js' ],
89
89
  route_regexp: [ '/javascripts/route_regexp.js' ],
90
90
  jquery: [ '/javascripts/jquery.js' ],
91
- jqueryui: [ '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
91
+ jqueryui: [ '/javascripts/jquery.js', '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
92
92
  }, "lib.libs({test: null}) has been deleted");
93
93
 
94
94
  equal(typeof lib.test, 'undefined', 'lib.test is undefined');
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.22'
6
+ s.version = '0.0.23'
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.22
4
+ version: 0.0.23
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-15 00:00:00.000000000Z
12
+ date: 2011-09-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
16
- requirement: &6040240 !ruby/object:Gem::Requirement
16
+ requirement: &10800640 !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: *6040240
24
+ version_requirements: *10800640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &6039100 !ruby/object:Gem::Requirement
27
+ requirement: &10798980 !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: *6039100
35
+ version_requirements: *10798980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: compass
38
- requirement: &5960500 !ruby/object:Gem::Requirement
38
+ requirement: &10796720 !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: *5960500
46
+ version_requirements: *10796720
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: coffee-script
49
- requirement: &5959440 !ruby/object:Gem::Requirement
49
+ requirement: &10794440 !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: *5959440
57
+ version_requirements: *10794440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: uglifier
60
- requirement: &5958880 !ruby/object:Gem::Requirement
60
+ requirement: &10792860 !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: *5958880
68
+ version_requirements: *10792860
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
- requirement: &5958340 !ruby/object:Gem::Requirement
71
+ requirement: &10789880 !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: *5958340
79
+ version_requirements: *10789880
80
80
  description: ''
81
81
  email:
82
82
  - ben@zfben.com