Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4260

Show
Ignore:
Timestamp:
04/25/06 02:47:44 (4 years ago)
Author:
david
Message:

Updated to Builder 2.0 [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r4216 r4260  
    11*SVN* 
     2 
     3* Updated to Builder 2.0 [DHH] 
    24 
    35* 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  
    1515  # BlankSlate is useful as a base class when writing classes that 
    1616  # depend upon <tt>method_missing</tt> (e.g. dynamic proxies). 
    17   class BlankSlate #:nodoc: 
     17  class BlankSlate 
    1818    class << self 
     19 
     20      # Hide the method named +name+ in the BlankSlate class.  Don't 
     21      # hide +instance_eval+ or any method beginning with "__". 
    1922      def hide(name) 
    20               undef_method name if 
    21                 instance_methods.include?(name.to_s) and 
    22                 name !~ /^(__|instance_eval)/ 
     23        undef_method name if 
     24          instance_methods.include?(name.to_s) and 
     25          name !~ /^(__|instance_eval)/ 
    2326      end 
    2427    end 
     
    3033# Since Ruby is very dynamic, methods added to the ancestors of 
    3134# 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 
    3337module Kernel #:nodoc: 
    3438  class << self 
    3539    alias_method :blank_slate_method_added, :method_added 
     40 
     41    # Detect method additions to Kernel and remove them in the 
     42    # BlankSlate class. 
    3643    def method_added(name) 
    3744      blank_slate_method_added(name) 
     
    4552  class << self 
    4653    alias_method :blank_slate_method_added, :method_added 
     54 
     55    # Detect method additions to Object and remove them in the 
     56    # BlankSlate class. 
    4757    def method_added(name) 
    4858      blank_slate_method_added(name) 
    49       return if self != Object 
     59      return if self != Object 
    5060      Builder::BlankSlate.hide(name) 
    5161    end 
  • trunk/activesupport/lib/active_support/vendor/builder/xmlbase.rb

    r525 r4260  
    33require 'builder/blankslate' 
    44 
    5 module Builder #:nodoc: 
     5module Builder 
    66 
    77  # Generic error for builder 
     
    1515    # Create an XML markup builder. 
    1616    # 
    17     # out::     Object receiving the markup.1  +out+ must respond to 
     17    # out::     Object receiving the markup.  +out+ must respond to 
    1818    #           <tt><<</tt>. 
    1919    # indent::  Number of spaces used for indentation (0 implies no 
     
    7777 
    7878    # Append text to the output target.  Escape any markup.  May be 
    79     # used within the markup brackets as: 
     79    # used within the markup brakets as: 
    8080    # 
    81     #   builder.p { br; text! "HI" }   #=>  <p><br/>HI</p> 
     81    #   builder.p { |b| b.br; b.text! "HI" }   #=>  <p><br/>HI</p> 
    8282    def text!(text) 
    8383      _text(_escape(text)) 
     
    8585     
    8686    # Append text to the output target without escaping any markup. 
    87     # May be used within the markup brackets as: 
     87    # May be used within the markup brakets as: 
    8888    # 
    8989    #   builder.p { |x| x << "<br/>HI" }   #=>  <p><br/>HI</p> 
     
    113113    private 
    114114     
     115    require 'builder/xchar' 
    115116    def _escape(text) 
    116       text. 
    117         gsub(%r{&}, '&amp;'). 
    118         gsub(%r{<}, '&lt;'). 
    119         gsub(%r{>}, '&gt;') 
     117      text.to_xs 
     118    end 
     119 
     120    def _escape_quote(text) 
     121      _escape(text).gsub(%r{"}, '&quot;')  # " WART 
    120122    end 
    121123 
  • trunk/activesupport/lib/active_support/vendor/builder/xmlmarkup.rb

    r1598 r4260  
    11#!/usr/bin/env ruby 
    22#-- 
    3 # Copyright 2004 by Jim Weirich (jim@weirichhouse.org). 
     3# Copyright 2004, 2005 by Jim Weirich (jim@weirichhouse.org). 
    44# All rights reserved. 
    55 
     
    166166    #    Object receiving the markup.  +out+ must respond to the 
    167167    #    <tt><<</tt> operator.  The default is a plain string target. 
     168    #     
    168169    # :indent=><em>indentation</em>:: 
    169170    #    Number of spaces used for indentation.  The default is no 
    170171    #    indentation and no line breaks. 
     172    #     
    171173    # :margin=><em>initial_indentation_level</em>:: 
    172174    #    Amount of initial indentation (specified in levels, not 
    173175    #    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. 
    174184    #     
    175185    def initialize(options={}) 
     
    240250    end 
    241251 
    242     # Surrounds the given text with a CDATA tag 
     252    # Insert a CDATA section into the XML markup. 
    243253    # 
    244254    # For example: 
    245255    # 
    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    # 
    248259    def cdata!(text) 
    249260      _ensure_no_block block_given? 
     
    290301      order.each do |k| 
    291302        v = attrs[k] 
    292         @target << %{ #{k}="#{v}"} if v 
     303        @target << %{ #{k}="#{_attr_value(v)}"} if v 
    293304      end 
    294305      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) 
    296316      end 
    297317    end