Module: SourceTools
- Defined in:
- lib/source-tools.rb,
lib/source-tools/version.rb
Constant Summary collapse
- VERSION =
'0.5.0'
Class Method Summary collapse
- .each_source_path ⇒ Object
- .extensions ⇒ Object
- .files ⇒ Object
- .strip(file, spaces = ' ') ⇒ Object
- .strip_utf8_bom(str) ⇒ Object
Class Method Details
.each_source_path ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/source-tools.rb', line 15 def each_source_path require 'pathname' Pathname.getwd.find do |path| # skip unreadable, unwritable, .git and .svn directories skip_dir = path.directory? && (!path.readable? || !path.writable?) Find.prune if skip_dir || %w[.git .svn].include?(path.basename.to_s) # skip non-files, zero-sized files, files not matching specific names, or files without the matching extensions match = files.include?(path.basename.to_s) || extensions.include?(path.extname[1..-1]) next unless path.file? && path.size? && match && path.readable? && path.writable? yield(path) end end |
.extensions ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/source-tools.rb', line 39 def extensions source_codes = %w[ rb rake sake php pl py js sh c cpp cxx h hpp hs ml java cs d y ] templates = %w[ haml builder erb eruby rxml rhtml rjs ratom rcsv ] markup = %w[ css htm html xml rdf yml yaml ] others = %w[ cgi fcgi conf deploy example htc key opts rpdf sql txt vcf log ] (source_codes + templates + markup + others) end |
.files ⇒ Object
32 33 34 35 36 37 |
# File 'lib/source-tools.rb', line 32 def files # files and extensions to process %w[ CHANGELOG HISTORY MIT-LICENSE LICENSE README README_FOR_APP RUNNING_UNIT_TESTS TODO USAGE INSTALL NOTICE .autotest .gitignore Makefile Rakefile capfile ] end |
.strip(file, spaces = ' ') ⇒ Object
5 6 7 8 9 |
# File 'lib/source-tools.rb', line 5 def strip file, spaces = ' ' strip_utf8_bom( file.map{ |line| line.gsub("\t", spaces).rstrip }.join("\n") + "\n" ) end |
.strip_utf8_bom(str) ⇒ Object
11 12 13 |
# File 'lib/source-tools.rb', line 11 def strip_utf8_bom str str[0..2] == "\xEF\xBB\xBF" ? str[3..-1] : str end |