33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/theme_bandit/parser/css.rb', line 33
def get_import_urls(file, file_name)
imports = file.scan(RE_IMPORT).map(&:first).select { |import| import[/\.css/] }
imports_arr = []
imports.each do |import|
dot_dots_length = import.split('/').select { |x| x[/\.\./] }.length
if dot_dots_length > 0
file_uri = URI.parse(file_name)
matcher = file_uri.path.split('/').last(dot_dots_length + 1).join('/')
destination = import.split('/').last(2).join('/')
dest_file = file_name.gsub(matcher, destination)
imports_arr << { destination: dest_file, rule: file.match(/\@import.*#{import}(.*\;)?/)[0] }
else
file_uri = URI.parse(file_name)
matcher = file_uri.path.split('/').last
destination = import
dest_file = file_name.gsub(matcher, destination)
imports_arr << { destination: dest_file, rule: file.match(/\@import.*#{import}(.*\;)?/)[0] }
end
end
imports_arr.length > 0 ? imports_arr : nil
end
|