Class: Coffeetags::Utils

Inherits:
Object show all
Defined in:
lib/CoffeeTags.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) option_parser(args)



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
88
89
90
91
92
# File 'lib/CoffeeTags.rb', line 33

def self.option_parser args
  args << '-h' if args.empty?
  options = {}
  optparse = OptionParser.new do |opts|
    opts.banner  = (<<-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|
      options[:include_vars] = true
    end

    opts.on('-f', '--file FILE', 'Write tags to FILE (use - for std out)') do |o|
      options[:output] = o unless o == '-'

    end

    opts.on('-R', '--recursive', 'Process current directory recursively') do |o|
      options[:recur] = true
    end

    opts.on('--vim-conf', 'Generate TagBar config (more info https://gist.github.com/1935512 )') do
      puts tagbar_conf options[:include_vars]
      exit
    end

    opts.on('-v', '--version', 'Current version') do
      puts Coffeetags::VERSION
      exit
    end

    opts.on('-h','--help','HALP') do
      puts opts
      exit
    end

  end

  optparse.parse! args

  options[:files]  = args.to_a
  options[:files] += Dir['./**/*.coffee', './**/Cakefile'] if options[:recur]

  [
    options[:output],
    options[:include_vars],
    options[:files]
  ]

end

+ (Object) run(output, include_vars, files)



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
# File 'lib/CoffeeTags.rb', line 95

def self.run output, include_vars,  files
  __out = if output.nil?
            STDOUT
          else
            File.open output, 'w'
          end

  __out  << Coffeetags::Formatter.header

  files = [ files] if files.is_a? String

  files.reject { |f| f =~ /^-/}.each do |file|
    sc = File.read file
    parser = Coffeetags::Parser.new sc, include_vars
    parser.execute!

    formatter = Coffeetags::Formatter.new file, parser.tree

    formatter.parse_tree

    __out << formatter.tags
  end
  __out.close if __out.respond_to? :close

  __out.join("\n") if __out.is_a? Array
end

+ (Object) tagbar_conf(include_vars)



24
25
26
27
28
29
30
31
# File 'lib/CoffeeTags.rb', line 24

def self.tagbar_conf include_vars
  include_vars_opt = include_vars ? "--include-vars" : ''

  tmpl_file = File.read(File.expand_path("../../vim/tagbar-coffee.vim.erb", __FILE__))
  tmpl = ERB.new(tmpl_file)

  tmpl.result(binding)
end