zfben_libjs 0.0.3 → 0.0.4

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.
data/lib/zfben_libjs.rb CHANGED
@@ -19,8 +19,8 @@ end
19
19
 
20
20
  class Libjs
21
21
  def initialize config_file
22
- @config_file = File.exists?(config_file) ? [config_file] : Dir[config_file + '*']
23
- if @config_file.length == 0 || File.directory?(@config_file[0])
22
+ @config_file = File.exists?(config_file) ? [config_file] : Dir[config_file + '*'].select{ |f| !File.directory?(f) }
23
+ if @config_file.length == 0
24
24
  err config_file + ' is not exist!'
25
25
  else
26
26
  @config_file = @config_file[0]
@@ -84,9 +84,15 @@ class Libjs
84
84
  num = num + 1
85
85
  tip "[#{num}/#{length}] #{name}"
86
86
  urls = [urls] unless urls.class == Array
87
+ urls = urls.map{ |url|
88
+ if url.include?('*')
89
+ url = Dir[url]
90
+ end
91
+ url
92
+ }.flatten.uniq.compact
87
93
  lib = []
88
94
  urls.each do |url|
89
- if @libs.has_key?(url)
95
+ if @libs.has_key?(url) && name != url
90
96
  lib.push(url)
91
97
  else
92
98
  path = File.join(@config['src/source'], name, File.basename(url))
@@ -95,15 +101,17 @@ class Libjs
95
101
  download url, path
96
102
  case get_filetype(path)
97
103
  when 'css'
98
- css = css_import(url, dir)
104
+ css = "/* @import #{url} */\n" << css_import(url, dir)
99
105
  File.open(path, 'w'){ |f| f.write(css) }
100
106
  images = download_images(name, url, path)
101
107
  if images.length > 0
102
108
  lib.push images
103
109
  end
110
+ when 'js'
111
+ js = "/* @import #{url} */\n" << File.read(path)
112
+ File.open(path, 'w'){ |f| f.write(js) }
104
113
  when 'rb'
105
114
  script = eval(File.read(path))
106
- rb_path = path
107
115
  css = ''
108
116
  js = ''
109
117
  script.each do | type, content |
@@ -116,26 +124,26 @@ class Libjs
116
124
  end
117
125
  if css != ''
118
126
  path = File.join(dir, File.basename(path, '.rb') << '.css')
119
- File.open(path, 'w'){ |f| f.write("/* @import #{rb_path} */\n" + css) }
127
+ File.open(path, 'w'){ |f| f.write("/* @import #{url} */\n" + css) }
120
128
  elsif js != ''
121
129
  path = File.join(dir, File.basename(path, '.rb') << '.js')
122
- File.open(path, 'w'){ |f| f.write("/* @import #{rb_path} */\n" + js) }
130
+ File.open(path, 'w'){ |f| f.write("/* @import #{url} */\n" + js) }
123
131
  end
124
132
  when 'sass'
125
133
  options = { :syntax => :sass, :cache => false }.merge(Compass.sass_engine_options)
126
134
  options[:load_paths].push File.dirname(path), File.dirname(url)
127
- css = "/* @import #{path} */\n" + Sass::Engine.new(File.read(path), options).render
128
- path = File.join(dir, File.basename(path, '.sass') << '.css')
135
+ css = "/* @import #{url} */\n" + Sass::Engine.new(File.read(path), options).render
136
+ path = File.join(dir, File.basename(path) << '.css')
129
137
  File.open(path, 'w'){ |f| f.write(css) }
130
138
  when 'scss'
131
139
  options = { :syntax => :scss, :cache => false }.merge(Compass.sass_engine_options)
132
140
  options[:load_paths].push File.dirname(path), File.dirname(url)
133
- css = "/* @import #{path} */\n" + Sass::Engine.new(File.read(path), options).render
134
- path = File.join(dir, File.basename(path, '.sass') << '.css')
141
+ css = "/* @import #{url} */\n" + Sass::Engine.new(File.read(path), options).render
142
+ path = File.join(dir, File.basename(path) << '.css')
135
143
  File.open(path, 'w'){ |f| f.write(css) }
136
144
  when 'coffee'
137
- js = "/* @import #{path} */\n" + CoffeeScript.compile(File.read(path))
138
- path = File.join(dir, File.basename(path, '.coffee') << '.js')
145
+ js = "/* @import #{url} */\n" + CoffeeScript.compile(File.read(path))
146
+ path = File.join(dir, File.basename(path) << '.js')
139
147
  File.open(path, 'w'){ |f| f.write(js) }
140
148
  else
141
149
  lib.push url
@@ -185,7 +193,7 @@ class Libjs
185
193
 
186
194
  path = File.join(@config['src/' + type], File.basename(file))
187
195
 
188
- p '=> ' + path
196
+ tip '=> ' + path
189
197
 
190
198
  system('cp ' + file + ' ' + path)
191
199
 
@@ -20,7 +20,9 @@ def download url, path
20
20
  exit!
21
21
  end
22
22
  else
23
- system "cp #{url} #{path}" if File.exists?(url) && url != path
23
+ if File.exists?(url) && url != path
24
+ err 'Copy Error' unless system "cp #{url} #{path}"
25
+ end
24
26
  end
25
27
  end
26
28
 
@@ -1,3 +1,3 @@
1
1
  module ZfbenLibjs
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
4
+ version: 0.0.4
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-08-07 00:00:00.000000000Z
12
+ date: 2011-08-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
16
- requirement: &21645300 !ruby/object:Gem::Requirement
16
+ requirement: &10037280 !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: *21645300
24
+ version_requirements: *10037280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &21644820 !ruby/object:Gem::Requirement
27
+ requirement: &10036800 !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: *21644820
35
+ version_requirements: *10036800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: compass
38
- requirement: &21644300 !ruby/object:Gem::Requirement
38
+ requirement: &10036380 !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: *21644300
46
+ version_requirements: *10036380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: coffee-script
49
- requirement: &21643820 !ruby/object:Gem::Requirement
49
+ requirement: &10035940 !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: *21643820
57
+ version_requirements: *10035940
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: uglifier
60
- requirement: &21643320 !ruby/object:Gem::Requirement
60
+ requirement: &10035500 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *21643320
68
+ version_requirements: *10035500
69
69
  description: ''
70
70
  email:
71
71
  - ben@zfben.com