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.

Examples:

Ruby


:coderay
  #!ruby

  if true
    puts "hello"
  end

See Also:

Constant Summary collapse

ENCODER =
:div
ENCODER_OPTIONS =
{}
VERSION =
File.read(File.expand_path("../../VERSION", __FILE__)).chomp

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#encoderObject

Encoder (default: ENCODER).



29
30
31
# File 'lib/haml-coderay.rb', line 29

def encoder
  @encoder
end

#encoder_optionsObject

Encoder options (default: ENCODER_OPTIONS).



35
36
37
# File 'lib/haml-coderay.rb', line 35

def encoder_options
  @encoder_options
end

Instance Method Details

#prepare(text) ⇒ Array<String, Symbol>

Prepares the text for passing to ‘::CodeRay.scan`.

Parameters:

  • text (String)

Returns:

  • (Array<String, Symbol>)

    code and language



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.

Parameters:

  • text (String)

    text to render

Returns:

  • (String)

    rendered text

See Also:



50
51
52
# File 'lib/haml-coderay.rb', line 50

def render(text)
  ::CodeRay.scan(*prepare(text)).send(encoder, encoder_options)
end