converter: recursive tree fetch

This commit is contained in:
Gleb Mazovetskiy 2015-02-25 01:43:00 +00:00
Родитель 49322ce2a3
Коммит 5d3c30a148
4 изменённых файлов: 13 добавлений и 10 удалений

Просмотреть файл

@ -6,5 +6,5 @@ gemspec
gem 'compass', require: false
group :development do
gem 'byebug', platform: :mri_21, require: false
gem 'byebug', platforms: [:mri_21, :mri_22], require: false
end

Просмотреть файл

@ -29,7 +29,7 @@ class Converter
def bootstrap_js_files
@bootstrap_js_files ||= begin
files = get_paths_by_type 'js', /\.js$/
files = get_paths_by_type('js', /\.js$/).reject { |path| path =~ %r(^tests/) }
files.sort_by { |f|
case f
# tooltip depends on popover and must be loaded earlier

Просмотреть файл

@ -150,9 +150,7 @@ class Converter
end
def bootstrap_less_files
@bootstrap_less_files ||= get_paths_by_type('less', /\.less$/) +
get_paths_by_type('mixins', /\.less$/,
get_tree(get_tree_sha('mixins', get_tree(get_tree_sha('less'))))).map { |p| "mixins/#{p}" }
@bootstrap_less_files ||= get_paths_by_type('less', /\.less$/)
end
# apply general less to scss conversion

Просмотреть файл

@ -3,8 +3,12 @@ class Converter
module Network
protected
def get_paths_by_type(dir, file_re, tree = get_tree(get_tree_sha(dir)))
tree['tree'].select { |f| f['type'] == 'blob' && f['path'] =~ file_re }.map { |f| f['path'] }
def get_paths_by_type(dir, file_re, recursive = true)
get_file_paths(dir, recursive).select { |path| path =~ file_re }
end
def get_file_paths(dir, recursive = true)
get_tree(get_tree_sha(dir), recursive)['tree'].select { |f| f['type'] == 'blob' }.map { |f| f['path'] }
end
def read_files(path, files)
@ -44,7 +48,8 @@ class Converter
def get_file(url)
cache_path = "./#@cache_path#{URI(url).path}"
uri = URI(url)
cache_path = "./#@cache_path#{uri.path}#{uri.query.tr('?&=', '-') if uri.query}"
FileUtils.mkdir_p File.dirname(cache_path)
if File.exists?(cache_path)
log_http_get_file url, true
@ -81,8 +86,8 @@ class Converter
@trees ||= get_tree(@branch_sha)
end
def get_tree(sha)
get_json("https://api.github.com/repos/#@repo/git/trees/#{sha}")
def get_tree(sha, recursive = true)
get_json("https://api.github.com/repos/#@repo/git/trees/#{sha}#{'?recursive=1' if recursive}")
end
def get_json(url)