Class: Simplabs::Highlight::PygmentsWrapper
- Inherits:
-
Object
- Object
- Simplabs::Highlight::PygmentsWrapper
- Defined in:
- lib/simplabs/highlight/pygments_wrapper.rb
Overview
Wraps the actual pygments
syntax highlighter and exposes its functionality to Ruby code.
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
The code the wrapper highlights.
-
#language ⇒ Object
readonly
The language the #code to highlight is in.
Instance Method Summary collapse
-
#highlight(options = {}) ⇒ String
Highlights the #code.
-
#initialize(code, language) ⇒ PygmentsWrapper
constructor
Initializes a new PygmentsWrapper.
Constructor Details
#initialize(code, language) ⇒ PygmentsWrapper
Initializes a new Simplabs::Highlight::PygmentsWrapper.
25 26 27 28 |
# File 'lib/simplabs/highlight/pygments_wrapper.rb', line 25 def initialize(code, language) @code = code @language = language end |
Instance Attribute Details
#code ⇒ Object (readonly)
The code the wrapper highlights
12 13 14 |
# File 'lib/simplabs/highlight/pygments_wrapper.rb', line 12 def code @code end |
#language ⇒ Object (readonly)
The language the #code to highlight is in
16 17 18 |
# File 'lib/simplabs/highlight/pygments_wrapper.rb', line 16 def language @language end |
Instance Method Details
#highlight(options = {}) ⇒ String
Highlights the #code.
36 37 38 39 40 41 42 43 |
# File 'lib/simplabs/highlight/pygments_wrapper.rb', line 36 def highlight( = {}) command = "pygmentize -f html -O nowrap=true -l #{@language}" IO.popen(command, mode = 'r+') do |pygments| pygments << @code pygments.close_write result = pygments.read.chomp end end |