Class: Rouge::CLI
- Inherits:
-
Thor
- Object
- Thor
- Rouge::CLI
- Defined in:
- lib/rouge/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.start(argv = ARGV, *a) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rouge/cli.rb', line 14 def self.start(argv=ARGV, *a) if argv.include? '-v' or argv.include? '--version' puts Rouge.version exit 0 end unless %w(highlight style list --help -h help).include?(argv.first) argv.unshift 'highlight' end super(argv, *a) end |
Instance Method Details
#highlight(file = nil) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rouge/cli.rb', line 42 def highlight(file=nil) filename = [:file] || file source = filename ? File.read(filename) : $stdin.read if [:lexer].nil? lexer_class = Lexer.guess( :filename => filename, :mimetype => [:mimetype], :source => source, ) else lexer_class = Lexer.find([:lexer]) raise "unknown lexer: #{[:lexer]}" unless lexer_class end formatter_class = Formatter.find([:formatter]) # only HTML is supported for now formatter = formatter_class.new(normalize_hash_keys([:formatter_opts])) lexer = lexer_class.new(normalize_hash_keys([:lexer_opts])) formatter.format(lexer.lex(source), &method(:print)) end |
#list ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rouge/cli.rb', line 76 def list puts "== Available Lexers ==" all_lexers = Lexer.all max_len = all_lexers.map { |l| l.tag.size }.max Lexer.all.each do |lexer| desc = "#{lexer.desc}" if lexer.aliases.any? desc << " [aliases: #{lexer.aliases.join(',')}]" end puts "%s: %s" % [lexer.tag, desc] puts end end |