Module: Haml::Filters::CodeRay
- Includes:
- Base
- Defined in:
- lib/haml-coderay.rb
Overview
CodeRay filter for Haml. Specify which language to highlight with a shebang followed by the language name.
Instance Attribute Summary collapse
-
#encoder ⇒ Object
Encoder (default: ‘:div`).
-
#encoder_options ⇒ Object
Encoder options (default: ‘{}`).
Instance Method Summary collapse
-
#prepare(text) ⇒ Array<String, Symbol>
Prepares the text for passing to ‘::CodeRay.scan`.
-
#render(text) ⇒ String
Rendered text.
Instance Attribute Details
#encoder ⇒ Object
Encoder (default: ‘:div`).
27 28 29 |
# File 'lib/haml-coderay.rb', line 27 def encoder @encoder end |
#encoder_options ⇒ Object
Encoder options (default: ‘{}`).
33 34 35 |
# File 'lib/haml-coderay.rb', line 33 def @encoder_options end |
Instance Method Details
#prepare(text) ⇒ Array<String, Symbol>
Prepares the text for passing to ‘::CodeRay.scan`.
40 41 42 |
# File 'lib/haml-coderay.rb', line 40 def prepare(text) [ text.sub(/\A\s*#!(\S+)\s*\n+/, ""), $1.downcase.to_sym ] end |
#render(text) ⇒ String
Returns rendered text.
48 49 50 |
# File 'lib/haml-coderay.rb', line 48 def render(text) ::CodeRay.scan(*prepare(text)).send(encoder, ) end |