public
Last active

download all the images assets that used in css file

  • Download Gist
fetch_css_images.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
require "fileutils"
require "net/http"
require "uri"
require "cgi"
def fetch(filename)
matched = open(filename) do |f|
content = f.read
content.scan(/url.*images\/(.*?)\'/i).flatten!
end
puts matched.inspect
matched.each do |m|
uri = URI.parse("http://ponjoh.s3.amazonaws.com/HTML%20Templates/Simpla%20Admin/resources/images/#{m}")
puts "fetch #{uri.path} ..."
response = Net::HTTP.get_response(uri)
dirs = m.split("/")
if dirs.size > 1
FileUtils.mkdir_p m.split("/")[0...-1].join("/")
end
File.open(m, "wb") { |f| f.write response.body}
end
puts "done"
end
 
fetch "style.css"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.