Class: CafeCar::CodePresenter
- Inherits:
-
Object
- Object
- CafeCar::CodePresenter
- Defined in:
- app/presenters/cafe_car/code_presenter.rb
Instance Method Summary collapse
- #formatted ⇒ Object
- #formatter ⇒ Object
- #guess_lexer ⇒ Object
- #lexer ⇒ Object
- #options_lexer ⇒ Object
- #source ⇒ Object
- #to_html ⇒ Object
Instance Method Details
#formatted ⇒ Object
5 |
# File 'app/presenters/cafe_car/code_presenter.rb', line 5 def formatted = formatter.format(lexer.lex(source)) |
#formatter ⇒ Object
3 |
# File 'app/presenters/cafe_car/code_presenter.rb', line 3 def formatter = Rouge::Formatters::HTML.new |
#guess_lexer ⇒ Object
8 |
# File 'app/presenters/cafe_car/code_presenter.rb', line 8 def guess_lexer = Rouge::Lexer.guess(source:) |
#lexer ⇒ Object
10 11 12 |
# File 'app/presenters/cafe_car/code_presenter.rb', line 10 def lexer @lexer ||= || guess_lexer end |
#options_lexer ⇒ Object
7 |
# File 'app/presenters/cafe_car/code_presenter.rb', line 7 def = [:lang].try { Rouge::Lexer.find(_1) } |
#source ⇒ Object
4 |
# File 'app/presenters/cafe_car/code_presenter.rb', line 4 def source = object.to_s |
#to_html ⇒ Object
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 |