Exception: Hamlit::HamlError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/hamlit/parser/haml_error.rb

Overview

An exception raised by Haml code.

Direct Known Subclasses

HamlSyntaxError

Constant Summary collapse

MESSAGES =
{
  :bad_script_indent            => '"%s" is indented at wrong level: expected %d, but was at %d.',
  :cant_run_filter              => 'Can\'t run "%s" filter; you must require its dependencies first',
  :cant_use_tabs_and_spaces     => "Indentation can't use both tabs and spaces.",
  :deeper_indenting             => "The line was indented %d levels deeper than the previous line.",
  :filter_not_defined           => 'Filter "%s" is not defined.',
  :gem_install_filter_deps      => '"%s" filter\'s %s dependency missing: try installing it or adding it to your Gemfile',
  :illegal_element              => "Illegal element: classes and ids must have values.",
  :illegal_nesting_content      => "Illegal nesting: nesting within a tag that already has content is illegal.",
  :illegal_nesting_header       => "Illegal nesting: nesting within a header command is illegal.",
  :illegal_nesting_line         => "Illegal nesting: content can't be both given on the same line as %%%s and nested within it.",
  :illegal_nesting_plain        => "Illegal nesting: nesting within plain text is illegal.",
  :illegal_nesting_self_closing => "Illegal nesting: nesting within a self-closing tag is illegal.",
  :inconsistent_indentation     => "Inconsistent indentation: %s used for indentation, but the rest of the document was indented using %s.",
  :indenting_at_start           => "Indenting at the beginning of the document is illegal.",
  :install_haml_contrib         => 'To use the "%s" filter, please install the haml-contrib gem.',
  :invalid_attribute_list       => 'Invalid attribute list: %s.',
  :invalid_filter_name          => 'Invalid filter name ":%s".',
  :invalid_tag                  => 'Invalid tag: "%s".',
  :missing_if                   => 'Got "%s" with no preceding "if"',
  :no_ruby_code                 => "There's no Ruby code for %s to evaluate.",
  :self_closing_content         => "Self-closing tags can't have content.",
  :unbalanced_brackets          => 'Unbalanced brackets.',
  :no_end                       => <<-END
You don't need to use "- end" in Haml. Un-indent to close a block:
- if foo?
  %strong Foo!
- else
  Not foo.
%p This line is un-indented, so it isn't part of the "if" block
END
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, line = nil) ⇒ HamlError

Returns a new instance of HamlError.

Parameters:

  • message (String) (defaults to: nil)

    The error message

  • line (Fixnum) (defaults to: nil)

    See #line


50
51
52
53
# File 'lib/hamlit/parser/haml_error.rb', line 50

def initialize(message = nil, line = nil)
  super(message)
  @line = line
end

Instance Attribute Details

#lineFixnum (readonly)

The line of the template on which the error occurred.

Returns:

  • (Fixnum)

46
47
48
# File 'lib/hamlit/parser/haml_error.rb', line 46

def line
  @line
end

Class Method Details

.message(key, *args) ⇒ Object


38
39
40
41
# File 'lib/hamlit/parser/haml_error.rb', line 38

def self.message(key, *args)
  string = MESSAGES[key] or raise "[HAML BUG] No error messages for #{key}"
  (args.empty? ? string : string % args).rstrip
end