Class: Rouge::Lexers::Haml

Inherits:
RegexLexer show all
Includes:
Indentation
Defined in:
lib/rouge/lexers/haml.rb

Overview

A lexer for the Haml templating system for Ruby.

See Also:

Constant Summary

Constants inherited from RegexLexer

RegexLexer::MAX_NULL_SCANS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Indentation

#indentation, #reset!, #starts_block

Methods inherited from RegexLexer

#delegate, get_state, #get_state, #group, #in_state?, #pop!, #push, #reset!, #reset_stack, #run_callback, #run_rule, #stack, start, start_procs, #state, state, #state?, states, #step, #stream_tokens, #token

Methods inherited from Rouge::Lexer

aliases, all, assert_utf8!, #debug, default_options, demo, demo_file, desc, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, lex, #lex, mimetypes, #option, #options, #reset!, #stream_tokens, #tag, tag

Constructor Details

#initialize(opts = {}) ⇒ Haml

Returns a new instance of Haml.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :filters (Object)

    A hash of filter name to lexer of how various filters should be highlighted. By default, :javascript, :css, :ruby, and :erb are supported.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rouge/lexers/haml.rb', line 24

def initialize(opts={})
  (opts.delete(:filters) || {}).each do |name, lexer|
    unless lexer.respond_to? :lex
      lexer = Lexer.find(lexer) or raise "unknown lexer: #{lexer}"
      lexer = lexer.new(options)
    end

    self.filters[name.to_s] = lexer
  end

  super(opts)
end

Class Method Details

.analyze_text(text) ⇒ Object



16
17
18
# File 'lib/rouge/lexers/haml.rb', line 16

def self.analyze_text(text)
  return 0.1 if text.start_with? '!!!'
end

Instance Method Details

#filtersObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rouge/lexers/haml.rb', line 45

def filters
  @filters ||= {
    'javascript' => Javascript.new(options),
    'css' => CSS.new(options),
    'ruby' => ruby,
    'erb' => ERB.new(options),
    'markdown' => Markdown.new(options),
    # TODO
    # 'sass' => Sass.new(options),
    # 'textile' => Textile.new(options),
    # 'maruku' => Maruku.new(options),
  }
end

#htmlObject



41
42
43
# File 'lib/rouge/lexers/haml.rb', line 41

def html
  @html ||= HTML.new(options)
end

#rubyObject



37
38
39
# File 'lib/rouge/lexers/haml.rb', line 37

def ruby
  @ruby ||= Ruby.new(options)
end