Class: Coffeetags::Formatter
Class Method Summary collapse
-
.header ⇒ Object
Generates CTAGS header.
- .kinds ⇒ Object
Instance Method Summary collapse
-
#initialize(file, tree = []) ⇒ Formatter
constructor
New Formatter class.
- #line_to_string(entry) ⇒ Object
- #lines ⇒ Object
- #parse_tree ⇒ Object
-
#regex_line(line) ⇒ Object
Helper function for formatting a source line into regex.
- #tags ⇒ Object
Constructor Details
Class Method Details
.header ⇒ Object
Generates CTAGS header
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/CoffeeTags/formatter.rb', line 5 def self.header return [ "!_TAG_FILE_FORMAT 2 /extended format/", "!_TAG_FILE_SORTED 0 /0=unsorted, 1=sorted, 2=foldcase/", "!_TAG_PROGRAM_AUTHOR #{::Coffeetags::AUTHOR}", "!_TAG_PROGRAM_NAME #{::Coffeetags::NAME} //", "!_TAG_PROGRAM_URL #{::Coffeetags::URL} /GitHub repository/", "!_TAG_PROGRAM_VERSION #{::Coffeetags::VERSION} //" ].map { |h| "#{h}\n"}.join '' end |
.kinds ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/CoffeeTags/formatter.rb', line 16 def self.kinds return { 'f' => 'function', 'c' => 'class', 'o' => 'object', 'v' => 'var' } end |
Instance Method Details
#line_to_string(entry) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/CoffeeTags/formatter.rb', line 42 def line_to_string entry namespace = (entry[:parent].blank?) ? entry[:name]: entry[:parent] namespace = namespace == entry[:name] ? '' : "object:#{namespace}" [ entry[:name], @file, regex_line(entry[:source]), entry[:kind], "line:#{entry[:line]}", namespace, "kind:"+Formatter::kinds()[entry[:kind]], "language:coffee" ].join("\t") end |
#lines ⇒ Object
70 71 72 |
# File 'lib/CoffeeTags/formatter.rb', line 70 def lines @lines end |
#parse_tree ⇒ Object
58 59 60 61 62 63 |
# File 'lib/CoffeeTags/formatter.rb', line 58 def parse_tree @lines = @tree.map do | content| line_to_string content unless content[:line].nil? or content[:name].blank? end @lines.reject!{|l| l.nil? } end |
#regex_line(line) ⇒ Object
Helper function for formatting a source line into regex
38 39 40 |
# File 'lib/CoffeeTags/formatter.rb', line 38 def regex_line line "/^#{line.gsub(/([\\^$])/, '\\\\\1')}$/;\"" end |
#tags ⇒ Object
66 67 68 |
# File 'lib/CoffeeTags/formatter.rb', line 66 def @lines.map { |l| "#{l}\n"}.join '' end |