Skip to content

Commit

Permalink
v0.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
zfben committed Sep 1, 2011
1 parent c6d2a0b commit 2e36eed
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
25 changes: 7 additions & 18 deletions lib/zfben_libjs/collection.rb
Expand Up @@ -27,32 +27,21 @@ def write_files!

merge_css = ''
@css.each do |css|
merge_css << css.to_css + ';'
merge_css << css.to_css
end
if merge_css != ''
@css_path = File.join(@options['src/stylesheets'], @name + '.css')
css = Zfben_libjs::Css.new(:source => merge_css, :options => @options)
if @options['changeImageUrl']
merge_css = merge_css.partition_all(REGEXP_REMOTE_IMAGE).map{ |line|
if REGEXP_REMOTE_IMAGE =~ line
path = line.match(REGEXP_REMOTE_IMAGE)[1]
filename = File.basename(path)
if File.exists?(File.join(@options['src/images'], filename))
if @options['url'] == ''
url = '../images/' + filename
else
url = @options['url/images'] + '/' + filename
end
line = 'url("' << url << '")'
end
end
line
}
css.change_images_url!
end
if @options['minify']
#File.open(@css_path + '.debug', 'w'){ |f| f.write(merge_css) }
merge_css = Zfben_libjs::Css.new(:source => merge_css).minify
file_content = css.minify
else
file_content = css.compile
end
File.open(@css_path, 'w'){ |f| f.write(merge_css) }
File.open(@css_path, 'w'){ |f| f.write(file_content) }
else
@css_path = nil
end
Expand Down
18 changes: 18 additions & 0 deletions lib/zfben_libjs/support_source/css.rb
Expand Up @@ -33,6 +33,24 @@ def before_minify
@minified = Sass::Engine.new(to_sass, @options).render
end

def change_images_url!
@source = @source.partition_all(REGEXP_REMOTE_IMAGE).map{ |line|
if REGEXP_REMOTE_IMAGE =~ line
path = line.match(REGEXP_REMOTE_IMAGE)[1]
filename = File.basename(path)
if File.exists?(File.join(@options['src/images'], filename))
if @options['url'] == ''
url = '../images/' + filename
else
url = @options['url/images'] + '/' + filename
end
line = 'url("' << url << '")'
end
end
line
}.join ''
end

private

def import_remote_css source, remote_url
Expand Down
10 changes: 8 additions & 2 deletions test/javascript/lib_test.js
Expand Up @@ -53,7 +53,9 @@ test('lib.libs', 6, function(){
unload: [ '/javascripts/unload.js' ],
load_times: [ '/javascripts/load_times.js' ],
route_string: [ '/javascripts/route_string.js' ],
route_regexp: [ '/javascripts/route_regexp.js' ]
route_regexp: [ '/javascripts/route_regexp.js' ],
jquery: [ '/javascripts/jquery.js' ],
jqueryui: [ '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
}, 'lib.libs is ok');

equal(typeof lib.lazyload, 'function', 'lib.lazyload is a function');
Expand All @@ -68,6 +70,8 @@ test('lib.libs', 6, function(){
load_times: [ '/javascripts/load_times.js' ],
route_string: [ '/javascripts/route_string.js' ],
route_regexp: [ '/javascripts/route_regexp.js' ],
jquery: [ '/javascripts/jquery.js' ],
jqueryui: [ '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ],
test: 'test'
}, "lib.libs({test: 'test'}) has been added");

Expand All @@ -82,7 +86,9 @@ test('lib.libs', 6, function(){
unload: [ '/javascripts/unload.js' ],
load_times: [ '/javascripts/load_times.js' ],
route_string: [ '/javascripts/route_string.js' ],
route_regexp: [ '/javascripts/route_regexp.js' ]
route_regexp: [ '/javascripts/route_regexp.js' ],
jquery: [ '/javascripts/jquery.js' ],
jqueryui: [ '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
}, "lib.libs({test: null}) has been deleted");

equal(typeof lib.test, 'undefined', 'lib.test is undefined');
Expand Down

0 comments on commit 2e36eed

Please sign in to comment.