Class: Lookbook::CodeFormatter
- Inherits:
-
Rouge::Formatters::HTML
- Object
- Rouge::Formatters::HTML
- Lookbook::CodeFormatter
- Defined in:
- lib/lookbook/code_formatter.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ CodeFormatter
constructor
A new instance of CodeFormatter.
- #stream(tokens, &block) ⇒ Object
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 |