module XCPerfect::Syntax

Syntax highlights the function signatures displayed to the user while using the `all.rb` formatter

Public Class Methods

find_lexer(filename, line) click to toggle source

@param [String] filename The filename @param String line of code to be highlighted @return [Rouge::Lexer]

# File lib/xcperfect/syntax.rb, line 35
def self.find_lexer(filename, line)
  case File.extname(filename)
  when '.cpp', '.cc', '.c++', '.cxx', '.hpp', '.h++', '.hxx'
    Rouge::Lexers::Cpp
  when '.m', '.h' then Rouge::Lexers::ObjectiveC
  when '.swift' then Rouge::Lexers::Swift
  when '.ruby', '.rb' then Rouge::Lexers::Ruby
  else
    options = {
      filename: File.basename(filename),
      source: line
    }
    Rouge::Lexer.guesses(options).first
  end
end
highlight(filename, line) click to toggle source
# File lib/xcperfect/syntax.rb, line 18
def self.highlight(filename, line)
  return signature unless Rouge
  highlight_with_formatter(filename, line, Rouge::Formatters::Terminal256.new)
end
highlight_with_formatter(filename, line, formatter) click to toggle source
# File lib/xcperfect/syntax.rb, line 23
def self.highlight_with_formatter(filename, line, formatter)
  lexer = find_lexer(filename, line)
  if lexer
    formatter.format(lexer.lex(line)).rstrip
  else
    line
  end
end