1
0
Fork 0
mirror of https://github.com/twbs/bootstrap-sass.git synced 2022-11-09 12:27:02 -05:00

converter: parallelize download during conversion

This commit is contained in:
Gleb Mazovetskiy 2013-07-30 22:08:49 +02:00
parent e9006aa7a7
commit e312899109

View file

@ -1,3 +1,4 @@
# coding: utf-8
# Based on convert script from vwall/compass-twitter-bootstrap gem. # Based on convert script from vwall/compass-twitter-bootstrap gem.
# https://github.com/vwall/compass-twitter-bootstrap/blob/master/build/convert.rb # https://github.com/vwall/compass-twitter-bootstrap/blob/master/build/convert.rb
# #
@ -29,9 +30,7 @@ class Converter
def process_stylesheet_assets def process_stylesheet_assets
puts "\nProcessing stylesheets..." puts "\nProcessing stylesheets..."
bootstrap_less_files.each do |name| read_files('less', bootstrap_less_files).each do |name, file|
file = open("https://raw.github.com/#@repo/#@branch/less/#{name}").read
case name case name
when 'bootstrap.less' when 'bootstrap.less'
file = replace_file_imports(file) file = replace_file_imports(file)
@ -62,10 +61,8 @@ class Converter
def process_javascript_assets def process_javascript_assets
puts "\nProcessing javascripts..." puts "\nProcessing javascripts..."
bootstrap_js_files.each do |name| read_files('js', bootstrap_js_files).each do |name, file|
file = open("https://raw.github.com/#@repo/#@branch/js/#{name}").read save_file("vendor/assets/javascripts/bootstrap/#{name}", file)
path = "vendor/assets/javascripts/bootstrap/#{name}"
save_file(path, file)
end end
# Update javascript manifest # Update javascript manifest
@ -80,6 +77,21 @@ class Converter
private private
def read_files(path, files)
contents = {}
files.map do |name|
url = "https://raw.github.com/#@repo/#@branch/#{path}/#{name}"
Thread.start {
content = open(url).read
Thread.exclusive {
puts "GET #{url}"
contents[name] = content
}
}
end.each(&:join)
contents
end
# Get the sha of a dir # Get the sha of a dir
def get_tree_sha(dir) def get_tree_sha(dir)
trees = open("https://api.github.com/repos/#@repo/git/trees/#@branch").read trees = open("https://api.github.com/repos/#@repo/git/trees/#@branch").read
@ -88,24 +100,30 @@ private
end end
def bootstrap_less_files def bootstrap_less_files
files = open("https://api.github.com/repos/#@repo/git/trees/#{get_tree_sha('less')}").read @bootstrap_less_files ||= begin
files = JSON.parse files files = open("https://api.github.com/repos/#@repo/git/trees/#{get_tree_sha('less')}").read
files['tree'].select{|f| f['type'] == 'blob' && f['path'] =~ /.less$/ }.map{|f| f['path'] } files = JSON.parse files
files['tree'].select{|f| f['type'] == 'blob' && f['path'] =~ /.less$/ }.map{|f| f['path'] }
end
end end
def bootstrap_js_files def bootstrap_js_files
files = open("https://api.github.com/repos/#@repo/git/trees/#{get_tree_sha('js')}").read @bootstrap_js_files ||= begin
files = JSON.parse files files = open("https://api.github.com/repos/#@repo/git/trees/#{get_tree_sha('js')}").read
files = files['tree'].select{|f| f['type'] == 'blob' && f['path'] =~ /.js$/ }.map{|f| f['path'] } files = JSON.parse files
files.sort_by { |f| files = files['tree'].select { |f| f['type'] == 'blob' && f['path'] =~ /.js$/ }.map { |f| f['path'] }
case f files.sort_by { |f|
# tooltip depends on popover and must be loaded earlier case f
when /tooltip/ then 1 # tooltip depends on popover and must be loaded earlier
when /popover/ then 2 when /tooltip/ then
else 1
0 when /popover/ then
end 2
} else
0
end
}
end
end end
def get_mixins_name def get_mixins_name