New Version

Sync with Latest Instiki Trunk.
Migrate to Rails 1.2.5.
Bump version number.
This commit is contained in:
Jacques Distler 2007-10-15 12:16:54 -05:00
parent de125367b0
commit 207fb1f7f2
120 changed files with 2592 additions and 662 deletions

View file

@ -1,5 +1,11 @@
class Object #:nodoc:
# "", " ", nil, [], and {} are blank
class Object
# An object is blank if it's nil, empty, or a whitespace string.
# For example, "", " ", nil, [], and {} are blank.
#
# This simplifies
# if !address.nil? && !address.empty?
# to
# if !address.blank?
def blank?
if respond_to?(:empty?) && respond_to?(:strip)
empty? or strip.empty?
@ -47,4 +53,4 @@ class Numeric #:nodoc:
def blank?
false
end
end
end

View file

@ -1,5 +1,44 @@
require 'date'
require 'xml_simple'
require 'cgi'
# Extensions needed for Hash#to_query
class Object
def to_param #:nodoc:
to_s
end
def to_query(key) #:nodoc:
"#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
end
end
class Array
def to_query(key) #:nodoc:
collect { |value| value.to_query("#{key}[]") }.sort * '&'
end
end
# Locked down XmlSimple#xml_in_string
class XmlSimple
# Same as xml_in but doesn't try to smartly shoot itself in the foot.
def xml_in_string(string, options = nil)
handle_options('in', options)
@doc = parse(string)
result = collapse(@doc.root)
if @options['keeproot']
merge({}, @doc.root.name, result)
else
result
end
end
def self.xml_in_string(string, options = nil)
new.xml_in_string(string, options)
end
end
module ActiveSupport #:nodoc:
module CoreExtensions #:nodoc:
@ -27,6 +66,12 @@ module ActiveSupport #:nodoc:
klass.extend(ClassMethods)
end
def to_query(namespace = nil)
collect do |key, value|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
end.sort * '&'
end
def to_xml(options = {})
options[:indent] ||= 2
options.reverse_merge!({ :builder => Builder::XmlMarkup.new(:indent => options[:indent]),
@ -81,14 +126,14 @@ module ActiveSupport #:nodoc:
module ClassMethods
def from_xml(xml)
# TODO: Refactor this into something much cleaner that doesn't rely on XmlSimple
undasherize_keys(typecast_xml_value(XmlSimple.xml_in(xml,
undasherize_keys(typecast_xml_value(XmlSimple.xml_in_string(xml,
'forcearray' => false,
'forcecontent' => true,
'keeproot' => true,
'contentkey' => '__content__')
))
))
end
def create_from_xml(xml)
ActiveSupport::Deprecation.warn("Hash.create_from_xml has been renamed to Hash.from_xml", caller)
from_xml(xml)

View file

@ -18,4 +18,18 @@ class Module
parents << Object unless parents.include? Object
parents
end
# Return the constants that have been defined locally by this object and not
# in an ancestor. This method may miss some constants if their definition in
# the ancestor is identical to their definition in the receiver.
def local_constants
inherited = {}
ancestors.each do |anc|
next if anc == self
anc.constants.each { |const| inherited[const] = anc.const_get(const) }
end
constants.select do |const|
! inherited.key?(const) || inherited[const].object_id != const_get(const).object_id
end
end
end

View file

@ -318,13 +318,13 @@ module Dependencies #:nodoc:
watch_frames = descs.collect do |desc|
if desc.is_a? Module
mod_name = desc.name
initial_constants = desc.constants
initial_constants = desc.local_constants
elsif desc.is_a?(String) || desc.is_a?(Symbol)
mod_name = desc.to_s
# Handle the case where the module has yet to be defined.
initial_constants = if qualified_const_defined?(mod_name)
mod_name.constantize.constants
mod_name.constantize.local_constants
else
[]
end
@ -349,7 +349,7 @@ module Dependencies #:nodoc:
mod = mod_name.constantize
next [] unless mod.is_a? Module
new_constants = mod.constants - prior_constants
new_constants = mod.local_constants - prior_constants
# Make sure no other frames takes credit for these constants.
constant_watch_stack.each do |frame_name, constants|

View file

@ -23,12 +23,14 @@ module ActiveSupport
"\n" => '\n',
"\r" => '\r',
"\t" => '\t',
'"' => '\"',
'\\' => '\\\\'
'"' => '\"',
'\\' => '\\\\',
'<' => '\\074',
'>' => '\\076'
}
define_encoder String do |string|
'"' + string.gsub(/[\010\f\n\r\t"\\]/) { |s|
'"' + string.gsub(/[\010\f\n\r\t"\\<>]/) { |s|
ESCAPED_CHARS[s]
}.gsub(/([\xC0-\xDF][\x80-\xBF]|
[\xE0-\xEF][\x80-\xBF]{2}|

View file

@ -43,7 +43,7 @@ module ActiveSupport::Multibyte #:nodoc:
# Create a new Chars instance.
def initialize(str)
@string = (str.string rescue str)
@string = str.respond_to?(:string) ? str.string : str
end
# Returns -1, 0 or +1 depending on whether the Chars object is to be sorted before, equal or after the
@ -70,18 +70,18 @@ module ActiveSupport::Multibyte #:nodoc:
def method_missing(m, *a, &b)
begin
# Simulate methods with a ! at the end because we can't touch the enclosed string from the handlers.
if m.to_s =~ /^(.*)\!$/
if m.to_s =~ /^(.*)\!$/ && handler.respond_to?($1)
result = handler.send($1, @string, *a, &b)
if result == @string
result = nil
else
@string.replace result
end
else
elsif handler.respond_to?(m)
result = handler.send(m, @string, *a, &b)
else
result = @string.send(m, *a, &b)
end
rescue NoMethodError
result = @string.send(m, *a, &b)
rescue Handlers::EncodingError
@string.replace handler.tidy_bytes(@string)
retry
@ -126,4 +126,4 @@ begin
ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8HandlerProc
rescue LoadError
ActiveSupport::Multibyte::Chars.handler = ActiveSupport::Multibyte::Handlers::UTF8Handler
end
end

View file

@ -2,7 +2,7 @@ module ActiveSupport
module VERSION #:nodoc:
MAJOR = 1
MINOR = 4
TINY = 2
TINY = 4
STRING = [MAJOR, MINOR, TINY].join('.')
end