Module | Erubis::JavascriptGenerator |
In: |
erubis/engine/ejavascript.rb
|
# File erubis/engine/ejavascript.rb, line 73 def add_expr_debug(src, code) add_indent(src, @indent) code.strip! src << "alert(\"*** debug: #{code}=\"+(#{code}));" end
# File erubis/engine/ejavascript.rb, line 69 def add_expr_escaped(src, code) add_expr_literal(src, escaped_expr(code)) end
# File erubis/engine/ejavascript.rb, line 63 def add_expr_literal(src, code) add_indent(src, @indent) code.strip! src << "#{@buf}.push(#{code});" end
# File erubis/engine/ejavascript.rb, line 42 def add_indent(src, indent) src << (src.empty? || src[-1] == ?\n ? indent : ' ') end
# File erubis/engine/ejavascript.rb, line 79 def add_postamble(src) src << "\n" if src[-1] == ?; if @docwrite src << @indent << 'document.write(' << @buf << ".join(\"\"));\n" else src << @indent << @buf << ".join(\"\");\n" end end
# File erubis/engine/ejavascript.rb, line 33 def add_preamble(src) src << "#{@indent}var #{@buf} = [];" end
# File erubis/engine/ejavascript.rb, line 46 def add_text(src, text) return if text.empty? add_indent(src, @indent) src << @buf << '.push("' s = escape_text(text) if s[-1] == ?\n s[-2, 2] = '' src << s << "\");\n" else src << s << "\");" end end
# File erubis/engine/ejavascript.rb, line 37 def escape_text(text) @@table_ ||= { "\r"=>"\\r", "\n"=>"\\n\\\n", "\t"=>"\\t", '"'=>'\\"', "\\"=>"\\\\" } return text.gsub!(/[\r\n\t"\\]/) { |m| @@table_[m] } || text end