Skip to content

Instantly share code, notes, and snippets.

@ChrisMissal
Last active December 19, 2015 02:09
Show Gist options
  • Select an option

  • Save ChrisMissal/5881424 to your computer and use it in GitHub Desktop.

Select an option

Save ChrisMissal/5881424 to your computer and use it in GitHub Desktop.
Rake task to convert gists from one format to another
desc "Convert old gist tags into new format"
task :convert_gists, :dir do |t, args|
puts ">>> !! Please provide a directory, eg. rake convert_gists[source/_new_posts]" unless args.dir
if args.dir
if args.dir == "/"
dir = ""
else
dir = args.dir.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, '');
end
Dir.open dir do |d|
d.each do |file|
next if file == '.' or file == '..'
file_location = File.join(dir, file)
text = File.read(file_location)
new_text = text.gsub(/\[gist id\=(\"?)(\d*)(\"?)\]/, '{% gist \2 %}') # [gist id=1234567] => {% gist 1234567 %}
File.open(file_location, "w") { |f| f.puts new_text }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment