lib/builder/xmlbase.rb in builder-3.0.1 vs lib/builder/xmlbase.rb in builder-3.0.2
- old
+ new
@@ -62,11 +62,11 @@
ensure
_indent
_end_tag(sym)
_newline
end
- elsif text.nil?
+ elsif text.nil? || text.empty?
_indent
_start_tag(sym, attrs, true)
_newline
else
_indent
@@ -126,11 +126,13 @@
require 'builder/xchar'
if ::String.method_defined?(:encode)
def _escape(text)
result = XChar.encode(text)
begin
- result.encode(@encoding)
+ encoding = ::Encoding::find(@encoding)
+ raise Exception if encoding.dummy?
+ result.encode(encoding)
rescue
# if the encoding can't be supported, use numeric character references
result.
gsub(/[^\u0000-\u007F]/) {|c| "&##{c.ord};"}.
force_encoding('ascii')
@@ -173,14 +175,14 @@
# documents are usually very repetative in nature, the next node will
# be handled by the new method instead of method_missing. As
# method_missing is very slow, this speeds up document generation
# significantly.
def cache_method_call(sym)
- instance_eval <<-NEW_METHOD
- def #{sym.to_s}(*args, &block)
- tag!(:#{sym.to_s}, *args, &block)
+ class << self; self; end.class_eval do
+ define_method(sym) do |*args, &block|
+ tag!(sym, *args, &block)
end
- NEW_METHOD
+ end
end
end
XmlBase.cache_method_calls = true