Class List Method List File List

# Class: Haml::Compiler

Inherits:
  Object
  - Object
  - Haml::Compiler
  show all
Includes:
  Util
Defined in:
  lib/haml/template.rb,
  lib/haml/compiler.rb

## Instance Attribute Summary (collapse)

- - options

  Returns the value of attribute options.

## Instance Method Summary (collapse)

- - compile(node)
- - (Compiler) initialize(options) constructor

  A new instance of Compiler.

- - precompiled
- - precompiled_method_return_value_with_haml_xss (also: #precompiled_method_return_value)
- - precompiled_method_return_value_without_haml_xss
- - precompiled_with_ambles(local_names)

  Returns the precompiled string with the preamble and postamble.

- - precompiled_with_return_value

### Methods included from Util

#av_template_class, #balance, #caller_info, #check_encoding, #check_haml_encoding, #contains_interpolation?, #def_static_method, #handle_interpolation, #html_safe, #human_indentation, #inspect_obj, #powerset, #rails_xss_safe?, #silence_warnings, #static_method_name, #unescape_interpolation

## Constructor Details

### - (`Compiler`) initialize(options)

Returns a new instance of Compiler

    9
    10
    11
    12
    13
    14

    # File 'lib/haml/compiler.rb', line 9

    def initialize(options)
      @options     = options
      @output_tabs = 0
      @to_merge    = []
      @precompiled = ''
    end

## Instance Attribute Details

### - options

Returns the value of attribute options

    7
    8
    9

    # File 'lib/haml/compiler.rb', line 7

    def options
      @options
    end

## Instance Method Details

### - compile(node)

    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26

    # File 'lib/haml/compiler.rb', line 16

    def compile(node)
      parent = instance_variable_defined?('@node') ? @node : nil
      @node = node
      if node.children.empty?
        send(:"compile_#{node.type}")
      else
        send(:"compile_#{node.type}") {node.children.each {|c| compile c}}
      end
    ensure
      @node = parent
    end

### - precompiled

    35
    36
    37

    # File 'lib/haml/compiler.rb', line 35

    def precompiled
      @precompiled
    end

### - precompiled_method_return_value_with_haml_xss Also known as: precompiled_method_return_value

    10
    11
    12

    # File 'lib/haml/template.rb', line 10

    def precompiled_method_return_value_with_haml_xss
      "::Haml::Util.html_safe(#{precompiled_method_return_value_without_haml_xss})"
    end

### - precompiled_method_return_value_without_haml_xss

    13

    # File 'lib/haml/template.rb', line 13

    alias_method :precompiled_method_return_value_without_haml_xss, :precompiled_method_return_value

### - precompiled_with_ambles(local_names)

Returns the precompiled string with the preamble and postamble.

Initializes to ActionView::OutputBuffer when available; this is necessary to avoid ordering issues with partial layouts in Rails. If not available, initializes to nil.

    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70

    # File 'lib/haml/compiler.rb', line 55

    def precompiled_with_ambles(local_names)
      preamble = <<END.gsub("\n", ";")
    begin
    extend Haml::Helpers
    _hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{options.for_buffer.inspect})
    _erbout = _hamlout.buffer
    @output_buffer = output_buffer ||= ActionView::OutputBuffer.new rescue nil
    END
      postamble = <<END.gsub("\n", ";")
    #{precompiled_method_return_value}
    ensure
    @haml_buffer = @haml_buffer.upper if @haml_buffer
    end
    END
      preamble + locals_code(local_names) + precompiled + postamble
    end

### - precompiled_with_return_value

    46
    47
    48

    # File 'lib/haml/compiler.rb', line 46

    def precompiled_with_return_value
      precompiled + ";" + precompiled_method_return_value
    end