Index: builder-2.1.2/builder.blurb
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/builder.blurb 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,27 @@
+name: builder
+document: http://builder.rubyforge.org
+download: http://rubyforge.org/frs/?group_id=415
+description: >
+ <p>This package contains Builder, a simple ruby library for
+ building XML document quickly and easily.</p>
+
+ <p>Here's an example:</p>
+
+ <pre>
+ xml = Builder::XmlMarkup.new(:indent=>2)
+ xml.person {
+ xml.first_name("Jim")
+ xml.last_name("Weirich")
+ }
+ puts xml.target!
+ </pre>
+
+ <p>Produces:</p>
+
+ <pre>
+ <person>
+ <first_name>Jim</first_name>
+ <last_name>Weirich</last_name>
+ </person>
+ </pre>
+
Index: builder-2.1.2/CHANGES
===================================================================
--- builder-2.1.2.orig/CHANGES 2007-06-15 07:01:59.000000000 +0200
+++ builder-2.1.2/CHANGES 2010-03-21 16:37:51.000000000 +0100
@@ -1,12 +1,16 @@
= Change Log
+== Version 2.2.0
+
+* Applied patch from Thijs van der Vossen to allow UTF-8 encoded
+ output when the encoding is UTF-8 and $KCODE is UTF8.
+
== Version 2.1.2
* Fixed bug where private methods in kernel could leak through using
tag!(). Thanks to Hagen Overdick for finding and diagnosing this
bug.
-
== Version 2.1.1
* Fixed typo in XmlMarkup class docs (ident => indent). (from Martin
Index: builder-2.1.2/doc/jamis.rb
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/doc/jamis.rb 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,591 @@
+module RDoc
+module Page
+
+FONTS = "\"Bitstream Vera Sans\", Verdana, Arial, Helvetica, sans-serif"
+
+STYLE = <<CSS
+a {
+ color: #00F;
+ text-decoration: none;
+}
+
+a:hover {
+ color: #77F;
+ text-decoration: underline;
+}
+
+body, td, p {
+ font-family: %fonts%;
+ background: #FFF;
+ color: #000;
+ margin: 0px;
+ font-size: small;
+}
+
+#content {
+ margin: 2em;
+}
+
+#description p {
+ margin-bottom: 0.5em;
+}
+
+.sectiontitle {
+ margin-top: 1em;
+ margin-bottom: 1em;
+ padding: 0.5em;
+ padding-left: 2em;
+ background: #005;
+ color: #FFF;
+ font-weight: bold;
+ border: 1px dotted black;
+}
+
+.attr-rw {
+ padding-left: 1em;
+ padding-right: 1em;
+ text-align: center;
+ color: #055;
+}
+
+.attr-name {
+ font-weight: bold;
+}
+
+.attr-desc {
+}
+
+.attr-value {
+ font-family: monospace;
+}
+
+.file-title-prefix {
+ font-size: large;
+}
+
+.file-title {
+ font-size: large;
+ font-weight: bold;
+ background: #005;
+ color: #FFF;
+}
+
+.banner {
+ background: #005;
+ color: #FFF;
+ border: 1px solid black;
+ padding: 1em;
+}
+
+.banner td {
+ background: transparent;
+ color: #FFF;
+}
+
+h1 a, h2 a, .sectiontitle a, .banner a {
+ color: #FF0;
+}
+
+h1 a:hover, h2 a:hover, .sectiontitle a:hover, .banner a:hover {
+ color: #FF7;
+}
+
+.dyn-source {
+ display: none;
+ background: #FFE;
+ color: #000;
+ border: 1px dotted black;
+ margin: 0.5em 2em 0.5em 2em;
+ padding: 0.5em;
+}
+
+.dyn-source .cmt {
+ color: #00F;
+ font-style: italic;
+}
+
+.dyn-source .kw {
+ color: #070;
+ font-weight: bold;
+}
+
+.method {
+ margin-left: 1em;
+ margin-right: 1em;
+ margin-bottom: 1em;
+}
+
+.description pre {
+ padding: 0.5em;
+ border: 1px dotted black;
+ background: #FFE;
+}
+
+.method .title {
+ font-family: monospace;
+ font-size: large;
+ border-bottom: 1px dashed black;
+ margin-bottom: 0.3em;
+ padding-bottom: 0.1em;
+}
+
+.method .description, .method .sourcecode {
+ margin-left: 1em;
+}
+
+.description p, .sourcecode p {
+ margin-bottom: 0.5em;
+}
+
+.method .sourcecode p.source-link {
+ text-indent: 0em;
+ margin-top: 0.5em;
+}
+
+.method .aka {
+ margin-top: 0.3em;
+ margin-left: 1em;
+ font-style: italic;
+ text-indent: 2em;
+}
+
+h1 {
+ padding: 1em;
+ border: 1px solid black;
+ font-size: x-large;
+ font-weight: bold;
+ color: #FFF;
+ background: #007;
+}
+
+h2 {
+ padding: 0.5em 1em 0.5em 1em;
+ border: 1px solid black;
+ font-size: large;
+ font-weight: bold;
+ color: #FFF;
+ background: #009;
+}
+
+h3, h4, h5, h6 {
+ padding: 0.2em 1em 0.2em 1em;
+ border: 1px dashed black;
+ color: #000;
+ background: #AAF;
+}
+
+.sourcecode > pre {
+ padding: 0.5em;
+ border: 1px dotted black;
+ background: #FFE;
+}
+
+CSS
+
+XHTML_PREAMBLE = %{<?xml version="1.0" encoding="%charset%"?>
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+}
+
+HEADER = XHTML_PREAMBLE + <<ENDHEADER
+<html>
+ <head>
+ <title>%title%</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%" />
+ <link rel="stylesheet" href="%style_url%" type="text/css" media="screen" />
+
+ <script language="JavaScript" type="text/javascript">
+ // <![CDATA[
+
+ function toggleSource( id )
+ {
+ var elem
+ var link
+
+ if( document.getElementById )
+ {
+ elem = document.getElementById( id )
+ link = document.getElementById( "l_" + id )
+ }
+ else if ( document.all )
+ {
+ elem = eval( "document.all." + id )
+ link = eval( "document.all.l_" + id )
+ }
+ else
+ return false;
+
+ if( elem.style.display == "block" )
+ {
+ elem.style.display = "none"
+ link.innerHTML = "show source"
+ }
+ else
+ {
+ elem.style.display = "block"
+ link.innerHTML = "hide source"
+ }
+ }
+
+ function openCode( url )
+ {
+ window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
+ }
+ // ]]>
+ </script>
+ </head>
+
+ <body>
+ENDHEADER
+
+FILE_PAGE = <<HTML
+<table border='0' cellpadding='0' cellspacing='0' width="100%" class='banner'>
+ <tr><td>
+ <table width="100%" border='0' cellpadding='0' cellspacing='0'><tr>
+ <td class="file-title" colspan="2"><span class="file-title-prefix">File</span><br />%short_name%</td>
+ <td align="right">
+ <table border='0' cellspacing="0" cellpadding="2">
+ <tr>
+ <td>Path:</td>
+ <td>%full_path%
+IF:cvsurl
+ (<a href="%cvsurl%">CVS</a>)
+ENDIF:cvsurl
+ </td>
+ </tr>
+ <tr>
+ <td>Modified:</td>
+ <td>%dtm_modified%</td>
+ </tr>
+ </table>
+ </td></tr>
+ </table>
+ </td></tr>
+</table><br>
+HTML
+
+###################################################################
+
+CLASS_PAGE = <<HTML
+<table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
+ <td class="file-title"><span class="file-title-prefix">%classmod%</span><br />%full_name%</td>
+ <td align="right">
+ <table cellspacing=0 cellpadding=2>
+ <tr valign="top">
+ <td>In:</td>
+ <td>
+START:infiles
+HREF:full_path_url:full_path:
+IF:cvsurl
+ (<a href="%cvsurl%">CVS</a>)
+ENDIF:cvsurl
+END:infiles
+ </td>
+ </tr>
+IF:parent
+ <tr>
+ <td>Parent:</td>
+ <td>
+IF:par_url
+ <a href="%par_url%">
+ENDIF:par_url
+%parent%
+IF:par_url
+ </a>
+ENDIF:par_url
+ </td>
+ </tr>
+ENDIF:parent
+ </table>
+ </td>
+ </tr>
+ </table>
+HTML
+
+###################################################################
+
+METHOD_LIST = <<HTML
+ <div id="content">
+IF:diagram
+ <table cellpadding='0' cellspacing='0' border='0' width="100%"><tr><td align="center">
+ %diagram%
+ </td></tr></table>
+ENDIF:diagram
+
+IF:description
+ <div class="description">%description%</div>
+ENDIF:description
+
+IF:requires
+ <div class="sectiontitle">Required Files</div>
+ <ul>
+START:requires
+ <li>HREF:aref:name:</li>
+END:requires
+ </ul>
+ENDIF:requires
+
+IF:toc
+ <div class="sectiontitle">Contents</div>
+ <ul>
+START:toc
+ <li><a href="#%href%">%secname%</a></li>
+END:toc
+ </ul>
+ENDIF:toc
+
+IF:methods
+ <div class="sectiontitle">Methods</div>
+ <ul>
+START:methods
+ <li>HREF:aref:name:</li>
+END:methods
+ </ul>
+ENDIF:methods
+
+IF:includes
+<div class="sectiontitle">Included Modules</div>
+<ul>
+START:includes
+ <li>HREF:aref:name:</li>
+END:includes
+</ul>
+ENDIF:includes
+
+START:sections
+IF:sectitle
+<div class="sectiontitle"><a nem="%secsequence%">%sectitle%</a></div>
+IF:seccomment
+<div class="description">
+%seccomment%
+</div>
+ENDIF:seccomment
+ENDIF:sectitle
+
+IF:classlist
+ <div class="sectiontitle">Classes and Modules</div>
+ %classlist%
+ENDIF:classlist
+
+IF:constants
+ <div class="sectiontitle">Constants</div>
+ <table border='0' cellpadding='5'>
+START:constants
+ <tr valign='top'>
+ <td class="attr-name">%name%</td>
+ <td>=</td>
+ <td class="attr-value">%value%</td>
+ </tr>
+IF:desc
+ <tr valign='top'>
+ <td> </td>
+ <td colspan="2" class="attr-desc">%desc%</td>
+ </tr>
+ENDIF:desc
+END:constants
+ </table>
+ENDIF:constants
+
+IF:attributes
+ <div class="sectiontitle">Attributes</div>
+ <table border='0' cellpadding='5'>
+START:attributes
+ <tr valign='top'>
+ <td class='attr-rw'>
+IF:rw
+[%rw%]
+ENDIF:rw
+ </td>
+ <td class='attr-name'>%name%</td>
+ <td class='attr-desc'>%a_desc%</td>
+ </tr>
+END:attributes
+ </table>
+ENDIF:attributes
+
+IF:method_list
+START:method_list
+IF:methods
+<div class="sectiontitle">%type% %category% methods</div>
+START:methods
+<div class="method">
+ <div class="title">
+IF:callseq
+ <a name="%aref%"></a><b>%callseq%</b>
+ENDIF:callseq
+IFNOT:callseq
+ <a name="%aref%"></a><b>%name%</b>%params%
+ENDIF:callseq
+IF:codeurl
+[ <a href="javascript:openCode('%codeurl%')">source</a> ]
+ENDIF:codeurl
+ </div>
+IF:m_desc
+ <div class="description">
+ %m_desc%
+ </div>
+ENDIF:m_desc
+IF:aka
+<div class="aka">
+ This method is also aliased as
+START:aka
+ <a href="%aref%">%name%</a>
+END:aka
+</div>
+ENDIF:aka
+IF:sourcecode
+<div class="sourcecode">
+ <p class="source-link">[ <a href="javascript:toggleSource('%aref%_source')" id="l_%aref%_source">show source</a> ]</p>
+ <div id="%aref%_source" class="dyn-source">
+<pre>
+%sourcecode%
+</pre>
+ </div>
+</div>
+ENDIF:sourcecode
+</div>
+END:methods
+ENDIF:methods
+END:method_list
+ENDIF:method_list
+END:sections
+</div>
+HTML
+
+FOOTER = <<ENDFOOTER
+ </body>
+</html>
+ENDFOOTER
+
+BODY = HEADER + <<ENDBODY
+ !INCLUDE! <!-- banner header -->
+
+ <div id="bodyContent">
+ #{METHOD_LIST}
+ </div>
+
+ #{FOOTER}
+ENDBODY
+
+########################## Source code ##########################
+
+SRC_PAGE = XHTML_PREAMBLE + <<HTML
+<html>
+<head><title>%title%</title>
+<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
+<style>
+.ruby-comment { color: green; font-style: italic }
+.ruby-constant { color: #4433aa; font-weight: bold; }
+.ruby-identifier { color: #222222; }
+.ruby-ivar { color: #2233dd; }
+.ruby-keyword { color: #3333FF; font-weight: bold }
+.ruby-node { color: #777777; }
+.ruby-operator { color: #111111; }
+.ruby-regexp { color: #662222; }
+.ruby-value { color: #662222; font-style: italic }
+ .kw { color: #3333FF; font-weight: bold }
+ .cmt { color: green; font-style: italic }
+ .str { color: #662222; font-style: italic }
+ .re { color: #662222; }
+</style>
+</head>
+<body bgcolor="white">
+<pre>%code%</pre>
+</body>
+</html>
+HTML
+
+########################## Index ################################
+
+FR_INDEX_BODY = <<HTML
+!INCLUDE!
+HTML
+
+FILE_INDEX = XHTML_PREAMBLE + <<HTML
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=%charset%">
+<style>
+<!--
+ body {
+ background-color: #EEE;
+ font-family: #{FONTS};
+ color: #000;
+ margin: 0px;
+ }
+ .banner {
+ background: #005;
+ color: #FFF;
+ padding: 0.2em;
+ font-size: small;
+ font-weight: bold;
+ text-align: center;
+ }
+ .entries {
+ margin: 0.25em 1em 0 1em;
+ font-size: x-small;
+ }
+ a {
+ color: #00F;
+ text-decoration: none;
+ white-space: nowrap;
+ }
+ a:hover {
+ color: #77F;
+ text-decoration: underline;
+ }
+-->
+</style>
+<base target="docwin">
+</head>
+<body>
+<div class="banner">%list_title%</div>
+<div class="entries">
+START:entries
+<a href="%href%">%name%</a><br>
+END:entries
+</div>
+</body></html>
+HTML
+
+CLASS_INDEX = FILE_INDEX
+METHOD_INDEX = FILE_INDEX
+
+INDEX = XHTML_PREAMBLE + <<HTML
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>%title%</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=%charset%">
+</head>
+
+<frameset cols="20%,*">
+ <frameset rows="15%,35%,50%">
+ <frame src="fr_file_index.html" title="Files" name="Files" />
+ <frame src="fr_class_index.html" name="Classes" />
+ <frame src="fr_method_index.html" name="Methods" />
+ </frameset>
+IF:inline_source
+ <frame src="%initial_page%" name="docwin">
+ENDIF:inline_source
+IFNOT:inline_source
+ <frameset rows="80%,20%">
+ <frame src="%initial_page%" name="docwin">
+ <frame src="blank.html" name="source">
+ </frameset>
+ENDIF:inline_source
+ <noframes>
+ <body bgcolor="white">
+ Click <a href="html/index.html">here</a> for a non-frames
+ version of this page.
+ </body>
+ </noframes>
+</frameset>
+
+</html>
+HTML
+
+end
+end
+
+
Index: builder-2.1.2/.gitignore
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/.gitignore 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,2 @@
+html
+.DS_Store
Index: builder-2.1.2/lib/blankslate.rb
===================================================================
--- builder-2.1.2.orig/lib/blankslate.rb 2007-05-31 19:19:47.000000000 +0200
+++ builder-2.1.2/lib/blankslate.rb 2010-03-21 16:37:51.000000000 +0100
@@ -36,13 +36,9 @@
# Redefine a previously hidden method so that it may be called on a blank
# slate object.
def reveal(name)
- bound_method = nil
- unbound_method = find_hidden_method(name)
- fail "Don't know how to reveal method '#{name}'" unless unbound_method
- define_method(name) do |*args|
- bound_method ||= unbound_method.bind(self)
- bound_method.call(*args)
- end
+ hidden_method = find_hidden_method(name)
+ fail "Don't know how to reveal method '#{name}'" unless hidden_method
+ define_method(name, hidden_method)
end
end
Index: builder-2.1.2/lib/builder/css.rb
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/lib/builder/css.rb 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,250 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2004, 2005 by Jim Weirich (jim@weirichhouse.org).
+# Copyright 2005 by Scott Barron (scott@elitists.net).
+# All rights reserved.
+#
+# Permission is granted for use, copying, modification, distribution,
+# and distribution of modified versions of this work as long as the
+# above copyright notice is included.
+#
+# Much of this is taken from Jim's work in xmlbase.rb and xmlmarkup.rb.
+# Documentation has also been copied and pasted and modified to reflect
+# that we're building CSS here instead of XML. Jim is conducting the
+# orchestra here and I'm just off in the corner playing a flute.
+#++
+
+# Provide a flexible and easy to use Builder for creating Cascading
+# Style Sheets (CSS).
+
+
+require 'builder/blankslate'
+
+module Builder
+
+ # Create a Cascading Style Sheet (CSS) using Ruby.
+ #
+ # Example usage:
+ #
+ # css = Builder::CSS.new
+ #
+ # text_color = '#7F7F7F'
+ # preferred_fonts = 'Helvetica, Arial, sans_serif'
+ #
+ # css.comment! 'This is our stylesheet'
+ # css.body {
+ # background_color '#FAFAFA'
+ # font_size 'small'
+ # font_family preferred_fonts
+ # color text_color
+ # }
+ #
+ # css.id!('navbar') {
+ # width '500px'
+ # }
+ #
+ # css.class!('navitem') {
+ # color 'red'
+ # }
+ #
+ # css.a :hover {
+ # text_decoration 'underline'
+ # }
+ #
+ # css.div(:id => 'menu') {
+ # background 'green'
+ # }
+ #
+ # css.div(:class => 'foo') {
+ # background 'red'
+ # }
+ #
+ # This will yield the following stylesheet:
+ #
+ # /* This is our stylesheet */
+ # body {
+ # background_color: #FAFAFA;
+ # font_size: small;
+ # font_family: Helvetica, Arial, sans_serif;
+ # color: #7F7F7F;
+ # }
+ #
+ # #navbar {
+ # width: 500px;
+ # }
+ #
+ # .navitem {
+ # color: red;
+ # }
+ #
+ # a:hover {
+ # text_decoration: underline;
+ # }
+ #
+ # div#menu {
+ # background: green;
+ # }
+ #
+ # div.foo {
+ # background: red;
+ # }
+ #
+ class CSS < BlankSlate
+
+ # Create a CSS builder.
+ #
+ # out:: Object receiving the markup.1 +out+ must respond to
+ # <tt><<</tt>.
+ # indent:: Number of spaces used for indentation (0 implies no
+ # indentation and no line breaks).
+ #
+ def initialize(indent=2)
+ @indent = indent
+ @target = []
+ @parts = []
+ @library = {}
+ end
+
+ def +(part)
+ _join_with_op! '+'
+ self
+ end
+
+ def >>(part)
+ _join_with_op! ''
+ self
+ end
+
+ def >(part)
+ _join_with_op! '>'
+ self
+ end
+
+ def |(part)
+ _join_with_op! ','
+ self
+ end
+
+ # Return the target of the builder
+ def target!
+ @target * ''
+ end
+
+ # Create a comment string in the output.
+ def comment!(comment_text)
+ @target << "/* #{comment_text} */\n"
+ end
+
+ def id!(arg, &block)
+ _start_container('#'+arg.to_s, nil, block_given?)
+ _css_block(block) if block
+ _unify_block
+ self
+ end
+
+ def class!(arg, &block)
+ _start_container('.'+arg.to_s, nil, block_given?)
+ _css_block(block) if block
+ _unify_block
+ self
+ end
+
+ def store!(sym, &block)
+ @library[sym] = block.to_proc
+ end
+
+ def group!(*args, &block)
+ args.each do |arg|
+ if arg.is_a?(Symbol)
+ instance_eval(&@library[arg])
+ else
+ instance_eval(&arg)
+ end
+ _text ', ' unless arg == args.last
+ end
+ if block
+ _css_block(block)
+ _unify_block
+ end
+ end
+
+ def method_missing(sym, *args, &block)
+ sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol)
+ if block
+ _start_container(sym, args.first)
+ _css_block(block)
+ _unify_block
+ elsif @in_block
+ _indent
+ _css_line(sym, *args)
+ _newline
+ return self
+ else
+ _start_container(sym, args.first, false)
+ _unify_block
+ end
+ self
+ end
+
+ # "Cargo culted" from Jim who also "cargo culted" it. See xmlbase.rb.
+ def nil?
+ false
+ end
+
+ private
+ def _unify_block
+ @target << @parts * ''
+ @parts = []
+ end
+
+ def _join_with_op!(op)
+ rhs, lhs = @target.pop, @target.pop
+ @target << "#{lhs} #{op} #{rhs}"
+ end
+
+ def _text(text)
+ @parts << text
+ end
+
+ def _css_block(block)
+ _newline
+ _nested_structures(block)
+ _end_container
+ _end_block
+ end
+
+ def _end_block
+ _newline
+ _newline
+ end
+
+ def _newline
+ _text "\n"
+ end
+
+ def _indent
+ _text ' ' * @indent
+ end
+
+ def _nested_structures(block)
+ @in_block = true
+ self.instance_eval(&block)
+ @in_block = false
+ end
+
+ def _start_container(sym, atts = {}, with_bracket = true)
+ selector = sym.to_s
+ selector << ".#{atts[:class]}" if atts && atts[:class]
+ selector << '#' + "#{atts[:id]}" if atts && atts[:id]
+ @parts << "#{selector}#{with_bracket ? ' {' : ''}"
+ end
+
+ def _end_container
+ @parts << "}"
+ end
+
+ def _css_line(sym, *args)
+ _text("#{sym.to_s.gsub('_','-')}: #{args * ' '};")
+ end
+ end
+end
Index: builder-2.1.2/lib/builder/xchar.rb
===================================================================
--- builder-2.1.2.orig/lib/builder/xchar.rb 2006-12-24 20:29:01.000000000 +0100
+++ builder-2.1.2/lib/builder/xchar.rb 2010-03-21 16:37:51.000000000 +0100
@@ -10,7 +10,7 @@
module Builder
def self.check_for_name_collision(klass, method_name, defined_constant=nil)
- if klass.instance_methods.include?(method_name)
+ if klass.instance_methods.include?(method_name.to_s)
fail RuntimeError,
"Name Collision: Method '#{method_name}' is already defined in #{klass}"
end
@@ -89,11 +89,13 @@
class Fixnum
XChar = Builder::XChar if ! defined?(XChar)
- # XML escaped version of chr
- def xchr
+ # XML escaped version of chr. When <tt>escape</tt> is set to false
+ # the CP1252 fix is still applied but utf-8 characters are not
+ # converted to character entities.
+ def xchr(escape=true)
n = XChar::CP1252[self] || self
case n when *XChar::VALID
- XChar::PREDEFINED[n] or (n<128 ? n.chr : "&##{n};")
+ XChar::PREDEFINED[n] or (n<128 ? n.chr : (escape ? "&##{n};" : [n].pack('U*')))
else
'*'
end
@@ -106,9 +108,11 @@
# to_s.
#
class String
- # XML escaped version of to_s
- def to_xs
- unpack('U*').map {|n| n.xchr}.join # ASCII, UTF-8
+ # XML escaped version of to_s. When <tt>escape</tt> is set to false
+ # the CP1252 fix is still applied but utf-8 characters are not
+ # converted to character entities.
+ def to_xs(escape=true)
+ unpack('U*').map {|n| n.xchr(escape)}.join # ASCII, UTF-8
rescue
unpack('C*').map {|n| n.xchr}.join # ISO-8859-1, WIN-1252
end
Index: builder-2.1.2/lib/builder/xmlbase.rb
===================================================================
--- builder-2.1.2.orig/lib/builder/xmlbase.rb 2007-06-15 07:00:31.000000000 +0200
+++ builder-2.1.2/lib/builder/xmlbase.rb 2010-03-21 16:37:51.000000000 +0100
@@ -13,19 +13,22 @@
# Create an XML markup builder.
#
- # out:: Object receiving the markup. +out+ must respond to
- # <tt><<</tt>.
- # indent:: Number of spaces used for indentation (0 implies no
- # indentation and no line breaks).
- # initial:: Level of initial indentation.
- #
- def initialize(indent=0, initial=0)
+ # out:: Object receiving the markup. +out+ must respond to
+ # <tt><<</tt>.
+ # indent:: Number of spaces used for indentation (0 implies no
+ # indentation and no line breaks).
+ # initial:: Level of initial indentation.
+ # encoding:: When <tt>encoding</tt> and $KCODE are set to 'utf-8'
+ # characters aren't converted to character entities in
+ # the output stream.
+ def initialize(indent=0, initial=0, encoding='utf-8')
@indent = indent
@level = initial
+ @encoding = encoding.downcase
end
# Create a tag named +sym+. Other than the first argument which
- # is the tag name, the arguements are the same as the tags
+ # is the tag name, the arguments are the same as the tags
# implemented via <tt>method_missing</tt>.
def tag!(sym, *args, &block)
method_missing(sym.to_sym, *args, &block)
@@ -74,7 +77,7 @@
end
# Append text to the output target. Escape any markup. May be
- # used within the markup brakets as:
+ # used within the markup brackets as:
#
# builder.p { |b| b.br; b.text! "HI" } #=> <p><br/>HI</p>
def text!(text)
@@ -82,7 +85,7 @@
end
# Append text to the output target without escaping any markup.
- # May be used within the markup brakets as:
+ # May be used within the markup brackets as:
#
# builder.p { |x| x << "<br/>HI" } #=> <p><br/>HI</p>
#
@@ -112,7 +115,7 @@
require 'builder/xchar'
def _escape(text)
- text.to_xs
+ text.to_xs((@encoding != 'utf-8' or $KCODE != 'UTF8'))
end
def _escape_quote(text)
Index: builder-2.1.2/lib/builder/xmlmarkup.rb
===================================================================
--- builder-2.1.2.orig/lib/builder/xmlmarkup.rb 2007-02-15 22:01:48.000000000 +0100
+++ builder-2.1.2/lib/builder/xmlmarkup.rb 2010-03-21 16:37:51.000000000 +0100
@@ -23,14 +23,14 @@
# Examples will demonstrate this easier than words. In the
# following, +xm+ is an +XmlMarkup+ object.
#
- # xm.em("emphasized") # => <em>emphasized</em>
- # xm.em { xmm.b("emp & bold") } # => <em><b>emph & bold</b></em>
+ # xm.em("emphasized") # => <em>emphasized</em>
+ # xm.em { xm.b("emp & bold") } # => <em><b>emph & bold</b></em>
# xm.a("A Link", "href"=>"http://onestepback.org")
- # # => <a href="http://onestepback.org">A Link</a>
- # xm.div { br } # => <div><br/></div>
+ # # => <a href="http://onestepback.org">A Link</a>
+ # xm.div { xm.br } # => <div><br/></div>
# xm.target("name"=>"compile", "option"=>"fast")
- # # => <target option="fast" name="compile"\>
- # # NOTE: order of attributes is not specified.
+ # # => <target option="fast" name="compile"\>
+ # # NOTE: order of attributes is not specified.
#
# xm.instruct! # <?xml version="1.0" encoding="UTF-8"?>
# xm.html { # <html>
@@ -163,8 +163,9 @@
# option hash.
#
# :target=><em>target_object</em>::
- # Object receiving the markup. +out+ must respond to the
- # <tt><<</tt> operator. The default is a plain string target.
+ # Object receiving the markup. +target_object+ must respond to
+ # the <tt><<(<em>a_string</em>)</tt> operator and return
+ # itself. The default target is a plain string target.
#
# :indent=><em>indentation</em>::
# Number of spaces used for indentation. The default is no
@@ -174,7 +175,7 @@
# Amount of initial indentation (specified in levels, not
# spaces).
#
- # :escape_attrs=><b>OBSOLETE</em>::
+ # :escape_attrs=><em>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
@@ -235,18 +236,22 @@
# xml.instruct! :aaa, :bbb=>"ccc"
# #=> <?aaa bbb="ccc"?>
#
+ # Note: If the encoding is setup to "UTF-8" and the value of
+ # $KCODE is "UTF8", then builder will emit UTF-8 encoded strings
+ # rather than the entity encoding normally used.
def instruct!(directive_tag=:xml, attrs={})
_ensure_no_block block_given?
if directive_tag == :xml
a = { :version=>"1.0", :encoding=>"UTF-8" }
attrs = a.merge attrs
+ @encoding = attrs[:encoding].downcase
end
_special(
- "<?#{directive_tag}",
- "?>",
- nil,
- attrs,
- [:version, :encoding, :standalone])
+ "<?#{directive_tag}",
+ "?>",
+ nil,
+ attrs,
+ [:version, :encoding, :standalone])
end
# Insert a CDATA section into the XML markup.
Index: builder-2.1.2/Rakefile
===================================================================
--- builder-2.1.2.orig/Rakefile 2007-06-15 07:06:26.000000000 +0200
+++ builder-2.1.2/Rakefile 2010-03-21 16:37:51.000000000 +0100
@@ -21,7 +21,7 @@
CLOBBER.include('pkg')
-CURRENT_VERSION = '2.1.2'
+CURRENT_VERSION = '2.2.0'
PKG_VERSION = ENV['REL'] ? ENV['REL'] : CURRENT_VERSION
SRC_RB = FileList['lib/**/*.rb']
@@ -49,7 +49,7 @@
rd = Rake::RDocTask.new("rdoc") { |rdoc|
rdoc.rdoc_dir = 'html'
rdoc.title = "Builder for Markup"
- rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
rdoc.rdoc_files.include('lib/**/*.rb', '[A-Z]*', 'doc/**/*.rdoc')
rdoc.template = 'doc/jamis.rb'
}
@@ -99,7 +99,7 @@
s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
s.rdoc_options <<
'--title' << 'Builder -- Easy XML Building' <<
- '--main' << 'README' <<
+ '--main' << 'README.rdoc' <<
'--line-numbers'
s.author = "Jim Weirich"
@@ -130,7 +130,7 @@
s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
s.rdoc_options <<
'--title' << 'BlankSlate -- Base Class for building proxies.' <<
- '--main' << 'README' <<
+ '--main' << 'README.rdoc' <<
'--line-numbers'
s.author = "Jim Weirich"
@@ -158,6 +158,40 @@
FileList['**/*.rb'].egrep /\bDBG|\bbreakpoint\b/
end
+
+# RCov ---------------------------------------------------------------
+begin
+ require 'rcov/rcovtask'
+
+ Rcov::RcovTask.new do |t|
+ t.libs << "test"
+ t.rcov_opts = [
+ '-xRakefile', '--text-report'
+ ]
+ t.test_files = FileList[
+ 'test/test*.rb'
+ ]
+ t.output_dir = 'coverage'
+ t.verbose = true
+ end
+rescue LoadError
+ # No rcov available
+end
+
+# Tags file ----------------------------------------------------------
+
+namespace "tags" do
+ desc "Create a TAGS file"
+ task :emacs => "TAGS"
+
+ TAGS = 'xctags -e'
+
+ file "TAGS" => SRC_RB do
+ puts "Makings TAGS"
+ sh "#{TAGS} #{SRC_RB}", :verbose => false
+ end
+end
+
# --------------------------------------------------------------------
# Creating a release
@@ -235,7 +269,7 @@
if ENV['RELTEST']
announce "Release Task Testing, skipping commiting of new version"
else
- sh %{cvs commit -m "Updated to version #{PKG_VERSION}" Rakefile}
+ sh "cvs commit -m \"Updated to version #{PKG_VERSION}\" Rakefile"
end
end
end
@@ -259,5 +293,3 @@
fail "Unabled to write to #{dest_dir}" unless File.writable?(dest_dir)
install "doc/jamis.rb", dest_dir, :verbose => true
end
-
-require 'scripts/publish'
Index: builder-2.1.2/rakelib/publish.rake
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/rakelib/publish.rake 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,17 @@
+# Optional publish task for Rake
+
+require 'rake/contrib/sshpublisher'
+require 'rake/contrib/rubyforgepublisher'
+
+publisher = Rake::CompositePublisher.new
+publisher.add Rake::RubyForgePublisher.new('builder', 'jimweirich')
+publisher.add Rake::SshFilePublisher.new(
+ 'linode',
+ 'htdocs/software/builder',
+ '.',
+ 'builder.blurb')
+
+desc "Publish the Documentation to RubyForge."
+task :publish => [:rdoc] do
+ publisher.upload
+end
Index: builder-2.1.2/README
===================================================================
--- builder-2.1.2.orig/README 2006-12-24 20:29:01.000000000 +0100
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
@@ -1,210 +0,0 @@
-= Project: Builder
-
-== Goal
-
-Provide a simple way to create XML markup and data structures.
-
-== Classes
-
-Builder::XmlMarkup:: Generate XML markup notiation
-Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
-
-<b>Notes</b>::
-
-* An <tt>Builder::XmlTree</tt> class to generate XML tree
- (i.e. DOM-like) structures is also planned, but not yet implemented.
- Also, the events builder is currently lagging the markup builder in
- features.
-
-== Usage
-
- require 'rubygems'
- require_gem 'builder', '~> 2.0'
-
- builder = Builder::XmlMarkup.new
- xml = builder.person { |b| b.name("Jim"); b.phone("555-1234") }
- xml #=> <person><name>Jim</name><phone>555-1234</phone></person>
-
-or
-
- require 'rubygems'
- require_gem 'builder'
-
- builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
- builder.person { |b| b.name("Jim"); b.phone("555-1234") }
- #
- # Prints:
- # <person>
- # <name>Jim</name>
- # <phone>555-1234</phone>
- # </person>
-
-== Compatibility
-
-=== Version 2.0.0 Compatibility Changes
-
-Version 2.0.0 introduces automatically escaped attribute values for
-the first time. Versions prior to 2.0.0 did not insert escape
-characters into attribute values in the XML markup. This allowed
-attribute values to explicitly reference entities, which was
-occasionally used by a small number of developers. Since strings
-could always be explicitly escaped by hand, this was not a major
-restriction in functionality.
-
-However, it did suprise most users of builder. Since the body text is
-normally escaped, everybody expected the attribute values to be
-escaped as well. Escaped attribute values were the number one support
-request on the 1.x Builder series.
-
-Starting with Builder version 2.0.0, all attribute values expressed as
-strings will be processed and the appropriate characters will be
-escaped (e.g. "&" will be tranlated to "&"). Attribute values
-that are expressed as Symbol values will not be processed for escaped
-characters and will be unchanged in output. (Yes, this probably counts
-as Symbol abuse, but the convention is convenient and flexible).
-
-Example:
-
- xml = Builder::XmlMarkup.new
- xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There")
- xml.target! =>
- <sample escaped="This&That" unescaped="Here&There"/>
-
-=== Version 1.0.0 Compatibility Changes
-
-Version 1.0.0 introduces some changes that are not backwards
-compatible with earlier releases of builder. The main areas of
-incompatibility are:
-
-* Keyword based arguments to +new+ (rather than positional based). It
- was found that a developer would often like to specify indentation
- without providing an explicit target, or specify a target without
- indentation. Keyword based arguments handle this situation nicely.
-
-* Builder must now be an explicit target for markup tags. Instead of
- writing
-
- xml_markup = Builder::XmlMarkup.new
- xml_markup.div { strong("text") }
-
- you need to write
-
- xml_markup = Builder::XmlMarkup.new
- xml_markup.div { xml_markup.strong("text") }
-
-* The builder object is passed as a parameter to all nested markup
- blocks. This allows you to create a short alias for the builder
- object that can be used within the block. For example, the previous
- example can be written as:
-
- xml_markup = Builder::XmlMarkup.new
- xml_markup.div { |xml| xml.strong("text") }
-
-* If you have both a pre-1.0 and a post-1.0 gem of builder installed,
- you can choose which version to use through the RubyGems
- +require_gem+ facility.
-
- require_gem 'builder', "~> 0.0" # Gets the old version
- require_gem 'builder', "~> 1.0" # Gets the new version
-
-== Features
-
-* XML Comments are supported ...
-
- xml_markup.comment! "This is a comment"
- #=> <!-- This is a comment -->
-
-* XML processing instructions are supported ...
-
- xml_markup.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
- #=> <?xml version="1.0" encoding="UTF-8"?>
-
- If the processing instruction is omitted, it defaults to "xml".
- When the processing instruction is "xml", the defaults attributes
- are:
-
- <b>version</b>:: 1.0
- <b>encoding</b>:: "UTF-8"
-
-* XML entity declarations are now supported to a small degree.
-
- xml_markup.declare! :DOCTYPE, :chapter, :SYSTEM, "../dtds/chapter.dtd"
- #=> <!DOCTYPE chapter SYSTEM "../dtds/chapter.dtd">
-
- The parameters to a declare! method must be either symbols or
- strings. Symbols are inserted without quotes, and strings are
- inserted with double quotes. Attribute-like arguments in hashes are
- not allowed.
-
- If you need to have an argument to declare! be inserted without
- quotes, but the arguement does not conform to the typical Ruby
- syntax for symbols, then use the :"string" form to specify a symbol.
-
- For example:
-
- xml_markup.declare! :ELEMENT, :chapter, :"(title,para+)"
- #=> <!ELEMENT chapter (title,para+)>
-
- Nested entity declarations are allowed. For example:
-
- @xml_markup.declare! :DOCTYPE, :chapter do |x|
- x.declare! :ELEMENT, :chapter, :"(title,para+)"
- x.declare! :ELEMENT, :title, :"(#PCDATA)"
- x.declare! :ELEMENT, :para, :"(#PCDATA)"
- end
-
- #=>
-
- <!DOCTYPE chapter [
- <!ELEMENT chapter (title,para+)>
- <!ELEMENT title (#PCDATA)>
- <!ELEMENT para (#PCDATA)>
- ]>
-
-* Some support for XML namespaces is now available. If the first
- argument to a tag call is a symbol, it will be joined to the tag to
- produce a namespace:tag combination. It is easier to show this than
- describe it.
-
- xml.SOAP :Envelope do ... end
-
- Just put a space before the colon in a namespace to produce the
- right form for builder (e.g. "<tt>SOAP:Envelope</tt>" =>
- "<tt>xml.SOAP :Envelope</tt>")
-
-* String attribute values are <em>now</em> escaped by default by
- Builder (<b>NOTE:</b> this is _new_ behavior as of version 2.0).
-
- However, occasionally you need to use entities in attribute values.
- Using a symbols (rather than a string) for an attribute value will
- cause Builder to not run its quoting/escaping algorithm on that
- particular value.
-
- (<b>Note:</b> The +escape_attrs+ option for builder is now
- obsolete).
-
- Example:
-
- xml = Builder::XmlMarkup.new
- xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There")
- xml.target! =>
- <sample escaped="This&That" unescaped="Here&There"/>
-
-* UTF-8 Support
-
- Builder correctly translates UTF-8 characters into valid XML. (New
- in version 2.0.0). Thanks to Sam Ruby for the translation code.
-
- Example:
-
- xml = Builder::Markup.new
- xml.sample("Iñtërnâtiônà l")
- xml.target! =>
- "<sample>Iñtërnâtiônàl</sample>"
-
-== Contact
-
-Author:: Jim Weirich
-Email:: jim@weirichhouse.org
-Home Page:: http://onestepback.org
-License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
Index: builder-2.1.2/README.rdoc
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/README.rdoc 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,232 @@
+= Project: Builder
+
+== Goal
+
+Provide a simple way to create XML markup and data structures.
+
+== Classes
+
+Builder::XmlMarkup:: Generate XML markup notiation
+Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
+
+<b>Notes</b>::
+
+* An <tt>Builder::XmlTree</tt> class to generate XML tree
+ (i.e. DOM-like) structures is also planned, but not yet implemented.
+ Also, the events builder is currently lagging the markup builder in
+ features.
+
+== Usage
+
+ require 'rubygems'
+ require_gem 'builder', '~> 2.0'
+
+ builder = Builder::XmlMarkup.new
+ xml = builder.person { |b| b.name("Jim"); b.phone("555-1234") }
+ xml #=> <person><name>Jim</name><phone>555-1234</phone></person>
+
+or
+
+ require 'rubygems'
+ require_gem 'builder'
+
+ builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
+ builder.person { |b| b.name("Jim"); b.phone("555-1234") }
+ #
+ # Prints:
+ # <person>
+ # <name>Jim</name>
+ # <phone>555-1234</phone>
+ # </person>
+
+== Compatibility
+
+=== Version 2.0.0 Compatibility Changes
+
+Version 2.0.0 introduces automatically escaped attribute values for
+the first time. Versions prior to 2.0.0 did not insert escape
+characters into attribute values in the XML markup. This allowed
+attribute values to explicitly reference entities, which was
+occasionally used by a small number of developers. Since strings
+could always be explicitly escaped by hand, this was not a major
+restriction in functionality.
+
+However, it did suprise most users of builder. Since the body text is
+normally escaped, everybody expected the attribute values to be
+escaped as well. Escaped attribute values were the number one support
+request on the 1.x Builder series.
+
+Starting with Builder version 2.0.0, all attribute values expressed as
+strings will be processed and the appropriate characters will be
+escaped (e.g. "&" will be tranlated to "&"). Attribute values
+that are expressed as Symbol values will not be processed for escaped
+characters and will be unchanged in output. (Yes, this probably counts
+as Symbol abuse, but the convention is convenient and flexible).
+
+Example:
+
+ xml = Builder::XmlMarkup.new
+ xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There")
+ xml.target! =>
+ <sample escaped="This&That" unescaped="Here&There"/>
+
+=== Version 1.0.0 Compatibility Changes
+
+Version 1.0.0 introduces some changes that are not backwards
+compatible with earlier releases of builder. The main areas of
+incompatibility are:
+
+* Keyword based arguments to +new+ (rather than positional based). It
+ was found that a developer would often like to specify indentation
+ without providing an explicit target, or specify a target without
+ indentation. Keyword based arguments handle this situation nicely.
+
+* Builder must now be an explicit target for markup tags. Instead of
+ writing
+
+ xml_markup = Builder::XmlMarkup.new
+ xml_markup.div { strong("text") }
+
+ you need to write
+
+ xml_markup = Builder::XmlMarkup.new
+ xml_markup.div { xml_markup.strong("text") }
+
+* The builder object is passed as a parameter to all nested markup
+ blocks. This allows you to create a short alias for the builder
+ object that can be used within the block. For example, the previous
+ example can be written as:
+
+ xml_markup = Builder::XmlMarkup.new
+ xml_markup.div { |xml| xml.strong("text") }
+
+* If you have both a pre-1.0 and a post-1.0 gem of builder installed,
+ you can choose which version to use through the RubyGems
+ +require_gem+ facility.
+
+ require_gem 'builder', "~> 0.0" # Gets the old version
+ require_gem 'builder', "~> 1.0" # Gets the new version
+
+== Features
+
+* XML Comments are supported ...
+
+ xml_markup.comment! "This is a comment"
+ #=> <!-- This is a comment -->
+
+* XML processing instructions are supported ...
+
+ xml_markup.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
+ #=> <?xml version="1.0" encoding="UTF-8"?>
+
+ If the processing instruction is omitted, it defaults to "xml".
+ When the processing instruction is "xml", the defaults attributes
+ are:
+
+ <b>version</b>:: 1.0
+ <b>encoding</b>:: "UTF-8"
+
+ (NOTE: if the encoding is set to "UTF-8" and $KCODE is set to
+ "UTF8", then Builder will emit UTF-8 encoded strings rather than
+ encoding non-ASCII characters as entities.)
+
+* XML entity declarations are now supported to a small degree.
+
+ xml_markup.declare! :DOCTYPE, :chapter, :SYSTEM, "../dtds/chapter.dtd"
+ #=> <!DOCTYPE chapter SYSTEM "../dtds/chapter.dtd">
+
+ The parameters to a declare! method must be either symbols or
+ strings. Symbols are inserted without quotes, and strings are
+ inserted with double quotes. Attribute-like arguments in hashes are
+ not allowed.
+
+ If you need to have an argument to declare! be inserted without
+ quotes, but the arguement does not conform to the typical Ruby
+ syntax for symbols, then use the :"string" form to specify a symbol.
+
+ For example:
+
+ xml_markup.declare! :ELEMENT, :chapter, :"(title,para+)"
+ #=> <!ELEMENT chapter (title,para+)>
+
+ Nested entity declarations are allowed. For example:
+
+ @xml_markup.declare! :DOCTYPE, :chapter do |x|
+ x.declare! :ELEMENT, :chapter, :"(title,para+)"
+ x.declare! :ELEMENT, :title, :"(#PCDATA)"
+ x.declare! :ELEMENT, :para, :"(#PCDATA)"
+ end
+
+ #=>
+
+ <!DOCTYPE chapter [
+ <!ELEMENT chapter (title,para+)>
+ <!ELEMENT title (#PCDATA)>
+ <!ELEMENT para (#PCDATA)>
+ ]>
+
+* Some support for XML namespaces is now available. If the first
+ argument to a tag call is a symbol, it will be joined to the tag to
+ produce a namespace:tag combination. It is easier to show this than
+ describe it.
+
+ xml.SOAP :Envelope do ... end
+
+ Just put a space before the colon in a namespace to produce the
+ right form for builder (e.g. "<tt>SOAP:Envelope</tt>" =>
+ "<tt>xml.SOAP :Envelope</tt>")
+
+* String attribute values are <em>now</em> escaped by default by
+ Builder (<b>NOTE:</b> this is _new_ behavior as of version 2.0).
+
+ However, occasionally you need to use entities in attribute values.
+ Using a symbols (rather than a string) for an attribute value will
+ cause Builder to not run its quoting/escaping algorithm on that
+ particular value.
+
+ (<b>Note:</b> The +escape_attrs+ option for builder is now
+ obsolete).
+
+ Example:
+
+ xml = Builder::XmlMarkup.new
+ xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There")
+ xml.target! =>
+ <sample escaped="This&That" unescaped="Here&There"/>
+
+* UTF-8 Support
+
+ Builder correctly translates UTF-8 characters into valid XML. (New
+ in version 2.0.0). Thanks to Sam Ruby for the translation code.
+
+ Example:
+
+ xml = Builder::Markup.new
+ xml.sample("Iñtërnâtiônà l")
+ xml.target! =>
+ "<sample>Iñtërnâtiônàl</sample>"
+
+ You can get UTF-8 encoded output by making sure that the XML
+ encoding is set to "UTF-8" and that the $KCODE variable is set to
+ "UTF8".
+
+ $KCODE = 'UTF8'
+ xml = Builder::Markup.new
+ xml.instruct!(:xml, :encoding => "UTF-8")
+ xml.sample("Iñtërnâtiônà l")
+ xml.target! =>
+ "<sample>Iñtërnâtiônà l</sample>"
+
+== Links
+
+Documents:: http://builder.rubyforge.org/
+Github Clone:: git://github.com/jimweirich/builder.git
+Issue Tracking:: http://www.pivotaltracker.com/projects/29210
+Bug Reports:: http://onestepback.org/cgi-bin/bugs.cgi?project=builder
+
+== Contact
+
+Author:: Jim Weirich
+Email:: jim@weirichhouse.org
+Home Page:: http://onestepback.org
+License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
Index: builder-2.1.2/scripts/publish.rb
===================================================================
--- builder-2.1.2.orig/scripts/publish.rb 2006-12-24 20:29:01.000000000 +0100
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
@@ -1,17 +0,0 @@
-# Optional publish task for Rake
-
-require 'rake/contrib/sshpublisher'
-require 'rake/contrib/rubyforgepublisher'
-
-publisher = Rake::CompositePublisher.new
-publisher.add Rake::RubyForgePublisher.new('builder', 'jimweirich')
-publisher.add Rake::SshFilePublisher.new(
- 'umlcoop',
- 'htdocs/software/builder',
- '.',
- 'builder.blurb')
-
-desc "Publish the Documentation to RubyForge."
-task :publish => [:rdoc] do
- publisher.upload
-end
Index: builder-2.1.2/TAGS
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/TAGS 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,96 @@
+
+lib/blankslate.rb,455
+class BlankSlateBlankSlate17,621
+ def hide(name)hide22,788
+ def find_hidden_method(name)find_hidden_method31,1032
+ def reveal(name)reveal38,1268
+module KernelKernel55,1902
+ def method_added(name)method_added61,2078
+class ObjectObject73,2357
+ def method_added(name)method_added79,2532
+ def find_hidden_method(name)find_hidden_method86,2693
+class ModuleModule99,3124
+ def append_features(mod)append_features101,3197
+
+lib/builder/blankslate.rb,30
+module BuilderBuilder18,555
+
+lib/builder/css.rb,1102
+module BuilderBuilder23,757
+ class CSS < BlankSlateCSS92,2139
+ def initialize(indent=2)initialize101,2424
+ def +(part)+108,2562
+ def >>(part)>>113,2623
+ def >(part)>118,2684
+ def |(part)|123,2745
+ def target!target!129,2845
+ def comment!(comment_text)comment!134,2934
+ def id!(arg, &block)id!138,3017
+ def class!(arg, &block)class!145,3170
+ def store!(sym, &block)store!152,3326
+ def group!(*args, &block)group!156,3399
+ def method_missing(sym, *args, &block)method_missing171,3712
+ def nil?nil?190,4216
+ def _unify_block_unify_block195,4262
+ def _join_with_op!(op)_join_with_op!200,4343
+ def _text(text)_text205,4464
+ def _css_block(block)_css_block209,4514
+ def _end_block_end_block216,4634
+ def _newline_newline221,4696
+ def _indent_indent225,4743
+ def _nested_structures(block)_nested_structures229,4794
+ def _start_container(sym, atts = {}, with_bracket = true)_start_container235,4917
+ def _end_container_end_container242,5192
+ def _css_line(sym, *args)_css_line246,5244
+
+lib/builder/xchar.rb,342
+module BuilderBuilder11,321
+ def self.check_for_name_collision(klass, method_name, defined_constant=nil)check_for_name_collision12,336
+module BuilderBuilder26,798
+ module XChar # :nodoc:XChar32,997
+class FixnumFixnum89,2948
+ def xchr(escape=true)xchr95,3179
+class StringString110,3542
+ def to_xs(escape=true)to_xs114,3727
+
+lib/builder/xmlbase.rb,639
+module BuilderBuilder5,51
+ class IllegalBlockError < RuntimeError; endIllegalBlockError8,97
+ class XmlBase < BlankSlateXmlBase12,264
+ def initialize(indent=0, initial=0, encoding='utf-8')initialize24,777
+ def tag!(sym, *args, &block)tag!33,1109
+ def method_missing(sym, *args, &block)method_missing40,1366
+ def text!(text)text!83,2417
+ def <<(text)<<100,3077
+ def nil?nil?110,3508
+ def _escape(text)_escape117,3587
+ def _escape_quote(text)_escape_quote121,3679
+ def _newline_newline125,3768
+ def _indent_indent130,3844
+ def _nested_structures(block)_nested_structures135,3955
+
+lib/builder/xmlevents.rb,216
+module BuilderBuilder14,315
+ class XmlEvents < XmlMarkupXmlEvents48,1598
+ def text!(text)text!49,1628
+ def _start_tag(sym, attrs, end_too=false)_start_tag53,1682
+ def _end_tag(sym)_end_tag58,1804
+
+lib/builder/xmlmarkup.rb,776
+module BuilderBuilder16,425
+ class XmlMarkup < XmlBaseXmlMarkup160,5942
+ def initialize(options={})initialize186,7059
+ def target!target!194,7284
+ def comment!(comment_text)comment!198,7323
+ def declare!(inst, *args, &block)declare!209,7619
+ def instruct!(directive_tag=:xml, attrs={})instruct!242,8497
+ def cdata!(text)cdata!264,9081
+ def _text(text)_text275,9405
+ def _special(open, close, data=nil, attrs=nil, order=[])_special280,9495
+ def _start_tag(sym, attrs, end_too=false)_start_tag291,9829
+ def _end_tag(sym)_end_tag299,10028
+ def _insert_attributes(attrs, order=[])_insert_attributes304,10137
+ def _attr_value(value)_attr_value315,10452
+ def _ensure_no_block(got_block)_ensure_no_block324,10597
+
+lib/builder.rb,0
Index: builder-2.1.2/test/performance.rb
===================================================================
--- builder-2.1.2.orig/test/performance.rb 2006-12-24 20:29:01.000000000 +0100
+++ builder-2.1.2/test/performance.rb 2010-03-21 16:37:51.000000000 +0100
@@ -1,5 +1,15 @@
#!/usr/bin/env ruby
+#--
+# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
+# Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
+# All rights reserved.
+
+# Permission is granted for use, copying, modification, distribution,
+# and distribution of modified versions of this work as long as the
+# above copyright notice is included.
+#++
+
require 'builder/xmlmarkup'
require 'benchmark'
Index: builder-2.1.2/test/preload.rb
===================================================================
--- builder-2.1.2.orig/test/preload.rb 2006-12-24 20:29:01.000000000 +0100
+++ builder-2.1.2/test/preload.rb 2010-03-21 16:37:51.000000000 +0100
@@ -1,5 +1,15 @@
#!/usr/bin/env ruby
+#--
+# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
+# Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
+# All rights reserved.
+
+# Permission is granted for use, copying, modification, distribution,
+# and distribution of modified versions of this work as long as the
+# above copyright notice is included.
+#++
+
# We are defining method_added in Kernel and Object so that when
# BlankSlate overrides them later, we can verify that it correctly
# calls the older hooks.
Index: builder-2.1.2/test/test_blankslate.rb
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/test/test_blankslate.rb 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,218 @@
+#!/usr/bin/env ruby
+
+#--
+# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
+# Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
+# All rights reserved.
+
+# Permission is granted for use, copying, modification, distribution,
+# and distribution of modified versions of this work as long as the
+# above copyright notice is included.
+#++
+
+require 'test/unit'
+require 'test/preload'
+require 'builder/blankslate'
+require 'stringio'
+
+# Methods to be introduced into the Object class late.
+module LateObject
+ def late_object
+ 33
+ end
+ def LateObject.included(mod)
+ # Modules defining an included method should not prevent blank
+ # slate erasure!
+ end
+end
+
+# Methods to be introduced into the Kernel module late.
+module LateKernel
+ def late_kernel
+ 44
+ end
+ def LateKernel.included(mod)
+ # Modules defining an included method should not prevent blank
+ # slate erasure!
+ end
+end
+
+# Introduce some late methods (both module and direct) into the Kernel
+# module.
+module Kernel
+ include LateKernel
+
+ def late_addition
+ 1234
+ end
+
+ def double_late_addition
+ 11
+ end
+
+ def double_late_addition
+ 22
+ end
+end
+
+
+# Introduce some late methods (both module and direct) into the Object
+# class.
+class Object
+ include LateObject
+ def another_late_addition
+ 4321
+ end
+end
+
+# Introduce some late methods by inclusion.
+module GlobalModule
+ def global_inclusion
+ 42
+ end
+end
+include GlobalModule
+
+def direct_global
+ 43
+end
+
+######################################################################
+# Test case for blank slate.
+#
+class TestBlankSlate < Test::Unit::TestCase
+ def setup
+ @bs = BlankSlate.new
+ end
+
+ def test_undefined_methods_remain_undefined
+ assert_raise(NoMethodError) { @bs.no_such_method }
+ assert_raise(NoMethodError) { @bs.nil? }
+ end
+
+
+ # NOTE: NameError is acceptable because the lack of a '.' means that
+ # Ruby can't tell if it is a method or a local variable.
+ def test_undefined_methods_remain_undefined_during_instance_eval
+ assert_raise(NoMethodError, NameError) do
+ @bs.instance_eval do nil? end
+ end
+ assert_raise(NoMethodError, NameError) do
+ @bs.instance_eval do no_such_method end
+ end
+ end
+
+ def test_private_methods_are_undefined
+ assert_raise(NoMethodError) do
+ @bs.puts "HI"
+ end
+ end
+
+ def test_targetted_private_methods_are_undefined_during_instance_eval
+ assert_raise(NoMethodError, NameError) do
+ @bs.instance_eval do self.puts "HI" end
+ end
+ end
+
+ def test_untargetted_private_methods_are_defined_during_instance_eval
+ oldstdout = $stdout
+ $stdout = StringIO.new
+ @bs.instance_eval do
+ puts "HI"
+ end
+ ensure
+ $stdout = oldstdout
+ end
+
+ def test_methods_added_late_to_kernel_remain_undefined
+ assert_equal 1234, nil.late_addition
+ assert_raise(NoMethodError) { @bs.late_addition }
+ end
+
+ def test_methods_added_late_to_object_remain_undefined
+ assert_equal 4321, nil.another_late_addition
+ assert_raise(NoMethodError) { @bs.another_late_addition }
+ end
+
+ def test_methods_added_late_to_global_remain_undefined
+ assert_equal 42, global_inclusion
+ assert_raise(NoMethodError) { @bs.global_inclusion }
+ end
+
+ def test_preload_method_added
+ assert Kernel.k_added_names.include?(:late_addition)
+ assert Object.o_added_names.include?(:another_late_addition)
+ end
+
+ def test_method_defined_late_multiple_times_remain_undefined
+ assert_equal 22, nil.double_late_addition
+ assert_raise(NoMethodError) { @bs.double_late_addition }
+ end
+
+ def test_late_included_module_in_object_is_ok
+ assert_equal 33, 1.late_object
+ assert_raise(NoMethodError) { @bs.late_object }
+ end
+
+ def test_late_included_module_in_kernel_is_ok
+ assert_raise(NoMethodError) { @bs.late_kernel }
+ end
+
+ def test_revealing_previously_hidden_methods_are_callable
+ with_to_s = Class.new(BlankSlate) do
+ reveal :to_s
+ end
+ assert_match /^#<.*>$/, with_to_s.new.to_s
+ end
+
+ def test_revealing_previously_hidden_methods_are_callable_with_block
+ Object.class_eval <<-EOS
+ def given_block(&block)
+ block
+ end
+ EOS
+
+ with_given_block = Class.new(BlankSlate) do
+ reveal :given_block
+ end
+ assert_not_nil with_given_block.new.given_block {}
+ end
+
+ def test_revealing_a_hidden_method_twice_is_ok
+ with_to_s = Class.new(BlankSlate) do
+ reveal :to_s
+ reveal :to_s
+ end
+ assert_match /^#<.*>$/, with_to_s.new.to_s
+ end
+
+ def test_revealing_unknown_hidden_method_is_an_error
+ assert_raises(RuntimeError) do
+ Class.new(BlankSlate) do
+ reveal :xyz
+ end
+ end
+ end
+
+ def test_global_includes_still_work
+ assert_nothing_raised do
+ assert_equal 42, global_inclusion
+ assert_equal 42, Object.new.global_inclusion
+ assert_equal 42, "magic number".global_inclusion
+ assert_equal 43, direct_global
+ end
+ end
+
+ def test_reveal_should_not_bind_to_an_instance
+ with_object_id = Class.new(BlankSlate) do
+ reveal(:object_id)
+ end
+
+ obj1 = with_object_id.new
+ obj2 = with_object_id.new
+
+ assert obj1.object_id != obj2.object_id,
+ "Revealed methods should not be bound to a particular instance"
+ end
+end
+
Index: builder-2.1.2/test/testblankslate.rb
===================================================================
--- builder-2.1.2.orig/test/testblankslate.rb 2007-05-31 19:19:46.000000000 +0200
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
@@ -1,183 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'test/unit'
-require 'test/preload'
-require 'builder/blankslate'
-require 'stringio'
-
-# Methods to be introduced into the Object class late.
-module LateObject
- def late_object
- 33
- end
- def LateObject.included(mod)
- # Modules defining an included method should not prevent blank
- # slate erasure!
- end
-end
-
-# Methods to be introduced into the Kernel module late.
-module LateKernel
- def late_kernel
- 44
- end
- def LateKernel.included(mod)
- # Modules defining an included method should not prevent blank
- # slate erasure!
- end
-end
-
-# Introduce some late methods (both module and direct) into the Kernel
-# module.
-module Kernel
- include LateKernel
-
- def late_addition
- 1234
- end
-
- def double_late_addition
- 11
- end
-
- def double_late_addition
- 22
- end
-end
-
-
-# Introduce some late methods (both module and direct) into the Object
-# class.
-class Object
- include LateObject
- def another_late_addition
- 4321
- end
-end
-
-# Introduce some late methods by inclusion.
-module GlobalModule
- def global_inclusion
- 42
- end
-end
-include GlobalModule
-
-def direct_global
- 43
-end
-
-######################################################################
-# Test case for blank slate.
-#
-class TestBlankSlate < Test::Unit::TestCase
- def setup
- @bs = BlankSlate.new
- end
-
- def test_undefined_methods_remain_undefined
- assert_raise(NoMethodError) { @bs.no_such_method }
- assert_raise(NoMethodError) { @bs.nil? }
- end
-
-
- # NOTE: NameError is acceptable because the lack of a '.' means that
- # Ruby can't tell if it is a method or a local variable.
- def test_undefined_methods_remain_undefined_during_instance_eval
- assert_raise(NoMethodError, NameError) do
- @bs.instance_eval do nil? end
- end
- assert_raise(NoMethodError, NameError) do
- @bs.instance_eval do no_such_method end
- end
- end
-
- def test_private_methods_are_undefined
- assert_raise(NoMethodError) do
- @bs.puts "HI"
- end
- end
-
- def test_targetted_private_methods_are_undefined_during_instance_eval
- assert_raise(NoMethodError, NameError) do
- @bs.instance_eval do self.puts "HI" end
- end
- end
-
- def test_untargetted_private_methods_are_defined_during_instance_eval
- oldstdout = $stdout
- $stdout = StringIO.new
- @bs.instance_eval do
- puts "HI"
- end
- ensure
- $stdout = oldstdout
- end
-
- def test_methods_added_late_to_kernel_remain_undefined
- assert_equal 1234, nil.late_addition
- assert_raise(NoMethodError) { @bs.late_addition }
- end
-
- def test_methods_added_late_to_object_remain_undefined
- assert_equal 4321, nil.another_late_addition
- assert_raise(NoMethodError) { @bs.another_late_addition }
- end
-
- def test_methods_added_late_to_global_remain_undefined
- assert_equal 42, global_inclusion
- assert_raise(NoMethodError) { @bs.global_inclusion }
- end
-
- def test_preload_method_added
- assert Kernel.k_added_names.include?(:late_addition)
- assert Object.o_added_names.include?(:another_late_addition)
- end
-
- def test_method_defined_late_multiple_times_remain_undefined
- assert_equal 22, nil.double_late_addition
- assert_raise(NoMethodError) { @bs.double_late_addition }
- end
-
- def test_late_included_module_in_object_is_ok
- assert_equal 33, 1.late_object
- assert_raise(NoMethodError) { @bs.late_object }
- end
-
- def test_late_included_module_in_kernel_is_ok
- assert_raise(NoMethodError) { @bs.late_kernel }
- end
-
- def test_revealing_previously_hidden_methods_are_callable
- with_to_s = Class.new(BlankSlate) do
- reveal :to_s
- end
- assert_match /^#<.*>$/, with_to_s.new.to_s
- end
-
- def test_revealing_a_hidden_method_twice_is_ok
- with_to_s = Class.new(BlankSlate) do
- reveal :to_s
- reveal :to_s
- end
- assert_match /^#<.*>$/, with_to_s.new.to_s
- end
-
- def test_revealing_unknown_hidden_method_is_an_error
- assert_raises(RuntimeError) do
- Class.new(BlankSlate) do
- reveal :xyz
- end
- end
- end
-
- def test_global_includes_still_work
- assert_nothing_raised do
- assert_equal 42, global_inclusion
- assert_equal 42, Object.new.global_inclusion
- assert_equal 42, "magic number".global_inclusion
- assert_equal 43, direct_global
- end
- end
-end
-
Index: builder-2.1.2/test/test_cssbuilder.rb
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/test/test_cssbuilder.rb 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,125 @@
+#!/usr/bin/env ruby
+
+#--
+# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
+# Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
+# All rights reserved.
+
+# Permission is granted for use, copying, modification, distribution,
+# and distribution of modified versions of this work as long as the
+# above copyright notice is included.
+#++
+
+require 'test/unit'
+require 'test/preload'
+require 'builder'
+require 'builder/css'
+
+class TestCSS < Test::Unit::TestCase
+ def setup
+ @css = Builder::CSS.new
+ end
+
+ def test_create
+ assert_not_nil @css
+ end
+
+ def test_no_block
+ @css.body
+ assert_equal 'body', @css.target!
+ end
+
+ def test_block
+ @css.body {
+ color 'green'
+ }
+ assert_equal "body {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_id
+ @css.id!('nav') { color 'green' }
+ assert_equal "#nav {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_class
+ @css.class!('nav') { color 'green' }
+ assert_equal ".nav {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_elem_with_id
+ @css.div(:id => 'nav') { color 'green' }
+ assert_equal "div#nav {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_elem_with_class
+ @css.div(:class => 'nav') { color 'green' }
+ assert_equal "div.nav {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_comment
+ @css.comment!('foo')
+ assert_equal "/* foo */\n", @css.target!
+ end
+
+ def test_selector
+ @css.a(:hover) { color 'green' }
+ assert_equal "a:hover {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_plus
+ @css.h1 + @css.span
+ assert_equal "h1 + span", @css.target!
+ end
+
+ def test_plus_with_block
+ @css.h1 + @css.span { color 'green' }
+ assert_equal "h1 + span {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_contextual
+ @css.h1 >> @css.span
+ assert_equal "h1 span", @css.target!
+ end
+
+ def test_contextual_with_block
+ @css.h1 >> @css.span { color 'green' }
+ assert_equal "h1 span {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_child
+ @css.h1 > @css.span
+ assert_equal "h1 > span", @css.target!
+ end
+
+ def test_child_with_block
+ @css.h1 > @css.span { color 'green' }
+ assert_equal "h1 > span {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_multiple_op
+ @css.h1 + @css.span + @css.span
+ assert_equal "h1 + span + span", @css.target!
+ end
+
+ def test_all
+ @css.h1 | @css.h2 { color 'green' }
+ assert_equal "h1 , h2 {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_all_with_atts
+ @css.h1(:class => 'foo') | @css.h2(:class => 'bar') { color 'green' }
+ assert_equal "h1.foo , h2.bar {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_multiple_basic
+ @css.body { color 'green' }
+ @css.h1 { color 'green' }
+ assert_equal "body {\n color: green;\n}\n\nh1 {\n color: green;\n}\n\n", @css.target!
+ end
+
+ def test_multiple_ops
+ @css.body { color 'green' }
+ @css.body > @css.h1 { color 'green' }
+ assert_equal "body {\n color: green;\n}\n\nbody > h1 {\n color: green;\n}\n\n", @css.target!
+ end
+end
Index: builder-2.1.2/test/test_eventbuilder.rb
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/test/test_eventbuilder.rb 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,150 @@
+#!/usr/bin/env ruby
+
+#--
+# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
+# Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
+# All rights reserved.
+
+# Permission is granted for use, copying, modification, distribution,
+# and distribution of modified versions of this work as long as the
+# above copyright notice is included.
+#++
+
+require 'test/unit'
+require 'test/preload'
+require 'builder'
+require 'builder/xmlevents'
+
+class TestEvents < Test::Unit::TestCase
+
+ class Target
+ attr_reader :events
+
+ def initialize
+ @events = []
+ end
+
+ def start_tag(tag, attrs)
+ @events << [:start_tag, tag, attrs]
+ end
+
+ def end_tag(tag)
+ @events << [:end_tag, tag]
+ end
+
+ def text(string)
+ @events << [:text, string]
+ end
+
+ end
+
+
+ def setup
+ @target = Target.new
+ @xml = Builder::XmlEvents.new(:target=>@target)
+ end
+
+ def test_simple
+ @xml.one
+ expect [:start_tag, :one, nil]
+ expect [:end_tag, :one]
+ expect_done
+ end
+
+ def test_nested
+ @xml.one { @xml.two }
+ expect [:start_tag, :one, nil]
+ expect [:start_tag, :two, nil]
+ expect [:end_tag, :two]
+ expect [:end_tag, :one]
+ expect_done
+ end
+
+ def test_text
+ @xml.one("a")
+ expect [:start_tag, :one, nil]
+ expect [:text, "a"]
+ expect [:end_tag, :one]
+ expect_done
+ end
+
+ def test_special_text
+ @xml.one("H&R")
+ expect [:start_tag, :one, nil]
+ expect [:text, "H&R"]
+ expect [:end_tag, :one]
+ expect_done
+ end
+
+ def test_text_with_entity
+ @xml.one("H&R")
+ expect [:start_tag, :one, nil]
+ expect [:text, "H&R"]
+ expect [:end_tag, :one]
+ expect_done
+ end
+
+ def test_attributes
+ @xml.a(:b=>"c", :x=>"y")
+ expect [:start_tag, :a, {:x => "y", :b => "c"}]
+ expect [:end_tag, :a]
+ expect_done
+ end
+
+ def test_moderately_complex
+ @xml.tag! "address-book" do |x|
+ x.entry :id=>"1" do
+ x.name {
+ x.first "Bill"
+ x.last "Smith"
+ }
+ x.address "Cincinnati"
+ end
+ x.entry :id=>"2" do
+ x.name {
+ x.first "John"
+ x.last "Doe"
+ }
+ x.address "Columbus"
+ end
+ end
+ expect [:start_tag, "address-book".intern, nil]
+ expect [:start_tag, :entry, {:id => "1"}]
+ expect [:start_tag, :name, nil]
+ expect [:start_tag, :first, nil]
+ expect [:text, "Bill"]
+ expect [:end_tag, :first]
+ expect [:start_tag, :last, nil]
+ expect [:text, "Smith"]
+ expect [:end_tag, :last]
+ expect [:end_tag, :name]
+ expect [:start_tag, :address, nil]
+ expect [:text, "Cincinnati"]
+ expect [:end_tag, :address]
+ expect [:end_tag, :entry]
+ expect [:start_tag, :entry, {:id => "2"}]
+ expect [:start_tag, :name, nil]
+ expect [:start_tag, :first, nil]
+ expect [:text, "John"]
+ expect [:end_tag, :first]
+ expect [:start_tag, :last, nil]
+ expect [:text, "Doe"]
+ expect [:end_tag, :last]
+ expect [:end_tag, :name]
+ expect [:start_tag, :address, nil]
+ expect [:text, "Columbus"]
+ expect [:end_tag, :address]
+ expect [:end_tag, :entry]
+ expect [:end_tag, "address-book".intern]
+ expect_done
+ end
+
+ def expect(value)
+ assert_equal value, @target.events.shift
+ end
+
+ def expect_done
+ assert_nil @target.events.shift
+ end
+
+end
Index: builder-2.1.2/test/testeventbuilder.rb
===================================================================
--- builder-2.1.2.orig/test/testeventbuilder.rb 2006-12-24 20:29:01.000000000 +0100
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
@@ -1,133 +0,0 @@
-class TestEvents < Test::Unit::TestCase
-
- class Target
- attr_reader :events
-
- def initialize
- @events = []
- end
-
- def start_tag(tag, attrs)
- @events << [:start_tag, tag, attrs]
- end
-
- def end_tag(tag)
- @events << [:end_tag, tag]
- end
-
- def text(string)
- @events << [:text, string]
- end
-
- end
-
-
- def setup
- @target = Target.new
- @xml = Builder::XmlEvents.new(:target=>@target)
- end
-
- def test_simple
- @xml.one
- expect [:start_tag, :one, nil]
- expect [:end_tag, :one]
- expect_done
- end
-
- def test_nested
- @xml.one { @xml.two }
- expect [:start_tag, :one, nil]
- expect [:start_tag, :two, nil]
- expect [:end_tag, :two]
- expect [:end_tag, :one]
- expect_done
- end
-
- def test_text
- @xml.one("a")
- expect [:start_tag, :one, nil]
- expect [:text, "a"]
- expect [:end_tag, :one]
- expect_done
- end
-
- def test_special_text
- @xml.one("H&R")
- expect [:start_tag, :one, nil]
- expect [:text, "H&R"]
- expect [:end_tag, :one]
- expect_done
- end
-
- def test_text_with_entity
- @xml.one("H&R")
- expect [:start_tag, :one, nil]
- expect [:text, "H&R"]
- expect [:end_tag, :one]
- expect_done
- end
-
- def test_attributes
- @xml.a(:b=>"c", :x=>"y")
- expect [:start_tag, :a, {:x => "y", :b => "c"}]
- expect [:end_tag, :a]
- expect_done
- end
-
- def test_moderately_complex
- @xml.tag! "address-book" do |x|
- x.entry :id=>"1" do
- x.name {
- x.first "Bill"
- x.last "Smith"
- }
- x.address "Cincinnati"
- end
- x.entry :id=>"2" do
- x.name {
- x.first "John"
- x.last "Doe"
- }
- x.address "Columbus"
- end
- end
- expect [:start_tag, "address-book".intern, nil]
- expect [:start_tag, :entry, {:id => "1"}]
- expect [:start_tag, :name, nil]
- expect [:start_tag, :first, nil]
- expect [:text, "Bill"]
- expect [:end_tag, :first]
- expect [:start_tag, :last, nil]
- expect [:text, "Smith"]
- expect [:end_tag, :last]
- expect [:end_tag, :name]
- expect [:start_tag, :address, nil]
- expect [:text, "Cincinnati"]
- expect [:end_tag, :address]
- expect [:end_tag, :entry]
- expect [:start_tag, :entry, {:id => "2"}]
- expect [:start_tag, :name, nil]
- expect [:start_tag, :first, nil]
- expect [:text, "John"]
- expect [:end_tag, :first]
- expect [:start_tag, :last, nil]
- expect [:text, "Doe"]
- expect [:end_tag, :last]
- expect [:end_tag, :name]
- expect [:start_tag, :address, nil]
- expect [:text, "Columbus"]
- expect [:end_tag, :address]
- expect [:end_tag, :entry]
- expect [:end_tag, "address-book".intern]
- expect_done
- end
-
- def expect(value)
- assert_equal value, @target.events.shift
- end
-
- def expect_done
- assert_nil @target.events.shift
- end
-
-end
Index: builder-2.1.2/test/test_markupbuilder.rb
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/test/test_markupbuilder.rb 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,505 @@
+#!/usr/bin/env ruby
+
+#--
+# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
+# Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
+# All rights reserved.
+
+# Permission is granted for use, copying, modification, distribution,
+# and distribution of modified versions of this work as long as the
+# above copyright notice is included.
+#++
+
+require 'test/unit'
+require 'test/preload'
+require 'builder'
+require 'builder/xmlmarkup'
+
+class TestMarkup < Test::Unit::TestCase
+ def setup
+ @xml = Builder::XmlMarkup.new
+ end
+
+ def test_create
+ assert_not_nil @xml
+ end
+
+ def test_simple
+ @xml.simple
+ assert_equal "<simple/>", @xml.target!
+ end
+
+ def test_value
+ @xml.value("hi")
+ assert_equal "<value>hi</value>", @xml.target!
+ end
+
+ def test_nested
+ @xml.outer { |x| x.inner("x") }
+ assert_equal "<outer><inner>x</inner></outer>", @xml.target!
+ end
+
+ def test_attributes
+ @xml.ref(:id => 12)
+ assert_equal %{<ref id="12"/>}, @xml.target!
+ end
+
+ def test_string_attributes_are_quoted_by_default
+ @xml.ref(:id => "H&R")
+ assert_equal %{<ref id="H&R"/>}, @xml.target!
+ end
+
+ def test_symbol_attributes_are_unquoted_by_default
+ @xml.ref(:id => :"H&R")
+ assert_equal %{<ref id="H&R"/>}, @xml.target!
+ end
+
+ def test_attributes_quoted_can_be_turned_on
+ @xml = Builder::XmlMarkup.new
+ @xml.ref(:id => "<H&R \"block\">")
+ assert_equal %{<ref id="<H&R "block">"/>}, @xml.target!
+ end
+
+ def test_mixed_attribute_quoting_with_nested_builders
+ x = Builder::XmlMarkup.new(:target=>@xml)
+ @xml.ref(:id=>:"H&R") {
+ x.element(:tag=>"Long&Short")
+ }
+ assert_equal "<ref id=\"H&R\"><element tag=\"Long&Short\"/></ref>",
+ @xml.target!
+ end
+
+ def test_multiple_attributes
+ @xml.ref(:id => 12, :name => "bill")
+ assert_match %r{^<ref( id="12"| name="bill"){2}/>$}, @xml.target!
+ end
+
+ def test_attributes_with_text
+ @xml.a("link", :href=>"http://onestepback.org")
+ assert_equal %{<a href="http://onestepback.org">link</a>}, @xml.target!
+ end
+
+ def test_complex
+ @xml.body(:bg=>"#ffffff") { |x|
+ x.title("T", :style=>"red")
+ }
+ assert_equal %{<body bg="#ffffff"><title style="red">T</title></body>}, @xml.target!
+ end
+
+ def test_funky_symbol
+ @xml.tag!("non-ruby-token", :id=>1) { |x| x.ok }
+ assert_equal %{<non-ruby-token id="1"><ok/></non-ruby-token>}, @xml.target!
+ end
+
+ def test_tag_can_handle_private_method
+ @xml.tag!("loop", :id=>1) { |x| x.ok }
+ assert_equal %{<loop id="1"><ok/></loop>}, @xml.target!
+ end
+
+ def test_no_explicit_marker
+ @xml.p { |x| x.b("HI") }
+ assert_equal "<p><b>HI</b></p>", @xml.target!
+ end
+
+ def test_reference_local_vars
+ n = 3
+ @xml.ol { |x| n.times { x.li(n) } }
+ assert_equal "<ol><li>3</li><li>3</li><li>3</li></ol>", @xml.target!
+ end
+
+ def test_reference_methods
+ @xml.title { |x| x.a { x.b(name) } }
+ assert_equal "<title><a><b>bob</b></a></title>", @xml.target!
+ end
+
+ def test_append_text
+ @xml.p { |x| x.br; x.text! "HI" }
+ assert_equal "<p><br/>HI</p>", @xml.target!
+ end
+
+ def test_ambiguous_markup
+ ex = assert_raises(ArgumentError) {
+ @xml.h1("data1") { b }
+ }
+ assert_match /\btext\b/, ex.message
+ assert_match /\bblock\b/, ex.message
+ end
+
+ def test_capitalized_method
+ @xml.P { |x| x.B("hi"); x.BR(); x.EM { x.text! "world" } }
+ assert_equal "<P><B>hi</B><BR/><EM>world</EM></P>", @xml.target!
+ end
+
+ def test_escaping
+ @xml.div { |x| x.text! "<hi>"; x.em("H&R Block") }
+ assert_equal %{<div><hi><em>H&R Block</em></div>}, @xml.target!
+ end
+
+ def test_non_escaping
+ @xml.div("ns:xml"=>:"&xml;") { |x| x << "<h&i>"; x.em("H&R Block") }
+ assert_equal %{<div ns:xml="&xml;"><h&i><em>H&R Block</em></div>}, @xml.target!
+ end
+
+ def test_return_value
+ str = @xml.x("men")
+ assert_equal @xml.target!, str
+ end
+
+ def test_stacked_builders
+ b = Builder::XmlMarkup.new( :target => @xml )
+ b.div { @xml.span { @xml.a("text", :href=>"ref") } }
+ assert_equal "<div><span><a href=\"ref\">text</a></span></div>", @xml.target!
+ end
+
+ def name
+ "bob"
+ end
+end
+
+class TestAttributeEscaping < Test::Unit::TestCase
+
+ def setup
+ @xml = Builder::XmlMarkup.new
+ end
+
+ def test_element_gt
+ @xml.title('1<2')
+ assert_equal '<title>1<2</title>', @xml.target!
+ end
+
+ def test_element_amp
+ @xml.title('AT&T')
+ assert_equal '<title>AT&T</title>', @xml.target!
+ end
+
+ def test_element_amp2
+ @xml.title('&')
+ assert_equal '<title>&amp;</title>', @xml.target!
+ end
+
+ def test_attr_less
+ @xml.a(:title => '2>1')
+ assert_equal '<a title="2>1"/>', @xml.target!
+ end
+
+ def test_attr_amp
+ @xml.a(:title => 'AT&T')
+ assert_equal '<a title="AT&T"/>', @xml.target!
+ end
+
+ def test_attr_quot
+ @xml.a(:title => '"x"')
+ assert_equal '<a title=""x""/>', @xml.target!
+ end
+
+end
+
+class TestNameSpaces < Test::Unit::TestCase
+ def setup
+ @xml = Builder::XmlMarkup.new(:indent=>2)
+ end
+
+ def test_simple_name_spaces
+ @xml.rdf :RDF
+ assert_equal "<rdf:RDF/>\n", @xml.target!
+ end
+
+ def test_long
+ xml = Builder::XmlMarkup.new(:indent=>2)
+ xml.instruct!
+ xml.rdf :RDF,
+ "xmlns:rdf" => :"&rdf;",
+ "xmlns:rdfs" => :"&rdfs;",
+ "xmlns:xsd" => :"&xsd;",
+ "xmlns:owl" => :"&owl;" do
+ xml.owl :Class, :'rdf:ID'=>'Bird' do
+ xml.rdfs :label, 'bird'
+ xml.rdfs :subClassOf do
+ xml.owl :Restriction do
+ xml.owl :onProperty, 'rdf:resource'=>'#wingspan'
+ xml.owl :maxCardinality,1,'rdf:datatype'=>'&xsd;nonNegativeInteger'
+ end
+ end
+ end
+ end
+ assert_match /^<\?xml/, xml.target!
+ assert_match /\n<rdf:RDF/m, xml.target!
+ assert_match /xmlns:rdf="&rdf;"/m, xml.target!
+ assert_match /<owl:Restriction>/m, xml.target!
+ end
+
+end
+
+class TestDeclarations < Test::Unit::TestCase
+ def setup
+ @xml = Builder::XmlMarkup.new(:indent=>2)
+ end
+
+ def test_declare
+ @xml.declare! :element
+ assert_equal "<!element>\n", @xml.target!
+ end
+
+ def test_bare_arg
+ @xml.declare! :element, :arg
+ assert_equal"<!element arg>\n", @xml.target!
+ end
+
+ def test_string_arg
+ @xml.declare! :element, "string"
+ assert_equal"<!element \"string\">\n", @xml.target!
+ end
+
+ def test_mixed_args
+ @xml.declare! :element, :x, "y", :z, "-//OASIS//DTD DocBook XML//EN"
+ assert_equal "<!element x \"y\" z \"-//OASIS//DTD DocBook XML//EN\">\n", @xml.target!
+ end
+
+ def test_nested_declarations
+ @xml = Builder::XmlMarkup.new
+ @xml.declare! :DOCTYPE, :chapter do |x|
+ x.declare! :ELEMENT, :chapter, "(title,para+)".intern
+ end
+ assert_equal "<!DOCTYPE chapter [<!ELEMENT chapter (title,para+)>]>", @xml.target!
+ end
+
+ def test_nested_indented_declarations
+ @xml.declare! :DOCTYPE, :chapter do |x|
+ x.declare! :ELEMENT, :chapter, "(title,para+)".intern
+ end
+ assert_equal "<!DOCTYPE chapter [\n <!ELEMENT chapter (title,para+)>\n]>\n", @xml.target!
+ end
+
+ def test_complex_declaration
+ @xml.declare! :DOCTYPE, :chapter do |x|
+ x.declare! :ELEMENT, :chapter, "(title,para+)".intern
+ x.declare! :ELEMENT, :title, "(#PCDATA)".intern
+ x.declare! :ELEMENT, :para, "(#PCDATA)".intern
+ end
+ expected = %{<!DOCTYPE chapter [
+ <!ELEMENT chapter (title,para+)>
+ <!ELEMENT title (#PCDATA)>
+ <!ELEMENT para (#PCDATA)>
+]>
+}
+ assert_equal expected, @xml.target!
+ end
+end
+
+
+class TestSpecialMarkup < Test::Unit::TestCase
+ def setup
+ @xml = Builder::XmlMarkup.new(:indent=>2)
+ end
+
+ def test_comment
+ @xml.comment!("COMMENT")
+ assert_equal "<!-- COMMENT -->\n", @xml.target!
+ end
+
+ def test_indented_comment
+ @xml.p { @xml.comment! "OK" }
+ assert_equal "<p>\n <!-- OK -->\n</p>\n", @xml.target!
+ end
+
+ def test_instruct
+ @xml.instruct! :abc, :version=>"0.9"
+ assert_equal "<?abc version=\"0.9\"?>\n", @xml.target!
+ end
+
+ def test_indented_instruct
+ @xml.p { @xml.instruct! :xml }
+ assert_match %r{<p>\n <\?xml version="1.0" encoding="UTF-8"\?>\n</p>\n},
+ @xml.target!
+ end
+
+ def test_instruct_without_attributes
+ @xml.instruct! :zz
+ assert_equal "<?zz?>\n", @xml.target!
+ end
+
+ def test_xml_instruct
+ @xml.instruct!
+ assert_match /^<\?xml version="1.0" encoding="UTF-8"\?>$/, @xml.target!
+ end
+
+ def test_xml_instruct_with_overrides
+ @xml.instruct! :xml, :encoding=>"UCS-2"
+ assert_match /^<\?xml version="1.0" encoding="UCS-2"\?>$/, @xml.target!
+ end
+
+ def test_xml_instruct_with_standalong
+ @xml.instruct! :xml, :encoding=>"UCS-2", :standalone=>"yes"
+ assert_match /^<\?xml version="1.0" encoding="UCS-2" standalone="yes"\?>$/, @xml.target!
+ end
+
+ def test_no_blocks
+ assert_raises(Builder::IllegalBlockError) do
+ @xml.instruct! { |x| x.hi }
+ end
+ assert_raises(Builder::IllegalBlockError) do
+ @xml.comment!(:element) { |x| x.hi }
+ end
+ end
+
+ def test_cdata
+ @xml.cdata!("TEST")
+ assert_equal "<![CDATA[TEST]]>\n", @xml.target!
+ end
+
+ def test_cdata_with_ampersand
+ @xml.cdata!("TEST&CHECK")
+ assert_equal "<![CDATA[TEST&CHECK]]>\n", @xml.target!
+ end
+end
+
+class TestIndentedXmlMarkup < Test::Unit::TestCase
+ def setup
+ @xml = Builder::XmlMarkup.new(:indent=>2)
+ end
+
+ def test_one_level
+ @xml.ol { |x| x.li "text" }
+ assert_equal "<ol>\n <li>text</li>\n</ol>\n", @xml.target!
+ end
+
+ def test_two_levels
+ @xml.p { |x|
+ x.ol { x.li "text" }
+ x.br
+ }
+ assert_equal "<p>\n <ol>\n <li>text</li>\n </ol>\n <br/>\n</p>\n", @xml.target!
+ end
+
+ def test_initial_level
+ @xml = Builder::XmlMarkup.new(:indent=>2, :margin=>4)
+ @xml.name { |x| x.first("Jim") }
+ assert_equal " <name>\n <first>Jim</first>\n </name>\n", @xml.target!
+ end
+
+ class TestUtfMarkup < Test::Unit::TestCase
+ def setup
+ @old_kcode = $KCODE
+ end
+
+ def teardown
+ $KCODE = @old_kcode
+ end
+
+ def test_use_entities_if_no_encoding_is_given_and_kcode_is_none
+ $KCODE = 'NONE'
+ xml = Builder::XmlMarkup.new
+ xml.p("\xE2\x80\x99")
+ assert_match(%r(<p>’</p>), xml.target!) #
+ end
+
+ def test_use_entities_if_encoding_is_utf_but_kcode_is_not
+ $KCODE = 'NONE'
+ xml = Builder::XmlMarkup.new
+ xml.instruct!(:xml, :encoding => 'UTF-8')
+ xml.p("\xE2\x80\x99")
+ assert_match(%r(<p>’</p>), xml.target!) #
+ end
+
+ def test_use_entities_if_kcode_is_utf_but_encoding_is_something_else
+ $KCODE = 'UTF8'
+ xml = Builder::XmlMarkup.new
+ xml.instruct!(:xml, :encoding => 'UTF-16')
+ xml.p("\xE2\x80\x99")
+ assert_match(%r(<p>’</p>), xml.target!) #
+ end
+
+ def test_use_utf8_if_encoding_defaults_and_kcode_is_utf8
+ $KCODE = 'UTF8'
+ xml = Builder::XmlMarkup.new
+ xml.p("\xE2\x80\x99")
+ assert_equal "<p>\xE2\x80\x99</p>", xml.target!
+ end
+
+ def test_use_utf8_if_both_encoding_and_kcode_are_utf8
+ $KCODE = 'UTF8'
+ xml = Builder::XmlMarkup.new
+ xml.instruct!(:xml, :encoding => 'UTF-8')
+ xml.p("\xE2\x80\x99")
+ assert_match(%r(<p>\xE2\x80\x99</p>), xml.target!)
+ end
+
+ def test_use_utf8_if_both_encoding_and_kcode_are_utf8_with_lowercase
+ $KCODE = 'UTF8'
+ xml = Builder::XmlMarkup.new
+ xml.instruct!(:xml, :encoding => 'utf-8')
+ xml.p("\xE2\x80\x99")
+ assert_match(%r(<p>\xE2\x80\x99</p>), xml.target!)
+ end
+ end
+
+ class TestXmlEvents < Test::Unit::TestCase
+ def setup
+ @handler = EventHandler.new
+ @xe = Builder::XmlEvents.new(:target=>@handler)
+ end
+
+ def test_simple
+ @xe.p
+ assert_equal [:start, :p, nil], @handler.events.shift
+ assert_equal [:end, :p], @handler.events.shift
+ end
+
+ def test_text
+ @xe.p("HI")
+ assert_equal [:start, :p, nil], @handler.events.shift
+ assert_equal [:text, "HI"], @handler.events.shift
+ assert_equal [:end, :p], @handler.events.shift
+ end
+
+ def test_attributes
+ @xe.p("id"=>"2")
+ ev = @handler.events.shift
+ assert_equal [:start, :p], ev[0,2]
+ assert_equal "2", ev[2]['id']
+ assert_equal [:end, :p], @handler.events.shift
+ end
+
+ def test_indented
+ @xml = Builder::XmlEvents.new(:indent=>2, :target=>@handler)
+ @xml.p { |x| x.b("HI") }
+ assert_equal [:start, :p, nil], @handler.events.shift
+ assert_equal "\n ", pop_text
+ assert_equal [:start, :b, nil], @handler.events.shift
+ assert_equal "HI", pop_text
+ assert_equal [:end, :b], @handler.events.shift
+ assert_equal "\n", pop_text
+ assert_equal [:end, :p], @handler.events.shift
+ end
+
+ def pop_text
+ result = ''
+ while ! @handler.events.empty? && @handler.events[0][0] == :text
+ result << @handler.events[0][1]
+ @handler.events.shift
+ end
+ result
+ end
+
+ class EventHandler
+ attr_reader :events
+ def initialize
+ @events = []
+ end
+
+ def start_tag(sym, attrs)
+ @events << [:start, sym, attrs]
+ end
+
+ def end_tag(sym)
+ @events << [:end, sym]
+ end
+
+ def text(txt)
+ @events << [:text, txt]
+ end
+ end
+ end
+
+end
+
Index: builder-2.1.2/test/testmarkupbuilder.rb
===================================================================
--- builder-2.1.2.orig/test/testmarkupbuilder.rb 2007-06-15 06:58:44.000000000 +0200
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000
@@ -1,449 +0,0 @@
-#!/usr/bin/env ruby
-
-#--
-# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
-# Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
-# All rights reserved.
-
-# Permission is granted for use, copying, modification, distribution,
-# and distribution of modified versions of this work as long as the
-# above copyright notice is included.
-#++
-
-require 'test/unit'
-require 'test/preload'
-require 'builder'
-require 'builder/xmlmarkup'
-
-class TestMarkup < Test::Unit::TestCase
- def setup
- @xml = Builder::XmlMarkup.new
- end
-
- def test_create
- assert_not_nil @xml
- end
-
- def test_simple
- @xml.simple
- assert_equal "<simple/>", @xml.target!
- end
-
- def test_value
- @xml.value("hi")
- assert_equal "<value>hi</value>", @xml.target!
- end
-
- def test_nested
- @xml.outer { |x| x.inner("x") }
- assert_equal "<outer><inner>x</inner></outer>", @xml.target!
- end
-
- def test_attributes
- @xml.ref(:id => 12)
- assert_equal %{<ref id="12"/>}, @xml.target!
- end
-
- def test_string_attributes_are_quoted_by_default
- @xml.ref(:id => "H&R")
- assert_equal %{<ref id="H&R"/>}, @xml.target!
- end
-
- def test_symbol_attributes_are_unquoted_by_default
- @xml.ref(:id => :"H&R")
- assert_equal %{<ref id="H&R"/>}, @xml.target!
- end
-
- def test_attributes_quoted_can_be_turned_on
- @xml = Builder::XmlMarkup.new
- @xml.ref(:id => "<H&R \"block\">")
- assert_equal %{<ref id="<H&R "block">"/>}, @xml.target!
- end
-
- def test_mixed_attribute_quoting_with_nested_builders
- x = Builder::XmlMarkup.new(:target=>@xml)
- @xml.ref(:id=>:"H&R") {
- x.element(:tag=>"Long&Short")
- }
- assert_equal "<ref id=\"H&R\"><element tag=\"Long&Short\"/></ref>",
- @xml.target!
- end
-
- def test_multiple_attributes
- @xml.ref(:id => 12, :name => "bill")
- assert_match %r{^<ref( id="12"| name="bill"){2}/>$}, @xml.target!
- end
-
- def test_attributes_with_text
- @xml.a("link", :href=>"http://onestepback.org")
- assert_equal %{<a href="http://onestepback.org">link</a>}, @xml.target!
- end
-
- def test_complex
- @xml.body(:bg=>"#ffffff") { |x|
- x.title("T", :style=>"red")
- }
- assert_equal %{<body bg="#ffffff"><title style="red">T</title></body>}, @xml.target!
- end
-
- def test_funky_symbol
- @xml.tag!("non-ruby-token", :id=>1) { |x| x.ok }
- assert_equal %{<non-ruby-token id="1"><ok/></non-ruby-token>}, @xml.target!
- end
-
- def test_tag_can_handle_private_method
- @xml.tag!("loop", :id=>1) { |x| x.ok }
- assert_equal %{<loop id="1"><ok/></loop>}, @xml.target!
- end
-
- def test_no_explicit_marker
- @xml.p { |x| x.b("HI") }
- assert_equal "<p><b>HI</b></p>", @xml.target!
- end
-
- def test_reference_local_vars
- n = 3
- @xml.ol { |x| n.times { x.li(n) } }
- assert_equal "<ol><li>3</li><li>3</li><li>3</li></ol>", @xml.target!
- end
-
- def test_reference_methods
- @xml.title { |x| x.a { x.b(name) } }
- assert_equal "<title><a><b>bob</b></a></title>", @xml.target!
- end
-
- def test_append_text
- @xml.p { |x| x.br; x.text! "HI" }
- assert_equal "<p><br/>HI</p>", @xml.target!
- end
-
- def test_ambiguous_markup
- ex = assert_raises(ArgumentError) {
- @xml.h1("data1") { b }
- }
- assert_match /\btext\b/, ex.message
- assert_match /\bblock\b/, ex.message
- end
-
- def test_capitalized_method
- @xml.P { |x| x.B("hi"); x.BR(); x.EM { x.text! "world" } }
- assert_equal "<P><B>hi</B><BR/><EM>world</EM></P>", @xml.target!
- end
-
- def test_escaping
- @xml.div { |x| x.text! "<hi>"; x.em("H&R Block") }
- assert_equal %{<div><hi><em>H&R Block</em></div>}, @xml.target!
- end
-
- def test_non_escaping
- @xml.div("ns:xml"=>:"&xml;") { |x| x << "<h&i>"; x.em("H&R Block") }
- assert_equal %{<div ns:xml="&xml;"><h&i><em>H&R Block</em></div>}, @xml.target!
- end
-
- def test_return_value
- str = @xml.x("men")
- assert_equal @xml.target!, str
- end
-
- def test_stacked_builders
- b = Builder::XmlMarkup.new( :target => @xml )
- b.div { @xml.span { @xml.a("text", :href=>"ref") } }
- assert_equal "<div><span><a href=\"ref\">text</a></span></div>", @xml.target!
- end
-
- def name
- "bob"
- end
-end
-
-class TestAttributeEscaping < Test::Unit::TestCase
-
- def setup
- @xml = Builder::XmlMarkup.new
- end
-
- def test_element_gt
- @xml.title('1<2')
- assert_equal '<title>1<2</title>', @xml.target!
- end
-
- def test_element_amp
- @xml.title('AT&T')
- assert_equal '<title>AT&T</title>', @xml.target!
- end
-
- def test_element_amp2
- @xml.title('&')
- assert_equal '<title>&amp;</title>', @xml.target!
- end
-
- def test_attr_less
- @xml.a(:title => '2>1')
- assert_equal '<a title="2>1"/>', @xml.target!
- end
-
- def test_attr_amp
- @xml.a(:title => 'AT&T')
- assert_equal '<a title="AT&T"/>', @xml.target!
- end
-
- def test_attr_quot
- @xml.a(:title => '"x"')
- assert_equal '<a title=""x""/>', @xml.target!
- end
-
-end
-
-class TestNameSpaces < Test::Unit::TestCase
- def setup
- @xml = Builder::XmlMarkup.new(:indent=>2)
- end
-
- def test_simple_name_spaces
- @xml.rdf :RDF
- assert_equal "<rdf:RDF/>\n", @xml.target!
- end
-
- def test_long
- xml = Builder::XmlMarkup.new(:indent=>2)
- xml.instruct!
- xml.rdf :RDF,
- "xmlns:rdf" => :"&rdf;",
- "xmlns:rdfs" => :"&rdfs;",
- "xmlns:xsd" => :"&xsd;",
- "xmlns:owl" => :"&owl;" do
- xml.owl :Class, :'rdf:ID'=>'Bird' do
- xml.rdfs :label, 'bird'
- xml.rdfs :subClassOf do
- xml.owl :Restriction do
- xml.owl :onProperty, 'rdf:resource'=>'#wingspan'
- xml.owl :maxCardinality,1,'rdf:datatype'=>'&xsd;nonNegativeInteger'
- end
- end
- end
- end
- assert_match /^<\?xml/, xml.target!
- assert_match /\n<rdf:RDF/m, xml.target!
- assert_match /xmlns:rdf="&rdf;"/m, xml.target!
- assert_match /<owl:Restriction>/m, xml.target!
- end
-
-end
-
-class TestDeclarations < Test::Unit::TestCase
- def setup
- @xml = Builder::XmlMarkup.new(:indent=>2)
- end
-
- def test_declare
- @xml.declare! :element
- assert_equal "<!element>\n", @xml.target!
- end
-
- def test_bare_arg
- @xml.declare! :element, :arg
- assert_equal"<!element arg>\n", @xml.target!
- end
-
- def test_string_arg
- @xml.declare! :element, "string"
- assert_equal"<!element \"string\">\n", @xml.target!
- end
-
- def test_mixed_args
- @xml.declare! :element, :x, "y", :z, "-//OASIS//DTD DocBook XML//EN"
- assert_equal "<!element x \"y\" z \"-//OASIS//DTD DocBook XML//EN\">\n", @xml.target!
- end
-
- def test_nested_declarations
- @xml = Builder::XmlMarkup.new
- @xml.declare! :DOCTYPE, :chapter do |x|
- x.declare! :ELEMENT, :chapter, "(title,para+)".intern
- end
- assert_equal "<!DOCTYPE chapter [<!ELEMENT chapter (title,para+)>]>", @xml.target!
- end
-
- def test_nested_indented_declarations
- @xml.declare! :DOCTYPE, :chapter do |x|
- x.declare! :ELEMENT, :chapter, "(title,para+)".intern
- end
- assert_equal "<!DOCTYPE chapter [\n <!ELEMENT chapter (title,para+)>\n]>\n", @xml.target!
- end
-
- def test_complex_declaration
- @xml.declare! :DOCTYPE, :chapter do |x|
- x.declare! :ELEMENT, :chapter, "(title,para+)".intern
- x.declare! :ELEMENT, :title, "(#PCDATA)".intern
- x.declare! :ELEMENT, :para, "(#PCDATA)".intern
- end
- expected = %{<!DOCTYPE chapter [
- <!ELEMENT chapter (title,para+)>
- <!ELEMENT title (#PCDATA)>
- <!ELEMENT para (#PCDATA)>
-]>
-}
- assert_equal expected, @xml.target!
- end
-end
-
-
-class TestSpecialMarkup < Test::Unit::TestCase
- def setup
- @xml = Builder::XmlMarkup.new(:indent=>2)
- end
-
- def test_comment
- @xml.comment!("COMMENT")
- assert_equal "<!-- COMMENT -->\n", @xml.target!
- end
-
- def test_indented_comment
- @xml.p { @xml.comment! "OK" }
- assert_equal "<p>\n <!-- OK -->\n</p>\n", @xml.target!
- end
-
- def test_instruct
- @xml.instruct! :abc, :version=>"0.9"
- assert_equal "<?abc version=\"0.9\"?>\n", @xml.target!
- end
-
- def test_indented_instruct
- @xml.p { @xml.instruct! :xml }
- assert_match %r{<p>\n <\?xml version="1.0" encoding="UTF-8"\?>\n</p>\n},
- @xml.target!
- end
-
- def test_instruct_without_attributes
- @xml.instruct! :zz
- assert_equal "<?zz?>\n", @xml.target!
- end
-
- def test_xml_instruct
- @xml.instruct!
- assert_match /^<\?xml version="1.0" encoding="UTF-8"\?>$/, @xml.target!
- end
-
- def test_xml_instruct_with_overrides
- @xml.instruct! :xml, :encoding=>"UCS-2"
- assert_match /^<\?xml version="1.0" encoding="UCS-2"\?>$/, @xml.target!
- end
-
- def test_xml_instruct_with_standalong
- @xml.instruct! :xml, :encoding=>"UCS-2", :standalone=>"yes"
- assert_match /^<\?xml version="1.0" encoding="UCS-2" standalone="yes"\?>$/, @xml.target!
- end
-
- def test_no_blocks
- assert_raises(Builder::IllegalBlockError) do
- @xml.instruct! { |x| x.hi }
- end
- assert_raises(Builder::IllegalBlockError) do
- @xml.comment!(:element) { |x| x.hi }
- end
- end
-
- def test_cdata
- @xml.cdata!("TEST")
- assert_equal "<![CDATA[TEST]]>\n", @xml.target!
- end
-
- def test_cdata_with_ampersand
- @xml.cdata!("TEST&CHECK")
- assert_equal "<![CDATA[TEST&CHECK]]>\n", @xml.target!
- end
-end
-
-class TestIndentedXmlMarkup < Test::Unit::TestCase
- def setup
- @xml = Builder::XmlMarkup.new(:indent=>2)
- end
-
- def test_one_level
- @xml.ol { |x| x.li "text" }
- assert_equal "<ol>\n <li>text</li>\n</ol>\n", @xml.target!
- end
-
- def test_two_levels
- @xml.p { |x|
- x.ol { x.li "text" }
- x.br
- }
- assert_equal "<p>\n <ol>\n <li>text</li>\n </ol>\n <br/>\n</p>\n", @xml.target!
- end
-
- def test_initial_level
- @xml = Builder::XmlMarkup.new(:indent=>2, :margin=>4)
- @xml.name { |x| x.first("Jim") }
- assert_equal " <name>\n <first>Jim</first>\n </name>\n", @xml.target!
- end
-
- class TestXmlEvents < Test::Unit::TestCase
- def setup
- @handler = EventHandler.new
- @xe = Builder::XmlEvents.new(:target=>@handler)
- end
-
- def test_simple
- @xe.p
- assert_equal [:start, :p, nil], @handler.events.shift
- assert_equal [:end, :p], @handler.events.shift
- end
-
- def test_text
- @xe.p("HI")
- assert_equal [:start, :p, nil], @handler.events.shift
- assert_equal [:text, "HI"], @handler.events.shift
- assert_equal [:end, :p], @handler.events.shift
- end
-
- def test_attributes
- @xe.p("id"=>"2")
- ev = @handler.events.shift
- assert_equal [:start, :p], ev[0,2]
- assert_equal "2", ev[2]['id']
- assert_equal [:end, :p], @handler.events.shift
- end
-
- def test_indented
- @xml = Builder::XmlEvents.new(:indent=>2, :target=>@handler)
- @xml.p { |x| x.b("HI") }
- assert_equal [:start, :p, nil], @handler.events.shift
- assert_equal "\n ", pop_text
- assert_equal [:start, :b, nil], @handler.events.shift
- assert_equal "HI", pop_text
- assert_equal [:end, :b], @handler.events.shift
- assert_equal "\n", pop_text
- assert_equal [:end, :p], @handler.events.shift
- end
-
- def pop_text
- result = ''
- while ! @handler.events.empty? && @handler.events[0][0] == :text
- result << @handler.events[0][1]
- @handler.events.shift
- end
- result
- end
-
- class EventHandler
- attr_reader :events
- def initialize
- @events = []
- end
-
- def start_tag(sym, attrs)
- @events << [:start, sym, attrs]
- end
-
- def end_tag(sym)
- @events << [:end, sym]
- end
-
- def text(txt)
- @events << [:text, txt]
- end
- end
- end
-
-end
-
Index: builder-2.1.2/test/test_namecollision.rb
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ builder-2.1.2/test/test_namecollision.rb 2010-03-21 16:37:51.000000000 +0100
@@ -0,0 +1,39 @@
+#!/usr/bin/env ruby
+
+#--
+# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
+# Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
+# All rights reserved.
+
+# Permission is granted for use, copying, modification, distribution,
+# and distribution of modified versions of this work as long as the
+# above copyright notice is included.
+#++
+
+require 'test/unit'
+require 'builder/xchar'
+
+class TestNameCollisions < Test::Unit::TestCase
+ module Collide
+ def xchr
+ end
+ end
+
+ def test_no_collision
+ assert_nothing_raised do
+ Builder.check_for_name_collision(Collide, :not_defined)
+ end
+ end
+
+ def test_collision
+ assert_raise RuntimeError do
+ Builder.check_for_name_collision(Collide, "xchr")
+ end
+ end
+
+ def test_collision_with_symbol
+ assert_raise RuntimeError do
+ Builder.check_for_name_collision(Collide, :xchr)
+ end
+ end
+end
Index: builder-2.1.2/test/test_xchar.rb
===================================================================
--- builder-2.1.2.orig/test/test_xchar.rb 2006-12-24 20:29:01.000000000 +0100
+++ builder-2.1.2/test/test_xchar.rb 2010-03-21 16:37:51.000000000 +0100
@@ -1,5 +1,17 @@
#!/usr/bin/env ruby
+#--
+# Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
+# Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
+# All rights reserved.
+
+# Permission is granted for use, copying, modification, distribution,
+# and distribution of modified versions of this work as long as the
+# above copyright notice is included.
+#++
+
+#!/usr/bin/env ruby
+
require 'test/unit'
require 'builder/xchar'
@@ -34,4 +46,11 @@
assert_equal '’', "\xE2\x80\x99".to_xs # right single quote
assert_equal '©', "\xC2\xA9".to_xs # copy
end
+
+ def test_utf8_verbatim
+ assert_equal "\xE2\x80\x99", "\xE2\x80\x99".to_xs(false) # right single quote
+ assert_equal "\xC2\xA9", "\xC2\xA9".to_xs(false) # copy
+ assert_equal "\xC2\xA9&\xC2\xA9",
+ "\xC2\xA9&\xC2\xA9".to_xs(false) # copy with ampersand
+ end
end