# Class: Haml::Escapable

Inherits:
  Temple::Filter
  - Object
  - Temple::Filter
  - Haml::Escapable
  show all

Defined in:
  lib/haml/escapable.rb

## Overview

Like Temple::Filters::Escapable, but with support for escaping by Haml::Herlpers.html_escape and Haml::Herlpers.escape_once.

## Defined Under Namespace

Classes: EscapeSafeBuffer

## Instance Method Summary collapse

- #initialize ⇒ Escapable constructor

  A new instance of Escapable.

- #on_dynamic(value)

  The same as Haml::AttributeBuilder.build_attributes.

- #on_escape(flag, exp)
- #on_static(value)

  The same as Haml::AttributeBuilder.build_attributes.

## Constructor Details

### #initialize ⇒ `Escapable`

Returns a new instance of Escapable.

    10
    11
    12
    13
    14

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

    def initialize(*)
      super
      @escape = false
      @escape_safe_buffer = false
    end

## Instance Method Details

### #on_dynamic(value)

The same as Haml::AttributeBuilder.build_attributes

    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49

    # File 'lib/haml/escapable.rb', line 39

    def on_dynamic(value)
      [:dynamic,
       if @escape == :once
         escape_once_code(value)
       elsif @escape
         escape_code(value)
       else
         "(#{value}).to_s"
       end
      ]
    end

### #on_escape(flag, exp)

    16
    17
    18
    19
    20
    21
    22
    23

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

    def on_escape(flag, exp)
      old_escape, old_escape_safe_buffer = @escape, @escape_safe_buffer
      @escape_safe_buffer = flag.is_a?(EscapeSafeBuffer)
      @escape = @escape_safe_buffer ? flag.value : flag
      compile(exp)
    ensure
      @escape, @escape_safe_buffer = old_escape, old_escape_safe_buffer
    end

### #on_static(value)

The same as Haml::AttributeBuilder.build_attributes

    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36

    # File 'lib/haml/escapable.rb', line 26

    def on_static(value)
      [:static,
       if @escape == :once
         escape_once(value)
       elsif @escape
         escape(value)
       else
         value
       end
      ]
    end