zfben_libjs 0.0.12 → 0.0.13

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/README.rdoc CHANGED
@@ -77,7 +77,7 @@ support before and after events
77
77
  # => <script src="/javascripts/lib.js?12345678"></script><script>lib('home')</script>
78
78
 
79
79
  <%= lib 'home.css' %>
80
- # => <script src="/javascripts/lib.js?12345678"></script><link rel="stylesheet" href="/stylesheets/home.css?12345678" />
80
+ # => <link rel="stylesheet" href="/stylesheets/home.css?12345678" /><script src="/javascripts/lib.js?12345678"></script>
81
81
 
82
82
  <%= lib 'home.js' %>
83
- # => <script src="/javascripts/lib.js?12345678"></script><script src="/javascripts/home.js?12345678"></script>
83
+ # => <script src="/javascripts/home.js?12345678"></script><script src="/javascripts/lib.js?12345678"></script>
data/lib/zfben_libjs.rb CHANGED
@@ -12,9 +12,12 @@ require 'active_support/core_ext'
12
12
  module Zfben_libjs
13
13
  class Libjs
14
14
  end
15
+
16
+ class Compile
17
+ end
15
18
  end
16
19
 
17
- ['lib.rb', 'initialize.rb', 'railtie.rb'].each { |f| require File.join(File.dirname(__FILE__), 'zfben_libjs', f) }
20
+ ['lib.rb', 'source.rb', 'initialize.rb', 'collection.rb', 'railtie.rb'].each { |f| require File.join(File.dirname(__FILE__), 'zfben_libjs', f) }
18
21
 
19
22
  def err msg
20
23
  STDERR.print "#{msg}\n".color(:red)
@@ -25,19 +28,15 @@ def tip msg
25
28
  STDOUT.print "#{msg}\n".color(:green)
26
29
  end
27
30
 
28
- module Zfben_libjs
29
- class Libjs
30
-
31
- def build!
32
- tip '== Starting Build'
33
-
34
- if @opts[:config].has_key?('before')
35
- load @opts[:config]['before']
36
- end
37
-
38
-
39
- tip '== [1/2] Starting Progress Source =='
40
- length = @libs.length
31
+ class Zfben_libjs::Libjs
32
+ def build!
33
+ tip '== Starting Build'
34
+
35
+ if @opts[:config].has_key?('before')
36
+ load @opts[:config]['before']
37
+ end
38
+ tip '== [1/2] Starting Progress Source =='
39
+ length = @libs.length
41
40
  num = 0
42
41
  @libs.each do |name, urls|
43
42
  num = num + 1
@@ -54,151 +53,18 @@ module Zfben_libjs
54
53
  if @libs.has_key?(url) && name != url
55
54
  lib.push(url)
56
55
  else
57
- p path = File.join(@opts[:config]['src/source'], name, File.basename(url))
58
- dir = File.dirname(path)
59
- system('mkdir ' + dir) unless File.exists?(dir)
60
- download url, path
61
- case get_filetype(path)
62
- when 'css'
63
- css = "/* @import #{url} */\n" << css_import(url, dir)
64
- File.open(path, 'w'){ |f| f.write(css) }
65
- images = download_images(name, url, path)
66
- if images.length > 0
67
- lib.push images
68
- end
69
- when 'js'
70
- js = "/* @import #{url} */\n" << File.read(path)
71
- File.open(path, 'w'){ |f| f.write(js) }
72
- when 'rb'
73
- script = eval(File.read(path))
74
- css = ''
75
- js = ''
76
- script.each do | type, content |
77
- case type
78
- when :css
79
- css << content
80
- when :js
81
- js << content
82
- end
83
- end
84
- if css != ''
85
- path = File.join(dir, File.basename(path, '.rb') << '.css')
86
- File.open(path, 'w'){ |f| f.write("/* @import #{url} */\n" + css) }
87
- elsif js != ''
88
- path = File.join(dir, File.basename(path, '.rb') << '.js')
89
- File.open(path, 'w'){ |f| f.write("/* @import #{url} */\n" + js) }
90
- end
91
- when 'sass'
92
- options = { :syntax => :sass, :cache => false }.merge(Compass.sass_engine_options)
93
- options[:load_paths].push File.dirname(path), File.dirname(url)
94
- css = "/* @import #{url} */\n" + Sass::Engine.new(File.read(path), options).render
95
- path = File.join(dir, File.basename(path) << '.css')
96
- File.open(path, 'w'){ |f| f.write(css) }
97
- when 'scss'
98
- options = { :syntax => :scss, :cache => false }.merge(Compass.sass_engine_options)
99
- options[:load_paths].push File.dirname(path), File.dirname(url)
100
- css = "/* @import #{url} */\n" + Sass::Engine.new(File.read(path), options).render
101
- path = File.join(dir, File.basename(path) << '.css')
102
- File.open(path, 'w'){ |f| f.write(css) }
103
- when 'coffee'
104
- js = "/* @import #{url} */\n" + CoffeeScript.compile(File.read(path))
105
- path = File.join(dir, File.basename(path) << '.js')
106
- File.open(path, 'w'){ |f| f.write(js) }
107
- else
108
- lib.push url
109
- end
110
- lib.push(path)
56
+ source = Zfben_libjs.get_source(url, @opts[:config])
57
+ lib.push(source)
111
58
  end
112
59
  end
113
- lib = lib.flatten.uniq
60
+ lib = lib.flatten.uniq.compact
114
61
 
115
- css = ''
116
- js = ''
117
- lib = lib.map{ |file|
118
- if File.exists?(file)
119
- content = "/* @import #{file} */\n" + File.read(file)
120
- case File.extname(file)
121
- when '.css'
122
- css << content
123
- file = nil
124
- when '.js'
125
- js << content << ';'
126
- file = nil
127
- end
128
- end
129
- file
130
- }.compact
131
- if css != ''
132
- file = File.join(@opts[:config]['src/source'], name + '.css')
133
- File.open(file, 'w'){ |f| f.write(css) }
134
- lib.push(file)
135
- end
136
- if js != ''
137
- file = File.join(@opts[:config]['src/source'], name + '.js')
138
- File.open(file, 'w'){ |f| f.write(js) }
139
- lib.push(file)
140
- end
141
-
142
- @libs[name] = lib.map{ |file|
143
- if File.exists?(file)
144
- case File.extname(file)
145
- when '.js'
146
- type = 'javascripts'
147
- when '.css'
148
- type = 'stylesheets'
149
- else
150
- type = 'images'
151
- end
152
-
153
- path = File.join(@opts[:config]['src/' + type], File.basename(file))
154
-
155
- tip '=> ' + path
156
-
157
- system('cp ' + file + ' ' + path)
158
-
159
- reg = /url\("?'?([^'")]+)'?"?\)/
160
- if type == 'stylesheets' && @opts[:config]['changeImageUrl'] && reg =~ File.read(path)
161
- css = File.read(path).partition_all(reg).map{ |f|
162
- if reg =~ f
163
- filename = File.basename(f.match(reg)[1])
164
- if File.exists?(File.join(@opts[:config]['src/images'], filename))
165
- if @opts[:config]['url'] == ''
166
- url = '../images/' << File.basename(f.match(reg)[1])
167
- else
168
- url = @opts[:config]['url/images'] + File.basename(f.match(reg)[1])
169
- end
170
- f = 'url("' << url << '")'
171
- end
172
- end
173
- f
174
- }.join('')
175
- File.open(path, 'w'){ |f| f.write(css) }
176
- end
177
- if type == 'images'
178
- path = nil
179
- end
180
-
181
- if @opts[:config]['minify']
182
- if type == 'stylesheets'
183
- min = minify(File.read(path), :css)
184
- File.open(path, 'w'){ |f| f.write(min) }
185
- end
186
- if type == 'javascripts'
187
- min = minify(File.read(path), :js)
188
- File.open(path, 'w'){ |f| f.write(min) }
189
- end
190
- end
191
- else
192
- path = @libs[file]
193
- end
194
- path
195
- }.compact.flatten.uniq
196
- @libs[name] = @libs[name][0] if @libs[name].length == 1
62
+ @libs[name] = Zfben_libjs::Collection.new(name, lib, @libs, @opts[:config]).write_files!
197
63
  end
198
-
64
+
199
65
  tip '== [2/2] Generate lib.js =='
200
66
 
201
- libjs = File.read(@libs['lazyload']) << ';'
67
+ libjs = File.read(@libs['lazyload'][0]) << ';'
202
68
 
203
69
  libjs_core = File.read(File.join(@path_gem, 'lib.coffee'))
204
70
 
@@ -207,7 +73,8 @@ module Zfben_libjs
207
73
  libjs << libjs_core << ';'
208
74
 
209
75
  @urls = {}
210
-
76
+
77
+ p @libs
211
78
  @libs.each do |lib, path|
212
79
  path = [path] unless path.class == Array
213
80
  path = path.map{ |url|
@@ -295,5 +162,4 @@ module Zfben_libjs
295
162
 
296
163
  tip '== End Build =='
297
164
  end
298
- end
299
165
  end
@@ -0,0 +1,81 @@
1
+ class Zfben_libjs::Collection
2
+ attr_accessor :name, :sources, :options, :css, :js, :images, :css_path, :js_path, :images_path
3
+
4
+ def initialize name, sources, libs, options
5
+ sources = [sources] unless sources.class.to_s != 'Array'
6
+ @name = name
7
+
8
+ @sources = sources.flatten.uniq.compact
9
+
10
+ @options = options
11
+
12
+ @css = []
13
+ @js = []
14
+ @images = []
15
+
16
+ process_sources @sources, libs
17
+ end
18
+
19
+ def write_files!
20
+ if @images.length > 0
21
+ @images_path = @images.map{ |path|
22
+ new_path = File.join(@options['src/images'], File.basename(path))
23
+ FileUtils.cp path, new_path
24
+ new_path
25
+ }.uniq
26
+ end
27
+
28
+ merge_css = ''
29
+ @css.each do |css|
30
+ merge_css << css.to_css
31
+ end
32
+ if merge_css != ''
33
+ @css_path = File.join(@options['src/stylesheets'], @name + '.css')
34
+ css = Zfben_libjs::Css.new(:source => merge_css, :options => @options)
35
+ if @options['changeImageUrl']
36
+ css.change_images_url!
37
+ end
38
+ if @options['minify']
39
+ #File.open(@css_path + '.debug', 'w'){ |f| f.write(merge_css) }
40
+ file_content = css.minify
41
+ else
42
+ file_content = css.compile
43
+ end
44
+ File.open(@css_path, 'w'){ |f| f.write(file_content) }
45
+ else
46
+ @css_path = nil
47
+ end
48
+
49
+ merge_js = ''
50
+ @js.each do |js|
51
+ merge_js << js.to_js + ';'
52
+ end
53
+ if merge_js != ''
54
+ @js_path = File.join(@options['src/javascripts'], @name + '.js')
55
+ if @options['minify']
56
+ #File.open(@js_path + '.debug', 'w'){ |f| f.write(merge_js) }
57
+ merge_js = Zfben_libjs::Js.new(:source => merge_js).minify
58
+ end
59
+ File.open(@js_path, 'w'){ |f| f.write(merge_js) }
60
+ else
61
+ @js_path = nil
62
+ end
63
+
64
+ return [@css_path, @js_path].compact
65
+ end
66
+
67
+ private
68
+
69
+ def process_sources sources, libs
70
+ sources.each do |source|
71
+ if libs.has_key?(source)
72
+ process_sources libs[source], libs
73
+ elsif source.respond_to?(:to_css)
74
+ @css.push source
75
+ @images = @images + source.images if source.respond_to?(:images)
76
+ elsif source.respond_to?(:to_js)
77
+ @js.push source
78
+ end
79
+ end
80
+ end
81
+ end
@@ -10,15 +10,17 @@ class Zfben_libjs::Libjs
10
10
  'src/stylesheets' => 'src/stylesheets',
11
11
 
12
12
  'url' => '',
13
- 'url/javascripts' => 'url/javascripts',
14
- 'url/images' => 'url/images',
15
- 'url/stylesheets' => 'url/stylesheets',
13
+ 'url/javascripts' => '/javascripts',
14
+ 'url/images' => '/images',
15
+ 'url/stylesheets' => '/stylesheets',
16
16
 
17
17
  'download' => false,
18
18
  'minify' => true,
19
19
  'changeImageUrl' => true
20
-
21
20
  },
21
+
22
+ :support_source => [],
23
+
22
24
  :libs => {
23
25
  'lazyload' => 'https://raw.github.com/rgrove/lazyload/master/lazyload.js'
24
26
  },
@@ -26,6 +28,8 @@ class Zfben_libjs::Libjs
26
28
  :routes => {},
27
29
  :preload => {}
28
30
  }
31
+
32
+ Default_options[:support_source] = Dir[File.join(File.dirname(__FILE__), 'support_source', '*.rb')]
29
33
 
30
34
  def initialize *opts
31
35
 
@@ -39,7 +43,7 @@ class Zfben_libjs::Libjs
39
43
  opts = {}
40
44
  end
41
45
 
42
- @opts = merge_and_convert_options opts
46
+ @opts = merge_and_convert_options(opts)
43
47
 
44
48
  @path_gem = File.realpath(File.dirname(__FILE__))
45
49
 
@@ -83,16 +87,22 @@ class Zfben_libjs::Libjs
83
87
  def merge_and_convert_options opts
84
88
  options = Default_options.clone
85
89
 
86
- [:config, :libs, :bundle, :routes, :preload].each do |name|
90
+ opts = opts.symbolize_keys
91
+
92
+ [:config, :libs, :bundle, :routes, :preload, :support_source].each do |name|
87
93
  if opts.has_key?(name)
88
- options[name] = options[name].merge(opts[name])
89
- else
90
- if opts.has_key?(name.to_s)
91
- options[name] = options[name].merge(opts[name.to_s])
94
+ case opts[name].class.to_s
95
+ when 'Hash'
96
+ opts[name]
97
+ options[name] = options[name].merge(opts[name])
98
+ when 'Array'
99
+ options[name] = (options[name] + opts[name]).uniq
92
100
  end
93
101
  end
94
102
  end
95
103
 
104
+ options[:support_source].each{ |f| require f }
105
+
96
106
  return options
97
107
  end
98
108
  end
@@ -8,6 +8,20 @@ class String
8
8
  end
9
9
  end
10
10
 
11
+ class Hash
12
+ def merges *hashes
13
+ if hashes.length < 1
14
+ self
15
+ else
16
+ merged = self
17
+ hashes.each do |hash|
18
+ merged = merged.merge hash
19
+ end
20
+ merged
21
+ end
22
+ end
23
+ end
24
+
11
25
  def get_filetype path
12
26
  return File.extname(path).delete('.')
13
27
  end
@@ -3,7 +3,7 @@ if defined?(Rails)
3
3
  module Rails
4
4
  module ActionView::Helpers::AssetTagHelper
5
5
  def lib *opts
6
- html = lib_js('lib.js')
6
+ html = ''
7
7
  unless opts.blank?
8
8
  preload = []
9
9
  lib_preload = []
@@ -25,7 +25,7 @@ if defined?(Rails)
25
25
  end
26
26
  end
27
27
  if lib_preload.length > 0
28
- html << "<script>lib('#{lib_preload.join(' ')}')</script>"
28
+ html << lib_js('lib.js') << "<script>lib('#{lib_preload.join(' ')}')</script>"
29
29
  end
30
30
  end
31
31
  return html
@@ -0,0 +1,80 @@
1
+ module Zfben_libjs
2
+
3
+ def self.get_source filepath, *options
4
+ type = File.extname(filepath).delete('.').capitalize
5
+
6
+ if Zfben_libjs.const_defined?(type, false)
7
+ source_class = Zfben_libjs.const_get(type)
8
+ else
9
+ raise Exception.new(type + ' isn\'t exists!')
10
+ end
11
+
12
+ return source_class.new :filepath => filepath, :options => options[0]
13
+ end
14
+
15
+ class Source
16
+ attr_accessor :filepath, :source, :options, :compiled, :minified
17
+
18
+ def initialize *opts
19
+ [:filepath, :source, :options].each do |name|
20
+ self.send(name.to_s + '=', opts[0][name]) if opts[0].has_key?(name)
21
+ end
22
+
23
+ @options = {} if @options.nil?
24
+
25
+ download! if remote?
26
+
27
+ @source = @source || File.read(@filepath)
28
+
29
+ after_initialize if self.respond_to?(:after_initialize)
30
+ end
31
+
32
+ def remote?
33
+ return /^https?:\/\// =~ @filepath
34
+ end
35
+
36
+ def download!
37
+ @remote_path = @filepath
38
+ @filepath = File.join(@options['src/source'], '.download', File.basename(@remote_path))
39
+ download @remote_path, @filepath
40
+ end
41
+
42
+ def name
43
+ unless @filepath.nil?
44
+ File.basename(@filepath, File.extname(@filepath))
45
+ else
46
+ nil
47
+ end
48
+ end
49
+
50
+ def type
51
+ self.class.to_s.gsub(/Zfben_libjs::/, '').downcase
52
+ end
53
+
54
+ def compile
55
+ before_compile if self.respond_to?(:before_compile)
56
+ @compiled = @compiled || @source
57
+ end
58
+
59
+ def minify
60
+ before_minify if self.respond_to?(:before_minify)
61
+ @minified = @minified || @compiled || @source
62
+ @minified = @minified.gsub(/\n/ , '')
63
+ end
64
+
65
+ private
66
+
67
+ def download url, path
68
+ if !File.exists?(path) || @options['download']
69
+ dir = File.dirname(path)
70
+ FileUtils.mkdir(dir) unless File.exists?(dir)
71
+ unless system 'wget ' + url + ' -O ' + path
72
+ FileUtils.rm path
73
+ raise Exception.new(url + ' download failed!')
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,13 @@
1
+ class Zfben_libjs::Coffee < Zfben_libjs::Source
2
+ def to_js
3
+ compile
4
+ end
5
+
6
+ def before_compile
7
+ @compiled = CoffeeScript.compile(@source)
8
+ end
9
+
10
+ def before_minify
11
+ @minified = Zfben_libjs::Js.new(:source => @source, :options => @options).minify
12
+ end
13
+ end
@@ -0,0 +1,90 @@
1
+ class Zfben_libjs::Css < Zfben_libjs::Source
2
+
3
+ REGEXP_REMOTE_CSS = /@import[^"]+"([^"]+)"/
4
+ REGEXP_REMOTE_IMAGE = /url\("?'?([^'")]+)'?"?\)/
5
+
6
+ def after_initialize
7
+ @options = @options.merge({ :syntax => :sass, :style => :compressed, :cache => false })
8
+
9
+ if @remote_path || @filepath
10
+ remote_url = File.dirname(@remote_path || @filepath)
11
+ @source = import_remote_css @source, remote_url
12
+ @images = download_images! remote_url
13
+ end
14
+ end
15
+
16
+ def images
17
+ @images
18
+ end
19
+
20
+ def to_css
21
+ compile
22
+ end
23
+
24
+ def to_sass
25
+ Sass::CSS.new(@source, @options).render(:sass)
26
+ end
27
+
28
+ def to_scss
29
+ Sass::CSS.new(@source, @options).render(:scss)
30
+ end
31
+
32
+ def before_minify
33
+ @minified = Sass::Engine.new(to_sass, @options).render
34
+ end
35
+
36
+ def change_images_url!
37
+ @source = @source.partition_all(REGEXP_REMOTE_IMAGE).map{ |line|
38
+ if REGEXP_REMOTE_IMAGE =~ line
39
+ path = line.match(REGEXP_REMOTE_IMAGE)[1]
40
+ filename = File.basename(path)
41
+ if File.exists?(File.join(@options['src/images'], filename))
42
+ if @options['url'] == ''
43
+ url = '../images/' + filename
44
+ else
45
+ url = @options['url/images'] + '/' + filename
46
+ end
47
+ line = 'url("' << url << '")'
48
+ end
49
+ end
50
+ line
51
+ }.join ''
52
+ end
53
+
54
+ private
55
+
56
+ def import_remote_css source, remote_url
57
+ return source.partition_all(REGEXP_REMOTE_CSS).map{ |f|
58
+ if REGEXP_REMOTE_CSS =~ f
59
+ url = REGEXP_REMOTE_CSS.match(f)[1]
60
+ unless File.exists?(url)
61
+ url = File.join(remote_url, url)
62
+ path = File.join(@options['src/source'], '.download', File.basename(url))
63
+ download(url, path)
64
+ else
65
+ path = url
66
+ end
67
+ f = import_remote_css(File.read(path), File.dirname(url))
68
+ end
69
+ f
70
+ }.join("\n")
71
+ end
72
+
73
+ def download_images! remote_url
74
+ @source.partition_all(REGEXP_REMOTE_IMAGE).map{ |line|
75
+ if REGEXP_REMOTE_IMAGE =~ line
76
+ url = REGEXP_REMOTE_IMAGE.match(line)[1]
77
+ path = File.join(@options['src/source'], '.download', self.name + '_' + File.basename(url))
78
+ unless File.exists?(url) && File.exists?(path)
79
+ url = File.join(remote_url, url)
80
+ download(url, path)
81
+ else
82
+ path = url
83
+ end
84
+ path
85
+ else
86
+ nil
87
+ end
88
+ }.compact.uniq
89
+ end
90
+ end
@@ -0,0 +1,11 @@
1
+ class Zfben_libjs::Js < Zfben_libjs::Source
2
+
3
+ def to_js
4
+ compile
5
+ end
6
+
7
+ def before_minify
8
+ @minified = Uglifier.compile(@source, :copyright => false)
9
+ end
10
+
11
+ end
@@ -0,0 +1,20 @@
1
+ class Zfben_libjs::Rb < Zfben_libjs::Source
2
+ def self.new *options
3
+ filepath = options[0][:filepath]
4
+ if !filepath.nil?
5
+ p filepath
6
+ script = eval(File.read(filepath))
7
+ class_name = script.keys[0].capitalize
8
+ source = script.values[0]
9
+ if Zfben_libjs.const_defined?(class_name, false)
10
+ source_class = Zfben_libjs.const_get(class_name)
11
+ else
12
+ raise Exception.new(class_name + ' isn\'t exists!')
13
+ end
14
+
15
+ return source_class.new :filepath => filepath, :source => source, :options => options[0][:options]
16
+ else
17
+ raise Exception.new('filepath isn\'t exists!')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ class Zfben_libjs::Sass < Zfben_libjs::Source
2
+ def after_initialize
3
+ @options = @options.merges({ :syntax => :sass, :cache => false }, Compass.sass_engine_options)
4
+ @options[:load_paths].push File.dirname(@filepath)
5
+ end
6
+
7
+ def to_css
8
+ compile
9
+ end
10
+
11
+ def before_compile
12
+ @compiled = Sass::Engine.new(@source, @options).render
13
+ end
14
+
15
+ def before_minify
16
+ @minified = Zfben_libjs::Css.new(:source => @compiled, :options => @options).minify
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ class Zfben_libjs::Scss < Zfben_libjs::Source
2
+ def after_initialize
3
+ @options = @options.merges({ :syntax => :scss, :cache => false }, Compass.sass_engine_options)
4
+ @options[:load_paths].push File.dirname(@filepath)
5
+ end
6
+
7
+ def to_css
8
+ compile
9
+ end
10
+
11
+ def before_compile
12
+ @compiled = Sass::Engine.new(@source, @options).render
13
+ end
14
+
15
+ def before_minify
16
+ @minified = Zfben_libjs::Css.new(:source => @compiled, :options => @options).minify
17
+ end
18
+ end
data/test.yml CHANGED
@@ -16,6 +16,13 @@ libs:
16
16
  route_string: test/route_string.js
17
17
 
18
18
  route_regexp: test/route_regexp.js
19
+
20
+ jquery: https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js
21
+
22
+ jqueryui:
23
+ - jquery
24
+ - https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js
25
+ - https://raw.github.com/jquery/jquery-ui/master/themes/base/jquery.ui.all.css
19
26
 
20
27
  routes:
21
28
  "#Test_StringRoute": route_string
@@ -53,7 +53,9 @@ test('lib.libs', 6, function(){
53
53
  unload: [ '/javascripts/unload.js' ],
54
54
  load_times: [ '/javascripts/load_times.js' ],
55
55
  route_string: [ '/javascripts/route_string.js' ],
56
- route_regexp: [ '/javascripts/route_regexp.js' ]
56
+ route_regexp: [ '/javascripts/route_regexp.js' ],
57
+ jquery: [ '/javascripts/jquery.js' ],
58
+ jqueryui: [ '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
57
59
  }, 'lib.libs is ok');
58
60
 
59
61
  equal(typeof lib.lazyload, 'function', 'lib.lazyload is a function');
@@ -68,6 +70,8 @@ test('lib.libs', 6, function(){
68
70
  load_times: [ '/javascripts/load_times.js' ],
69
71
  route_string: [ '/javascripts/route_string.js' ],
70
72
  route_regexp: [ '/javascripts/route_regexp.js' ],
73
+ jquery: [ '/javascripts/jquery.js' ],
74
+ jqueryui: [ '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ],
71
75
  test: 'test'
72
76
  }, "lib.libs({test: 'test'}) has been added");
73
77
 
@@ -82,7 +86,9 @@ test('lib.libs', 6, function(){
82
86
  unload: [ '/javascripts/unload.js' ],
83
87
  load_times: [ '/javascripts/load_times.js' ],
84
88
  route_string: [ '/javascripts/route_string.js' ],
85
- route_regexp: [ '/javascripts/route_regexp.js' ]
89
+ route_regexp: [ '/javascripts/route_regexp.js' ],
90
+ jquery: [ '/javascripts/jquery.js' ],
91
+ jqueryui: [ '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
86
92
  }, "lib.libs({test: null}) has been deleted");
87
93
 
88
94
  equal(typeof lib.test, 'undefined', 'lib.test is undefined');
@@ -115,9 +121,9 @@ module('support_filetype');
115
121
  asyncTest('stylesheet', 4, function() {
116
122
  lib.support_filetype(function(){
117
123
  equal($('.css').css('color'), 'rgb(0, 0, 1)', 'css file loaded');
118
- equal($('.sass').css('color'), 'rgb(0, 0, 2)', 'sass file loaded');
119
- equal($('.scss').css('color'), 'rgb(0, 0, 3)', 'scss file loaded');
120
- equal($('.rb_css').css('color'), 'rgb(0, 0, 4)', 'rb_css file loaded');
124
+ equal($('.sass').css('color'), 'rgb(0, 0, 1)', 'sass file loaded');
125
+ equal($('.scss').css('color'), 'rgb(0, 0, 1)', 'scss file loaded');
126
+ equal($('.rb_css').css('color'), 'rgb(0, 0, 1)', 'rb_css file loaded');
121
127
  start();
122
128
  });
123
129
  });
@@ -0,0 +1,5 @@
1
+ class TestBuild < Test::Unit::TestCase
2
+ def test
3
+ Zfben_libjs::Libjs.new('test').build!
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ class TestSource < Test::Unit::TestCase
2
+ def test
3
+ ['js', 'css', 'sass', 'scss', 'coffee'].each do |type|
4
+ p type
5
+ source = Zfben_libjs.get_source('test/support_filetype/' + type + '.' + type)
6
+ assert_equal source.class.to_s.downcase, 'zfben_libjs::' + type
7
+ source.compile
8
+ source.minify
9
+
10
+ ruby = Zfben_libjs.get_source('test/support_filetype/rb_' + type + '.rb')
11
+ assert_equal ruby.class.to_s.downcase, 'zfben_libjs::' + type
12
+ ruby.compile
13
+ ruby.minify
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ { :coffee => 'this.rb_coffee = true' }
@@ -1 +1 @@
1
- { :css => '.rb_css{ color: rgb(0,0,4) !important }' }
1
+ { :css => '.rb_css{ color: rgb(0,0,1) !important; }' }
@@ -0,0 +1 @@
1
+ { :sass => ".rb_sass\n color: rgb(0,0,1) !important" }
@@ -0,0 +1 @@
1
+ { :scss => '.rb_scss{ color: rgb(0,0,1) !important }' }
@@ -1,2 +1,2 @@
1
1
  .sass
2
- color: rgb(0,0,2) !important
2
+ color: rgb(0,0,1) !important
@@ -1,3 +1,3 @@
1
- .scss{
2
- color: rgb(0,0,3) !important
1
+ .scss {
2
+ color: rgb(0,0,1) !important
3
3
  }
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.12'
6
+ s.version = '0.0.13'
7
7
  s.authors = ["Ben"]
8
8
  s.email = ["ben@zfben.com"]
9
9
  s.homepage = "https://github.com/benz303/zfben_libjs"
@@ -30,6 +30,6 @@ Gem::Specification.new do |s|
30
30
  s.add_dependency 'compass'
31
31
  s.add_dependency 'coffee-script'
32
32
  s.add_dependency 'uglifier'
33
- s.add_dependency 'active_support'
33
+ s.add_dependency 'activesupport'
34
34
 
35
35
  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.12
4
+ version: 0.0.13
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-29 00:00:00.000000000Z
12
+ date: 2011-09-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
16
- requirement: &20317000 !ruby/object:Gem::Requirement
16
+ requirement: &24349840 !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: *20317000
24
+ version_requirements: *24349840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &20316540 !ruby/object:Gem::Requirement
27
+ requirement: &24349380 !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: *20316540
35
+ version_requirements: *24349380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: compass
38
- requirement: &20316120 !ruby/object:Gem::Requirement
38
+ requirement: &24348960 !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: *20316120
46
+ version_requirements: *24348960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: coffee-script
49
- requirement: &20315700 !ruby/object:Gem::Requirement
49
+ requirement: &24348540 !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: *20315700
57
+ version_requirements: *24348540
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: uglifier
60
- requirement: &20315280 !ruby/object:Gem::Requirement
60
+ requirement: &24377940 !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: *20315280
68
+ version_requirements: *24377940
69
69
  - !ruby/object:Gem::Dependency
70
- name: active_support
71
- requirement: &20314860 !ruby/object:Gem::Requirement
70
+ name: activesupport
71
+ requirement: &24377520 !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: *20314860
79
+ version_requirements: *24377520
80
80
  description: ''
81
81
  email:
82
82
  - ben@zfben.com
@@ -90,11 +90,19 @@ files:
90
90
  - Rakefile
91
91
  - bin/libjs
92
92
  - lib/zfben_libjs.rb
93
+ - lib/zfben_libjs/collection.rb
93
94
  - lib/zfben_libjs/initialize.rb
94
95
  - lib/zfben_libjs/lib.coffee
95
96
  - lib/zfben_libjs/lib.rb
96
97
  - lib/zfben_libjs/libjs.yml
97
98
  - lib/zfben_libjs/railtie.rb
99
+ - lib/zfben_libjs/source.rb
100
+ - lib/zfben_libjs/support_source/coffee.rb
101
+ - lib/zfben_libjs/support_source/css.rb
102
+ - lib/zfben_libjs/support_source/js.rb
103
+ - lib/zfben_libjs/support_source/rb.rb
104
+ - lib/zfben_libjs/support_source/sass.rb
105
+ - lib/zfben_libjs/support_source/scss.rb
98
106
  - test.yml
99
107
  - test/javascript/assets/callback.js
100
108
  - test/javascript/fixtures/lib_fixtures.html
@@ -103,12 +111,17 @@ files:
103
111
  - test/load_times.js
104
112
  - test/route_regexp.js
105
113
  - test/route_string.js
114
+ - test/ruby/build_test.rb
106
115
  - test/ruby/initialize_test.rb
116
+ - test/ruby/source_test.rb
107
117
  - test/support_filetype/coffee.coffee
108
118
  - test/support_filetype/css.css
109
119
  - test/support_filetype/js.js
120
+ - test/support_filetype/rb_coffee.rb
110
121
  - test/support_filetype/rb_css.rb
111
122
  - test/support_filetype/rb_js.rb
123
+ - test/support_filetype/rb_sass.rb
124
+ - test/support_filetype/rb_scss.rb
112
125
  - test/support_filetype/sass.sass
113
126
  - test/support_filetype/scss.scss
114
127
  - test/unload.js