Module: Erubis::JavascriptGenerator

Module | Erubis::JavascriptGenerator
In: | erubis/engine/ejavascript.rb

### Methods

add_expr_debug add_expr_escaped add_expr_literal add_indent add_postamble add_preamble add_stmt add_text escape_text init_generator

### Included Modules

Generator

### Public Instance methods

add_expr_debug(src, code)

[Source]

    # File erubis/engine/ejavascript.rb, line 72
        def add_expr_debug(src, code)
          add_indent(src, @indent)
          code.strip!
          src << "alert(\"*** debug: #{code}=\"+(#{code}));"
        end

add_expr_escaped(src, code)

[Source]

    # File erubis/engine/ejavascript.rb, line 68
        def add_expr_escaped(src, code)
          add_expr_literal(src, escaped_expr(code))
        end

add_expr_literal(src, code)

[Source]

    # File erubis/engine/ejavascript.rb, line 62
        def add_expr_literal(src, code)
          add_indent(src, @indent)
          code.strip!
          src << "#{@bufvar}.push(#{code});"
        end

add_indent(src, indent)

[Source]

    # File erubis/engine/ejavascript.rb, line 41
        def add_indent(src, indent)
          src << (src.empty? || src[-1] == ?\n ? indent : ' ')
        end

add_postamble(src)

[Source]

    # File erubis/engine/ejavascript.rb, line 78
        def add_postamble(src)
          src << "\n" if src[-1] == ?;
          if @docwrite
            src << @indent << 'document.write(' << @bufvar << ".join(\"\"));\n"
          else
            src << @indent << @bufvar << ".join(\"\");\n"
          end
        end

add_preamble(src)

[Source]

    # File erubis/engine/ejavascript.rb, line 32
        def add_preamble(src)
          src << "#{@indent}var #{@bufvar} = [];"
        end

add_stmt(src, code)

[Source]

    # File erubis/engine/ejavascript.rb, line 58
        def add_stmt(src, code)
          src << code
        end

add_text(src, text)

[Source]

    # File erubis/engine/ejavascript.rb, line 45
        def add_text(src, text)
          return if text.empty?
          add_indent(src, @indent)
          src << @bufvar << '.push("'
          s = escape_text(text)
          if s[-1] == ?\n
            s[-2, 2] = ''
            src << s << "\");\n"
          else
            src << s << "\");"
          end
        end

escape_text(text)

[Source]

    # File erubis/engine/ejavascript.rb, line 36
        def escape_text(text)
          @@table_ ||= { "\r"=>"\\r", "\n"=>"\\n\\\n", "\t"=>"\\t", '"'=>'\\"', "\\"=>"\\\\" }
          return text.gsub!(/[\r\n\t"\\]/) { |m| @@table_[m] } || text
        end

init_generator(properties={})

[Source]

    # File erubis/engine/ejavascript.rb, line 24
        def init_generator(properties={})
          super
          @escapefunc ||= 'escape'
          @indent = properties[:indent] || ''
          @bufvar = properties[:bufvar] || '_buf'
          @docwrite = properties[:docwrite] != false  # '!= false' will be removed in the next release
        end

[Validate]