Class: CafeCar::CodePresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/cafe_car/code_presenter.rb

Instance Method Summary collapse

Instance Method Details

#formattedObject



5
# File 'app/presenters/cafe_car/code_presenter.rb', line 5

def formatted = formatter.format(lexer.lex(source))

#formatterObject



3
# File 'app/presenters/cafe_car/code_presenter.rb', line 3

def formatter = Rouge::Formatters::HTML.new

#guess_lexerObject



8
# File 'app/presenters/cafe_car/code_presenter.rb', line 8

def guess_lexer = Rouge::Lexer.guess(source:)

#lexerObject



10
11
12
# File 'app/presenters/cafe_car/code_presenter.rb', line 10

def lexer
  @lexer ||= options_lexer || guess_lexer
end

#options_lexerObject



7
# File 'app/presenters/cafe_car/code_presenter.rb', line 7

def options_lexer = options[:lang].try { Rouge::Lexer.find(_1) }

#sourceObject



4
# File 'app/presenters/cafe_car/code_presenter.rb', line 4

def source    = object.to_s

#to_htmlObject



14
15
16
# File 'app/presenters/cafe_car/code_presenter.rb', line 14

def to_html
  ui.Code(formatted.html_safe, class: [ "highlight", lexer.tag ])
end