Skip to content

Commit

Permalink
[change] 'JavaGenerator' and 'JavaScriptGenerator' to rename ':buf' o…
Browse files Browse the repository at this point in the history
…ption into ':bufvar'
  • Loading branch information
kwatch committed Mar 21, 2011
1 parent d15898c commit 2e1d6c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions lib/erubis/engine/ejava.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module JavaGenerator
def self.supported_properties() # :nodoc:
return [
[:indent, '', "indent spaces (ex. ' ')"],
[:buf, '_buf', "output buffer name"],
[:bufvar, '_buf', "output buffer variable name"],
[:bufclass, 'StringBuffer', "output buffer class (ex. 'StringBuilder')"],
]
end
Expand All @@ -25,12 +25,12 @@ def init_generator(properties={})
super
@escapefunc ||= 'escape'
@indent = properties[:indent] || ''
@buf = properties[:buf] || '_buf'
@bufvar = properties[:bufvar] || '_buf'
@bufclass = properties[:bufclass] || 'StringBuffer'
end

def add_preamble(src)
src << "#{@indent}#{@bufclass} #{@buf} = new #{@bufclass}();"
src << "#{@indent}#{@bufclass} #{@bufvar} = new #{@bufclass}();"
end

def escape_text(text)
Expand All @@ -41,7 +41,7 @@ def escape_text(text)
def add_text(src, text)
return if text.empty?
src << (src.empty? || src[-1] == ?\n ? @indent : ' ')
src << @buf << ".append("
src << @bufvar << ".append("
i = 0
text.each_line do |line|
src << "\n" << @indent << ' + ' if i > 0
Expand All @@ -58,7 +58,7 @@ def add_stmt(src, code)
def add_expr_literal(src, code)
src << @indent if src.empty? || src[-1] == ?\n
code.strip!
src << " #{@buf}.append(#{code});"
src << " #{@bufvar}.append(#{code});"
end

def add_expr_escaped(src, code)
Expand All @@ -73,8 +73,8 @@ def add_expr_debug(src, code)

def add_postamble(src)
src << "\n" if src[-1] == ?;
src << @indent << "return " << @buf << ".toString();\n"
#src << @indent << "System.out.print(" << @buf << ".toString());\n"
src << @indent << "return " << @bufvar << ".toString();\n"
#src << @indent << "System.out.print(" << @bufvar << ".toString());\n"
end

end
Expand Down
14 changes: 7 additions & 7 deletions lib/erubis/engine/ejavascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module JavascriptGenerator
def self.supported_properties() # :nodoc:
list = []
#list << [:indent, '', "indent spaces (ex. ' ')"]
#list << [:buf, '_buf', "output buffer name"]
#list << [:bufvar, '_buf', "output buffer variable name"]
list << [:docwrite, true, "use 'document.write()' when true"]
return list
end
Expand All @@ -25,12 +25,12 @@ def init_generator(properties={})
super
@escapefunc ||= 'escape'
@indent = properties[:indent] || ''
@buf = properties[:out] || '_buf'
@bufvar = properties[:bufvar] || '_buf'
@docwrite = properties[:docwrite] != false # '!= false' will be removed in the next release
end

def add_preamble(src)
src << "#{@indent}var #{@buf} = [];"
src << "#{@indent}var #{@bufvar} = [];"
end

def escape_text(text)
Expand All @@ -45,7 +45,7 @@ def add_indent(src, indent)
def add_text(src, text)
return if text.empty?
add_indent(src, @indent)
src << @buf << '.push("'
src << @bufvar << '.push("'
s = escape_text(text)
if s[-1] == ?\n
s[-2, 2] = ''
Expand All @@ -62,7 +62,7 @@ def add_stmt(src, code)
def add_expr_literal(src, code)
add_indent(src, @indent)
code.strip!
src << "#{@buf}.push(#{code});"
src << "#{@bufvar}.push(#{code});"
end

def add_expr_escaped(src, code)
Expand All @@ -78,9 +78,9 @@ def add_expr_debug(src, code)
def add_postamble(src)
src << "\n" if src[-1] == ?;
if @docwrite
src << @indent << 'document.write(' << @buf << ".join(\"\"));\n"
src << @indent << 'document.write(' << @bufvar << ".join(\"\"));\n"
else
src << @indent << @buf << ".join(\"\");\n"
src << @indent << @bufvar << ".join(\"\");\n"
end
end

Expand Down

0 comments on commit 2e1d6c3

Please sign in to comment.