Class: Lookbook::CodeFormatter

Inherits:
Rouge::Formatters::HTML
  • Object
show all
Defined in:
lib/lookbook/code_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CodeFormatter

Returns a new instance of CodeFormatter.



3
4
5
# File 'lib/lookbook/code_formatter.rb', line 3

def initialize(opts = {})
  @opts = opts
end

Instance Method Details

#stream(tokens, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/lookbook/code_formatter.rb', line 7

def stream(tokens, &block)
  token_lines(tokens).each_with_index do |line_tokens, i|
    yield "<div class='line'>"
    yield "<div class='line-number'>#{i}</div>" if @opts[:line_numbers]
    yield "<div class='line-content'>"
    line_tokens.each do |token, value|
      yield span(token, value)
    end
    yield "</div>"
    yield "</div>"
  end
end