Sha256: 6dbdb4db10d321baa492ed184f4f57dffeb90ec7f8d36b2809036f2b46f8dd09

Contents?: true

Size: 1.39 KB

Versions: 19

Compression:

Stored size: 1.39 KB

Contents

Node  = require('./node')

# Code node that represent lines of CoffeeScript code
# in the Haml template.
#
# @example inline code
#   - for project in projects
#
# @example Escaped code assignment
#   = user.get('email')
#
# @example Unescaped code assignment
#   != user.get('email')
#
module.exports = class Code extends Node

  # Evaluate the Haml inline code
  #
  evaluate: ->
    codeBlock  = @expression.match(/(-|!=|\&=|=|~)\s?(.*)?/)
    identifier = codeBlock[1]
    code       = codeBlock[2]
   
    # Code block without output
    if identifier is '-'
      @opener = @markRunningCode(code)

      # Suppress return value from function with Haml tags
      @closer = @markRunningCode("  ''") if @children.length isnt 0 and @opener.code.match(/(->|=>)/)

    # Code block that preserves whitespace
    else if identifier is '~'
      if @escapeHtml
        @opener = @markInsertingCode(code, true, false, true)
      else
        @opener = @markInsertingCode(code, false, false, true)

    # Code block with output
    else
      escape = identifier is '&=' or (identifier is '=' and @escapeHtml)

      if @children.length isnt 0 and code.match(/(->|=>)$/)
        @opener = @markInsertingCode(code, escape, false, false)
        @opener.block = 'start'

        @closer = @markRunningCode("  $buffer.join \"\\n\"")
        @closer.block = 'end'

      else
        @opener = @markInsertingCode(code, escape)

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 node_modules/haml-coffee/src/nodes/code.coffee
ela-4.1.5 node_modules/haml-coffee/src/nodes/code.coffee
ela-4.1.4 node_modules/haml-coffee/src/nodes/code.coffee
ela-4.1.3 node_modules/haml-coffee/src/nodes/code.coffee
ela-4.1.2 node_modules/haml-coffee/src/nodes/code.coffee
ela-4.1.1 node_modules/haml-coffee/src/nodes/code.coffee
ela-4.1.0 node_modules/haml-coffee/src/nodes/code.coffee
ela-4.0.0 node_modules/haml-coffee/src/nodes/code.coffee
ela-3.4.3 node_modules/haml-coffee/src/nodes/code.coffee
ela-3.4.2 node_modules/haml-coffee/src/nodes/code.coffee
ela-3.4.0 node_modules/haml-coffee/src/nodes/code.coffee
ela-3.3.1 node_modules/haml-coffee/src/nodes/code.coffee
ela-3.3.0 node_modules/haml-coffee/src/nodes/code.coffee
ela-3.2.0 node_modules/haml-coffee/src/nodes/code.coffee
ela-3.1.1 node_modules/haml-coffee/src/nodes/code.coffee
ela-3.1.0 node_modules/haml-coffee/src/nodes/code.coffee
ela-3.0.0 node_modules/haml-coffee/src/nodes/code.coffee
ela-2.0.0 node_modules/haml-coffee/src/nodes/code.coffee
ela-1.1.0 node_modules/haml-coffee/src/nodes/code.coffee