Created
June 6, 2013 00:59
-
-
Save leepfrog/5718581 to your computer and use it in GitHub Desktop.
1. Slap this code into a file
2. Run this file, pass in a list of .coffee files that you have read/write access to
3. Profit? (all of your single line comments will be converted to block comments)
This file contains hidden or 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 | |
| # Take in a file | |
| # Read each line | |
| # if it contains a single #, then do a regexp replace to make it ### <text> ### | |
| # | |
| # Each file | |
| ARGV.each do |file_name| | |
| # Open the file read only so we can grab it's contents | |
| file = File.open(file_name, 'r') | |
| buffer = [] | |
| # Inside of each file, push each line into a buffer, expand single comments to ### and end each line with ### | |
| file.each do |line| | |
| if line.match(/(.+[^#])#([^#].+)/) then | |
| buffer.push "#{$1}####{$2} ###\n" | |
| else | |
| buffer.push line | |
| end | |
| end | |
| # Reopen the file and write out our buffer | |
| file = File.open(file_name, 'w') | |
| buffer.each do |line| | |
| file.write(line) | |
| end | |
| file.close | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment