Created
May 8, 2012 17:16
-
-
Save AlexanderPavlenko/2637518 to your computer and use it in GitHub Desktop.
wrap erb template into erb template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
filename = ARGV[0] | |
str = File.read filename | |
blocks = str.split('<%').map{|s| s.empty? ? s : s.split('%>') }.flatten | |
inside = false | |
blocks.map do |block| | |
if inside | |
block.gsub! '\\', '\\\\\\\\' | |
block.gsub! '"', '\"' | |
block.gsub! '#{', '#" %><%= "{" + "' | |
end | |
inside = !inside | |
end | |
result = [] | |
blocks.each_slice(2) do |pair| | |
result.push pair.join('<%= "<%') | |
end | |
result = result.join('%" + ">" %>') | |
File.open("/tmp/#{filename.split('/').last}.erb", 'w') do |f| | |
f.write result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment