Class: Coffeetags::Utils
Class Method Summary collapse
- .file_path(file, output, tag_relative) ⇒ Object
- .option_parser(args) ⇒ Object
- .run(options) ⇒ Object
- .setup_tag_lines(output, files, append) ⇒ Object
Class Method Details
.file_path(file, output, tag_relative) ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'lib/CoffeeTags.rb', line 154 def self.file_path file, output, tag_relative return file if output.nil? return file unless tag_relative output_path = Pathname.new(output). file_path = Pathname.new(file). file_path.relative_path_from(output_path.dirname).to_s end |
.option_parser(args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/CoffeeTags.rb', line 26 def self.option_parser args args << '-h' if args.empty? = {} optparse = OptionParser.new do |opts| opts. = (<<-BAN --------------------------------------------------------------------- #{NAME} #{Coffeetags::VERSION} --------------------------------------------------------------------- by #{AUTHOR} ( #{URL} ) Usage: coffeetags [OPTIONS] <list of files> CoffeeTags + TagBar + Vim ---> https://gist.github.com/1935512 --------------------------------------------------------------------- BAN ).gsub(/^\s*/,'') opts.on('--include-vars', "Include variables in generated tags") do |o| [:include_vars] = true end opts.on('-f', '--file FILE', 'Write tags to FILE (use - for std out)') do |o| [:output] = o unless o == '-' end opts.on('-a', '--append', 'Append tags to existing tags file') do |o| [:append] = true end opts.on('-R', '--recursive', 'Process current directory recursively') do |o| [:recur] = true end opts.on('--tag-relative', 'Should paths be relative to location of tag file?') do |o| [:tag_relative] = true end opts.on('-v', '--version', 'Current version') do puts Coffeetags::VERSION exit end opts.on('--list-kinds', 'Lists the tag kinds') do Coffeetags::Formatter.kinds().map { |k, v| puts "#{k} #{v}" } [:exit] = true end opts.on('-h','--help','HELP') do puts opts [:exit] = true end end optparse.parse! args [:files] = args.to_a [:files] += Dir['./**/*.coffee', './**/Cakefile'] if [:recur] end |
.run(options) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/CoffeeTags.rb', line 90 def self.run exit if [:exit] output = [:output] include_vars = [:include_vars] files = [:files] files = [files] if files.is_a? String files = files.reject { |f| f =~ /^-/} lines = setup_tag_lines output, files, [:append] __out = if output.nil? STDOUT else File.open output, 'w' end __out << Coffeetags::Formatter.header files.each do |file| sc = File.read file parser = Coffeetags::Parser.new sc, include_vars parser.execute! tag_file_path = file_path file, output, [:tag_relative] formatter = Coffeetags::Formatter.new tag_file_path, parser.tree formatter.parse_tree lines.concat(formatter.lines) end lines.sort! __out << lines.map { |l| "#{l}\n"}.join('') __out.close if __out.respond_to? :close __out.join("\n") if __out.is_a? Array end |
.setup_tag_lines(output, files, append) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/CoffeeTags.rb', line 131 def self.setup_tag_lines output, files, append return [] unless append return [] if output.nil? return [] unless File.exists? output files = [] if files.nil? absolute_files = files.map {|f| Pathname.new(f). } output_dir = Pathname.new(output).dirname File.readlines(output). map {|l| l.strip}. reject {|l| l =~ /^!_/ }. reject {|l| raw_file_path = l.split("\t")[1] tag_file = Pathname.new(raw_file_path) tag_file = output_dir + tag_file if raw_file_path =~ /^\./ absolute_files.include? tag_file. } end |