This is not limited to Rails developers, but I would assume it’s pretty common to have to do this since Rails 3.1.
I’m looking for a script/some method of replacing everything of the form
'../foo/BLAHBLAH'
to <%= asset_path 'BLAHBLAH' %>
where foo is the name of the asset type, so it can be either images or fonts.
Anyone have experience with this?
You can do this with a global search and replace.
In Textmate you can hit
Command-Shift-Fto enter a project wide search. Then search for\.\.\/images\/(.*?)[\)'"]and replace it with<%= asset_path('$1') %>With
findandsedit’s a simple one liner:find PROJECT_DIR -type f -name "*.html" -exec sed -i -e 's/\.\.\/images\/\([^)'\''"]*\)/<%= asset_path("\1")/g' {} \;And in Vim you can do: