Created
July 10, 2009 08:08
-
-
Save ikasamt/144317 to your computer and use it in GitHub Desktop.
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
# | |
# ソースコードリーティング支援スクリプト | |
# -------------------------------------- | |
# 特定のディレクトリ下のファイルを再帰的に読み込み、大きなテキストファイルにする | |
# プリントアウトして読むためのソースを作ることを目的としている | |
# | |
$KCODE = 'u' | |
require 'jcode' | |
require 'kconv' | |
exclude_extnames = %w[.js .gif .jpg .png .swf .tpl .ini .svg .ai .jpeg .ico .pdf .mmap .html .css] | |
exclude_regex = /\.git|\.svn|test|.*spec/ # testを除いている | |
dir_name = ARGV[0] || '.' | |
all_files = `find #{dir_name} -name '*.*' `.split("\n") | |
all_files.delete_if{|f| File.directory?(f) or exclude_extnames.include?(File.extname(f)) or f =~ exclude_regex } | |
str = [] | |
files = [] | |
files << "##{'-'*100}" | |
all_files.sort.each_with_index do |filename,file_number| | |
extname = File.extname(filename) | |
filename.chomp! | |
next if filename.nil? #or extname != '.rb' | |
files << "# (#{(file_number+1).to_s.rjust(3,' ')}) #{filename.gsub(dir_name, '')}" | |
comment_str = '='* 100 | |
str << "##{comment_str}\n" | |
str << "# (#{file_number+1}) #{filename.gsub(dir_name, '')}" | |
str << "\n##{comment_str}\n\n" | |
lines = File.read(filename).toutf8 | |
lines.each_with_index do |line,idx| | |
str << "#{(idx+1).to_s.rjust(3,' ')}| #{line}" | |
end | |
str << "\n\n" | |
end | |
files << "##{'-'*100}\n\n\n\n" | |
File.open("#{File.basename(dir_name)}.out.txt", 'w') do |f| | |
f.write files.join("\n") | |
f.write str.join('') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment