【发布时间】:2011-06-15 18:03:57
【问题描述】:
如何使用 nokogiri 将所有 img 标签替换为图像标签?这是为了利用 Rails 自动插入正确的资产服务器的能力?
require 'nokogiri'
class ToImageTag
def self.convert
Dir.glob("app/views/**/*").each do |filename|
doc = Nokogiri::HTML(File.open(filename))
doc.xpath("//img").each |img_tags|
# grab the src and all the attributes and move them to ERB
end
# rewrite the file
end
rescue => err
puts "Exception: #{err}"
end
end
【问题讨论】:
-
也许你可以用一个例子来说明你到底想做什么,为什么?是不是要更改资产服务器,并附加一个缓存清除时间戳?
标签: ruby-on-rails ruby nokogiri erb