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

Constants included from Token::Tokens

Token::Tokens::Num, Token::Tokens::Str

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Indentation

#indentation, #reset!, #starts_block

Methods inherited from RegexLexer

append, #delegate, get_state, #get_state, #goto, #group, #groups, #in_state?, #pop!, prepend, #push, #recurse, replace_state, #reset!, #reset_stack, #stack, start, start_procs, #state, state, #state?, state_definitions, 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

Methods included from Token::Tokens

token

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.



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

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



18
19
20
# File 'lib/rouge/lexers/haml.rb', line 18

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

Instance Method Details

#filtersObject



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

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



43
44
45
# File 'lib/rouge/lexers/haml.rb', line 43

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

#rubyObject



39
40
41
# File 'lib/rouge/lexers/haml.rb', line 39

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