From 71a570ffd7ecc94b5b474c659a34e36a29989a65 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 25 Apr 2006 02:47:44 +0000 Subject: Updated to Builder 2.0 [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4260 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_support/vendor/builder/xmlmarkup.rb | 32 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'activesupport/lib/active_support/vendor/builder/xmlmarkup.rb') diff --git a/activesupport/lib/active_support/vendor/builder/xmlmarkup.rb b/activesupport/lib/active_support/vendor/builder/xmlmarkup.rb index b7e3b2d009..12b6ff9828 100644 --- a/activesupport/lib/active_support/vendor/builder/xmlmarkup.rb +++ b/activesupport/lib/active_support/vendor/builder/xmlmarkup.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby #-- -# Copyright 2004 by Jim Weirich (jim@weirichhouse.org). +# Copyright 2004, 2005 by Jim Weirich (jim@weirichhouse.org). # All rights reserved. # Permission is granted for use, copying, modification, distribution, @@ -165,13 +165,23 @@ module Builder # :target=>target_object:: # Object receiving the markup. +out+ must respond to the # << operator. The default is a plain string target. + # # :indent=>indentation:: # Number of spaces used for indentation. The default is no # indentation and no line breaks. + # # :margin=>initial_indentation_level:: # Amount of initial indentation (specified in levels, not # spaces). # + # :escape_attrs=>OBSOLETE:: + # The :escape_attrs option is no longer supported by builder + # (and will be quietly ignored). String attribute values are + # now automatically escaped. If you need unescaped attribute + # values (perhaps you are using entities in the attribute + # values), then give the value as a Symbol. This allows much + # finer control over escaping attribute values. + # def initialize(options={}) indent = options[:indent] || 0 margin = options[:margin] || 0 @@ -239,12 +249,13 @@ module Builder [:version, :encoding, :standalone]) end - # Surrounds the given text with a CDATA tag + # Insert a CDATA section into the XML markup. # # For example: # - # xml.cdata! "blah blah blah" - # # => + # xml.cdata!("text to be included in cdata") + # #=> + # def cdata!(text) _ensure_no_block block_given? _special("", text, nil) @@ -289,10 +300,19 @@ module Builder return if attrs.nil? order.each do |k| v = attrs[k] - @target << %{ #{k}="#{v}"} if v + @target << %{ #{k}="#{_attr_value(v)}"} if v end attrs.each do |k, v| - @target << %{ #{k}="#{v}"} unless order.member?(k) + @target << %{ #{k}="#{_attr_value(v)}"} unless order.member?(k) + end + end + + def _attr_value(value) + case value + when Symbol + value.to_s + else + _escape_quote(value.to_s) end end -- cgit v1.2.3