Class: Haml::Parser

### Home Classes Methods

### In Files

- lib/haml/parser.rb

### Parent

Object

### Namespace

- CLASS Haml::Parser::Line
- CLASS Haml::Parser::ParseNode

### Methods

- ::new
- #parse

### Included Modules

- Haml::Util

### Class/Module Index

Quicksearch

- Haml
- Haml::Buffer
- Haml::Compiler
- Haml::Engine
- Haml::Error
- Haml::ErubisTemplateHandler
- Haml::Exec
- Haml::Exec::Generic
- Haml::Exec::Haml
- Haml::Filters
- Haml::Filters::Base
- Haml::Filters::Cdata
- Haml::Filters::Css
- Haml::Filters::Erb
- Haml::Filters::Escaped
- Haml::Filters::Javascript
- Haml::Filters::Plain
- Haml::Filters::PrecompiledTiltFilter
- Haml::Filters::Preserve
- Haml::Filters::Ruby
- Haml::Filters::SassRailsTemplate
- Haml::Filters::ScssRailsTemplate
- Haml::Filters::TiltFilter
- Haml::Helpers
- Haml::Helpers::ActionViewExtensions
- Haml::Helpers::ErrorReturn
- Haml::Helpers::XssMods
- Haml::Options
- Haml::Parser
- Haml::Parser::Line
- Haml::Parser::ParseNode
- Haml::Plugin
- Haml::Railtie
- Haml::SafeErubisTemplate
- Haml::SyntaxError
- Haml::Template
- Haml::Util
- Haml::Util::StaticConditionalContext
- ActionView
- ActionView::Base
- ActionView::Helpers
- ActionView::Helpers::CaptureHelper
- ActionView::Helpers::FormHelper
- ActionView::Helpers::FormTagHelper
- ActionView::Helpers::HamlSupport
- ActionView::Helpers::InstanceTag
- ActionView::Helpers::TagHelper
- ActionView::Helpers::Tags
- ActionView::Helpers::Tags::TextArea
- ActionView::Helpers::TextHelper
- Object

No matching classes.

# Haml::Parser

### Constants

BLOCK_KEYWORD_REGEX
BLOCK_WITH_SPACES

  Regex to check for blocks with spaces around arguments. Not to be confused with multiline script. For example:

      foo.each do | bar |
        = bar

COMMENT

  Designates an XHTML/XML comment.

DIV_CLASS

  Designates a `<div>` element with the given class.

DIV_ID

  Designates a `<div>` element with the given id.

DOCTYPE

  Designates an XHTML doctype or script that is never HTML-escaped.

DOCTYPE_REGEX

  The Regex that matches a Doctype command.

ELEMENT

  Designates an XHTML/XML element.

ESCAPE

  Designates a non-parsed line.

FILTER

  Designates a block of filtered text.

FLAT_SCRIPT

  Designates script, the result of which is flattened and output.

LITERAL_VALUE_REGEX

  The Regex that matches a literal string or symbol value

MID_BLOCK_KEYWORDS
MULTILINE_CHAR_VALUE

  The value of the character that designates that a line is part of a multiline string.

PLAIN_TEXT

  Designates a non-parsed line. Not actually a character.

SANITIZE

  Designates script that is always HTML-escaped.

SCRIPT

  Designates script, the result of which is output.

SILENT_COMMENT

  When following SILENT_SCRIPT, designates a comment that is not output.

SILENT_SCRIPT

  Designates script which is run but not output.

SPECIAL_CHARACTERS

  Keeps track of the ASCII values of the characters that begin a specially-interpreted line.

START_BLOCK_KEYWORDS
START_BLOCK_KEYWORD_REGEX

  Try to parse assignments to block starters as best as possible

### Attributes

root[R]

### Public Class Methods

new(template, options) click to toggle source

    # File lib/haml/parser.rb, line 89
    def initialize(template, options)
      # :eod is a special end-of-document marker
      @template           = (template.rstrip).split(/\r\n|\r|\n/) + [:eod, :eod]
      @options            = options
      @flat               = false
      @index              = 0
      # Record the indent levels of "if" statements to validate the subsequent
      # elsif and else statements are indented at the appropriate level.
      @script_level_stack = []
      @template_index     = 0
      @template_tabs      = 0
    end

### Public Instance Methods

parse() click to toggle source

    # File lib/haml/parser.rb, line 102
    def parse
      @root = @parent = ParseNode.new(:root)
      @haml_comment = false
      @indentation = nil
      @line = next_line

      raise SyntaxError.new(Error.message(:indenting_at_start), @line.index) if @line.tabs != 0

      while next_line
        process_indent(@line) unless @line.text.empty?

        if flat?
          text = @line.full.dup
          text = "" unless text.gsub!(/^#{@flat_spaces}/, '')
          @filter_buffer << "#{text}\n"
          @line = @next_line
          next
        end

        @tab_up = nil
        process_line(@line.text, @line.index) unless @line.text.empty? || @haml_comment
        if @parent.type != :haml_comment && (block_opened? || @tab_up)
          @template_tabs += 1
          @parent = @parent.children.last
        end

        if !@haml_comment && !flat? && @next_line.tabs - @line.tabs > 1
          raise SyntaxError.new(Error.message(:deeper_indenting, @next_line.tabs - @line.tabs), @next_line.index)
        end

        @line = @next_line
      end

      # Close all the open tags
      close until @parent.type == :root
      @root
    rescue Haml::Error => e
      e.backtrace.unshift "#{@options[:filename]}:#{(e.line ? e.line + 1 : @index) + @options[:line] - 1}"
      raise
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.