Class: Hylite::Rouge

Inherits:
Hyliter show all
Defined in:
lib/hylite/hyliters.rb

Instance Attribute Summary

Attributes inherited from Hyliter

#code, #lang

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hyliter

#initialize, new?

Constructor Details

This class inherits a constructor from Hylite::Hyliter

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/hylite/hyliters.rb', line 26

def self.available?
  require 'rouge'
  true
rescue LoadError
  false
end

Instance Method Details

#callObject



37
38
39
40
41
42
43
44
45
# File 'lib/hylite/hyliters.rb', line 37

def call
  # From Fish, you can see all styles with:
  # for style in (rougify help style | tail -1 | tr -d ' ' | tr , \n); echo \n===== $style =====; rougify highlight -t $style -l ruby bin/hylite   ; end
  theme     = ::Rouge::Theme.find 'monokai'
  formatter = ::Rouge::Formatters::Terminal256.new theme
  lexer     = ::Rouge::Lexer.find @lang
  tokens    = lexer.lex @code
  formatter.format(tokens)
end

#typeObject



33
34
35
# File 'lib/hylite/hyliters.rb', line 33

def type
  :rouge
end