Skip to content

Instantly share code, notes, and snippets.

@nono
Created January 28, 2010 16:10
Show Gist options
  • Save nono/288872 to your computer and use it in GitHub Desktop.
Save nono/288872 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Author: Bruno Michel <bruno.michel@af83.com>
# Copyright 2010 (c) af83
# Licence: MIT http://www.opensource.org/licenses/mit-license.php
# Add two comments to each of your Rails view with the name of this file,
# one at the beginning and the other at the end.
TMPL_BEGIN = "<!-- Start of %s -->\n"
TMPL_END = "<!-- End of %s -->\n"
Dir['app/views/**/*.erb'].each do |view|
name = view.sub('app/views/', '')
content = File.read(view)
first = TMPL_BEGIN % name
last = TMPL_END % name
if content =~ /\A#{TMPL_BEGIN.gsub('%s', '.*')}/
puts " * #{name} already commented!"
else
puts " * #{name}"
File.open(view, "w+") { |f| f.write(first + content + last) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment