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.
Constant Summary collapse
- ENCODER =
:div
- ENCODER_OPTIONS =
{}
- VERSION =
File.read(File.("../../VERSION", __FILE__)).chomp
Instance Attribute Summary collapse
-
#encoder ⇒ Object
Encoder (default: ENCODER).
-
#encoder_options ⇒ Object
Encoder options (default: ENCODER_OPTIONS).
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: ENCODER).
29 30 31 |
# File 'lib/haml-coderay.rb', line 29 def encoder @encoder end |
#encoder_options ⇒ Object
Encoder options (default: ENCODER_OPTIONS).
35 36 37 |
# File 'lib/haml-coderay.rb', line 35 def @encoder_options end |
Instance Method Details
#prepare(text) ⇒ Array<String, Symbol>
Prepares the text for passing to ‘::CodeRay.scan`.
42 43 44 |
# File 'lib/haml-coderay.rb', line 42 def prepare(text) [ text.sub(/\A\s*#!(\S+)\s*\n+/, ""), $1.downcase.to_sym ] end |
#render(text) ⇒ String
Returns rendered text.
50 51 52 |
# File 'lib/haml-coderay.rb', line 50 def render(text) ::CodeRay.scan(*prepare(text)).send(encoder, ) end |