Changeset 4260
- Timestamp:
- 04/25/06 02:47:44 (4 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/vendor/builder/blankslate.rb (modified) (3 diffs)
- trunk/activesupport/lib/active_support/vendor/builder/xchar.rb (added)
- trunk/activesupport/lib/active_support/vendor/builder/xmlbase.rb (modified) (5 diffs)
- trunk/activesupport/lib/active_support/vendor/builder/xmlmarkup.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r4216 r4260 1 1 *SVN* 2 3 * Updated to Builder 2.0 [DHH] 2 4 3 5 * Add Array#split for dividing arrays into one or more subarrays by value or block. [Sam Stephenson] trunk/activesupport/lib/active_support/vendor/builder/blankslate.rb
r77 r4260 15 15 # BlankSlate is useful as a base class when writing classes that 16 16 # depend upon <tt>method_missing</tt> (e.g. dynamic proxies). 17 class BlankSlate #:nodoc:17 class BlankSlate 18 18 class << self 19 20 # Hide the method named +name+ in the BlankSlate class. Don't 21 # hide +instance_eval+ or any method beginning with "__". 19 22 def hide(name) 20 undef_method name if21 instance_methods.include?(name.to_s) and22 name !~ /^(__|instance_eval)/23 undef_method name if 24 instance_methods.include?(name.to_s) and 25 name !~ /^(__|instance_eval)/ 23 26 end 24 27 end … … 30 33 # Since Ruby is very dynamic, methods added to the ancestors of 31 34 # BlankSlate <em>after BlankSlate is defined</em> will show up in the 32 # list of available BlankSlate methods. We handle this by defining a hook in the Object and Kernel classes that will hide any defined 35 # list of available BlankSlate methods. We handle this by defining a 36 # hook in the Object and Kernel classes that will hide any defined 33 37 module Kernel #:nodoc: 34 38 class << self 35 39 alias_method :blank_slate_method_added, :method_added 40 41 # Detect method additions to Kernel and remove them in the 42 # BlankSlate class. 36 43 def method_added(name) 37 44 blank_slate_method_added(name) … … 45 52 class << self 46 53 alias_method :blank_slate_method_added, :method_added 54 55 # Detect method additions to Object and remove them in the 56 # BlankSlate class. 47 57 def method_added(name) 48 58 blank_slate_method_added(name) 49 return if self != Object59 return if self != Object 50 60 Builder::BlankSlate.hide(name) 51 61 end trunk/activesupport/lib/active_support/vendor/builder/xmlbase.rb
r525 r4260 3 3 require 'builder/blankslate' 4 4 5 module Builder #:nodoc:5 module Builder 6 6 7 7 # Generic error for builder … … 15 15 # Create an XML markup builder. 16 16 # 17 # out:: Object receiving the markup. 1+out+ must respond to17 # out:: Object receiving the markup. +out+ must respond to 18 18 # <tt><<</tt>. 19 19 # indent:: Number of spaces used for indentation (0 implies no … … 77 77 78 78 # Append text to the output target. Escape any markup. May be 79 # used within the markup bra ckets as:79 # used within the markup brakets as: 80 80 # 81 # builder.p { br;text! "HI" } #=> <p><br/>HI</p>81 # builder.p { |b| b.br; b.text! "HI" } #=> <p><br/>HI</p> 82 82 def text!(text) 83 83 _text(_escape(text)) … … 85 85 86 86 # Append text to the output target without escaping any markup. 87 # May be used within the markup bra ckets as:87 # May be used within the markup brakets as: 88 88 # 89 89 # builder.p { |x| x << "<br/>HI" } #=> <p><br/>HI</p> … … 113 113 private 114 114 115 require 'builder/xchar' 115 116 def _escape(text) 116 text. 117 gsub(%r{&}, '&'). 118 gsub(%r{<}, '<'). 119 gsub(%r{>}, '>') 117 text.to_xs 118 end 119 120 def _escape_quote(text) 121 _escape(text).gsub(%r{"}, '"') # " WART 120 122 end 121 123 trunk/activesupport/lib/active_support/vendor/builder/xmlmarkup.rb
r1598 r4260 1 1 #!/usr/bin/env ruby 2 2 #-- 3 # Copyright 2004 by Jim Weirich (jim@weirichhouse.org).3 # Copyright 2004, 2005 by Jim Weirich (jim@weirichhouse.org). 4 4 # All rights reserved. 5 5 … … 166 166 # Object receiving the markup. +out+ must respond to the 167 167 # <tt><<</tt> operator. The default is a plain string target. 168 # 168 169 # :indent=><em>indentation</em>:: 169 170 # Number of spaces used for indentation. The default is no 170 171 # indentation and no line breaks. 172 # 171 173 # :margin=><em>initial_indentation_level</em>:: 172 174 # Amount of initial indentation (specified in levels, not 173 175 # spaces). 176 # 177 # :escape_attrs=><b>OBSOLETE</em>:: 178 # The :escape_attrs option is no longer supported by builder 179 # (and will be quietly ignored). String attribute values are 180 # now automatically escaped. If you need unescaped attribute 181 # values (perhaps you are using entities in the attribute 182 # values), then give the value as a Symbol. This allows much 183 # finer control over escaping attribute values. 174 184 # 175 185 def initialize(options={}) … … 240 250 end 241 251 242 # Surrounds the given text with a CDATA tag252 # Insert a CDATA section into the XML markup. 243 253 # 244 254 # For example: 245 255 # 246 # xml.cdata! "blah blah blah" 247 # # => <![CDATA[blah blah blah]]> 256 # xml.cdata!("text to be included in cdata") 257 # #=> <![CDATA[text to be included in cdata]]> 258 # 248 259 def cdata!(text) 249 260 _ensure_no_block block_given? … … 290 301 order.each do |k| 291 302 v = attrs[k] 292 @target << %{ #{k}="#{ v}"} if v303 @target << %{ #{k}="#{_attr_value(v)}"} if v 293 304 end 294 305 attrs.each do |k, v| 295 @target << %{ #{k}="#{v}"} unless order.member?(k) 306 @target << %{ #{k}="#{_attr_value(v)}"} unless order.member?(k) 307 end 308 end 309 310 def _attr_value(value) 311 case value 312 when Symbol 313 value.to_s 314 else 315 _escape_quote(value.to_s) 296 316 end 297 317 end