aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/vendor/builder/xmlmarkup.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-04-25 02:47:44 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-04-25 02:47:44 +0000
commit71a570ffd7ecc94b5b474c659a34e36a29989a65 (patch)
tree1da95c9bb507be698b348cd90f93b492ed67c5cc /activesupport/lib/active_support/vendor/builder/xmlmarkup.rb
parenta9e02fd99fb2889fd25c20eeb5c0762e64d48719 (diff)
downloadrails-71a570ffd7ecc94b5b474c659a34e36a29989a65.tar.gz
rails-71a570ffd7ecc94b5b474c659a34e36a29989a65.tar.bz2
rails-71a570ffd7ecc94b5b474c659a34e36a29989a65.zip
Updated to Builder 2.0 [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4260 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/vendor/builder/xmlmarkup.rb')
-rw-r--r--activesupport/lib/active_support/vendor/builder/xmlmarkup.rb32
1 files changed, 26 insertions, 6 deletions
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=><em>target_object</em>::
# Object receiving the markup. +out+ must respond to the
# <tt><<</tt> operator. The default is a plain string target.
+ #
# :indent=><em>indentation</em>::
# Number of spaces used for indentation. The default is no
# indentation and no line breaks.
+ #
# :margin=><em>initial_indentation_level</em>::
# Amount of initial indentation (specified in levels, not
# spaces).
#
+ # :escape_attrs=><b>OBSOLETE</em>::
+ # 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"
- # # => <![CDATA[blah blah blah]]>
+ # xml.cdata!("text to be included in cdata")
+ # #=> <![CDATA[text to be included in cdata]]>
+ #
def cdata!(text)
_ensure_no_block block_given?
_special("<![CDATA[", "]]>", 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