blankslate 2.1.2.4 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,101 @@
1
+ = Change Log
2
+
3
+ == Version 3.1.0
4
+
5
+ * Included the to_xs arity patch needed for weird Rails compatibility
6
+ issue.
7
+
8
+ * Escaping newlines in attributes now.
9
+
10
+ * Allow method caching
11
+
12
+ == Version 3.0.0
13
+
14
+ * Ruby 1.9 compatiblity issues.
15
+
16
+ == Version 2.2.0
17
+
18
+ * Applied patch from Thijs van der Vossen to allow UTF-8 encoded
19
+ output when the encoding is UTF-8 and $KCODE is UTF8.
20
+
21
+ == Version 2.1.2
22
+
23
+ * Fixed bug where private methods in kernel could leak through using
24
+ tag!(). Thanks to Hagen Overdick for finding and diagnosing this
25
+ bug.
26
+
27
+ == Version 2.1.1
28
+
29
+ * Fixed typo in XmlMarkup class docs (ident => indent). (from Martin
30
+ Fowler).
31
+ * Removed extra directory indirection from legacy CVS to SVN move.
32
+ * Removed some extraneous tabs from source.
33
+ * Fixed test on private methods in blankslate to differentiate between
34
+ targetted and untargetted private methods.
35
+ * Removed legacy capture of @self in XmlBase (@self was used back when
36
+ we used instance eval).
37
+ * Added additional tests for global functions (both direct and included).
38
+
39
+ == Version 2.1.0
40
+
41
+ * Fixed bug in BlankSlate where including a module into Object could
42
+ cause methods to leak into BlankSlate.
43
+ * Made BlankSlate available as its own gem. Currently the builder gem
44
+ still directly includes the BlankSlate code.
45
+ * Added reveal capability to BlankSlate.
46
+
47
+ == Version 2.0.0
48
+
49
+ * Added doc directory
50
+ * Added unit tests for XmlEvents.
51
+ * Added XChar module and used it in the _escape method.
52
+ * Attributes are now quoted by default when strings. Use Symbol
53
+ attribute values for unquoted behavior.
54
+
55
+ == Version 1.2.4
56
+
57
+ * Added a cdata! command to an XML Builder (from Josh Knowles).
58
+
59
+ == Version 1.2.3
60
+
61
+ The attributes in the <?xml ... ?> instruction will be ordered:
62
+ version, encoding, standalone.
63
+
64
+ == Version 1.2.2
65
+
66
+ Another fix for BlankSlate. The Kernal/Object traps added in 1.2.1
67
+ failed when a method was defined late more than once. Since the
68
+ method was already marked as removed, another attempt to undefine it
69
+ raised an error. The fix was to check the list of instance methods
70
+ before attempting the undef operation. Thanks to Florian Gross and
71
+ David Heinemeier Hansson for the patch.
72
+
73
+ == Version 1.2.1
74
+
75
+ BlankSlate now traps method definitions in Kernel and Object to avoid
76
+ late method definitions inadvertently becoming part of the definition
77
+ of BlankSlate as well.
78
+
79
+ == Version 1.2.0
80
+
81
+ Improved support for entity declarations by allowing nested
82
+ declarations and removal of the attribute processing.
83
+
84
+ Added namespace support.
85
+
86
+ == Version 1.1.0
87
+
88
+ Added support for comments, entity declarations and processing instructions.
89
+
90
+ == Version 1.0.0
91
+
92
+ Removed use of <tt>instace_eval</tt> making the use of XmlMarkup much
93
+ less prone to error.
94
+
95
+ == Version 0.1.1
96
+
97
+ Bug fix.
98
+
99
+ == Version 0.1.0
100
+
101
+ Initial version release.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2003-2012 Jim Weirich (jim.weirich@gmail.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,225 @@
1
+ # coding: UTF-8
2
+ = Project: Builder
3
+
4
+ == Goal
5
+
6
+ Provide a simple way to create XML markup and data structures.
7
+
8
+ == Classes
9
+
10
+ Builder::XmlMarkup:: Generate XML markup notiation
11
+ Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
12
+
13
+ <b>Notes</b>::
14
+
15
+ * An <tt>Builder::XmlTree</tt> class to generate XML tree
16
+ (i.e. DOM-like) structures is also planned, but not yet implemented.
17
+ Also, the events builder is currently lagging the markup builder in
18
+ features.
19
+
20
+ == Usage
21
+
22
+ require 'rubygems'
23
+ require_gem 'builder', '~> 2.0'
24
+
25
+ builder = Builder::XmlMarkup.new
26
+ xml = builder.person { |b| b.name("Jim"); b.phone("555-1234") }
27
+ xml #=> <person><name>Jim</name><phone>555-1234</phone></person>
28
+
29
+ or
30
+
31
+ require 'rubygems'
32
+ require_gem 'builder'
33
+
34
+ builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
35
+ builder.person { |b| b.name("Jim"); b.phone("555-1234") }
36
+ #
37
+ # Prints:
38
+ # <person>
39
+ # <name>Jim</name>
40
+ # <phone>555-1234</phone>
41
+ # </person>
42
+
43
+ == Compatibility
44
+
45
+ === Version 2.0.0 Compatibility Changes
46
+
47
+ Version 2.0.0 introduces automatically escaped attribute values for
48
+ the first time. Versions prior to 2.0.0 did not insert escape
49
+ characters into attribute values in the XML markup. This allowed
50
+ attribute values to explicitly reference entities, which was
51
+ occasionally used by a small number of developers. Since strings
52
+ could always be explicitly escaped by hand, this was not a major
53
+ restriction in functionality.
54
+
55
+ However, it did suprise most users of builder. Since the body text is
56
+ normally escaped, everybody expected the attribute values to be
57
+ escaped as well. Escaped attribute values were the number one support
58
+ request on the 1.x Builder series.
59
+
60
+ Starting with Builder version 2.0.0, all attribute values expressed as
61
+ strings will be processed and the appropriate characters will be
62
+ escaped (e.g. "&" will be tranlated to "&amp;"). Attribute values
63
+ that are expressed as Symbol values will not be processed for escaped
64
+ characters and will be unchanged in output. (Yes, this probably counts
65
+ as Symbol abuse, but the convention is convenient and flexible).
66
+
67
+ Example:
68
+
69
+ xml = Builder::XmlMarkup.new
70
+ xml.sample(:escaped=>"This&That", :unescaped=>:"Here&amp;There")
71
+ xml.target! =>
72
+ <sample escaped="This&amp;That" unescaped="Here&amp;There"/>
73
+
74
+ === Version 1.0.0 Compatibility Changes
75
+
76
+ Version 1.0.0 introduces some changes that are not backwards
77
+ compatible with earlier releases of builder. The main areas of
78
+ incompatibility are:
79
+
80
+ * Keyword based arguments to +new+ (rather than positional based). It
81
+ was found that a developer would often like to specify indentation
82
+ without providing an explicit target, or specify a target without
83
+ indentation. Keyword based arguments handle this situation nicely.
84
+
85
+ * Builder must now be an explicit target for markup tags. Instead of
86
+ writing
87
+
88
+ xml_markup = Builder::XmlMarkup.new
89
+ xml_markup.div { strong("text") }
90
+
91
+ you need to write
92
+
93
+ xml_markup = Builder::XmlMarkup.new
94
+ xml_markup.div { xml_markup.strong("text") }
95
+
96
+ * The builder object is passed as a parameter to all nested markup
97
+ blocks. This allows you to create a short alias for the builder
98
+ object that can be used within the block. For example, the previous
99
+ example can be written as:
100
+
101
+ xml_markup = Builder::XmlMarkup.new
102
+ xml_markup.div { |xml| xml.strong("text") }
103
+
104
+ * If you have both a pre-1.0 and a post-1.0 gem of builder installed,
105
+ you can choose which version to use through the RubyGems
106
+ +require_gem+ facility.
107
+
108
+ require_gem 'builder', "~> 0.0" # Gets the old version
109
+ require_gem 'builder', "~> 1.0" # Gets the new version
110
+
111
+ == Features
112
+
113
+ * XML Comments are supported ...
114
+
115
+ xml_markup.comment! "This is a comment"
116
+ #=> <!-- This is a comment -->
117
+
118
+ * XML processing instructions are supported ...
119
+
120
+ xml_markup.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
121
+ #=> <?xml version="1.0" encoding="UTF-8"?>
122
+
123
+ If the processing instruction is omitted, it defaults to "xml".
124
+ When the processing instruction is "xml", the defaults attributes
125
+ are:
126
+
127
+ <b>version</b>:: 1.0
128
+ <b>encoding</b>:: "UTF-8"
129
+
130
+ (NOTE: if the encoding is set to "UTF-8" and $KCODE is set to
131
+ "UTF8", then Builder will emit UTF-8 encoded strings rather than
132
+ encoding non-ASCII characters as entities.)
133
+
134
+ * XML entity declarations are now supported to a small degree.
135
+
136
+ xml_markup.declare! :DOCTYPE, :chapter, :SYSTEM, "../dtds/chapter.dtd"
137
+ #=> <!DOCTYPE chapter SYSTEM "../dtds/chapter.dtd">
138
+
139
+ The parameters to a declare! method must be either symbols or
140
+ strings. Symbols are inserted without quotes, and strings are
141
+ inserted with double quotes. Attribute-like arguments in hashes are
142
+ not allowed.
143
+
144
+ If you need to have an argument to declare! be inserted without
145
+ quotes, but the arguement does not conform to the typical Ruby
146
+ syntax for symbols, then use the :"string" form to specify a symbol.
147
+
148
+ For example:
149
+
150
+ xml_markup.declare! :ELEMENT, :chapter, :"(title,para+)"
151
+ #=> <!ELEMENT chapter (title,para+)>
152
+
153
+ Nested entity declarations are allowed. For example:
154
+
155
+ @xml_markup.declare! :DOCTYPE, :chapter do |x|
156
+ x.declare! :ELEMENT, :chapter, :"(title,para+)"
157
+ x.declare! :ELEMENT, :title, :"(#PCDATA)"
158
+ x.declare! :ELEMENT, :para, :"(#PCDATA)"
159
+ end
160
+
161
+ #=>
162
+
163
+ <!DOCTYPE chapter [
164
+ <!ELEMENT chapter (title,para+)>
165
+ <!ELEMENT title (#PCDATA)>
166
+ <!ELEMENT para (#PCDATA)>
167
+ ]>
168
+
169
+ * Some support for XML namespaces is now available. If the first
170
+ argument to a tag call is a symbol, it will be joined to the tag to
171
+ produce a namespace:tag combination. It is easier to show this than
172
+ describe it.
173
+
174
+ xml.SOAP :Envelope do ... end
175
+
176
+ Just put a space before the colon in a namespace to produce the
177
+ right form for builder (e.g. "<tt>SOAP:Envelope</tt>" =>
178
+ "<tt>xml.SOAP :Envelope</tt>")
179
+
180
+ * String attribute values are <em>now</em> escaped by default by
181
+ Builder (<b>NOTE:</b> this is _new_ behavior as of version 2.0).
182
+
183
+ However, occasionally you need to use entities in attribute values.
184
+ Using a symbols (rather than a string) for an attribute value will
185
+ cause Builder to not run its quoting/escaping algorithm on that
186
+ particular value.
187
+
188
+ (<b>Note:</b> The +escape_attrs+ option for builder is now
189
+ obsolete).
190
+
191
+ Example:
192
+
193
+ xml = Builder::XmlMarkup.new
194
+ xml.sample(:escaped=>"This&That", :unescaped=>:"Here&amp;There")
195
+ xml.target! =>
196
+ <sample escaped="This&amp;That" unescaped="Here&amp;There"/>
197
+
198
+ * UTF-8 Support
199
+
200
+ Builder correctly translates UTF-8 characters into valid XML. (New
201
+ in version 2.0.0). Thanks to Sam Ruby for the translation code.
202
+
203
+ You can get UTF-8 encoded output by making sure that the XML
204
+ encoding is set to "UTF-8" and that the $KCODE variable is set to
205
+ "UTF8".
206
+
207
+ $KCODE = 'UTF8'
208
+ xml = Builder::Markup.new
209
+ xml.instruct!(:xml, :encoding => "UTF-8")
210
+ xml.sample("Iñtërnâtiônàl")
211
+ xml.target! =>
212
+ "<sample>Iñtërnâtiônàl</sample>"
213
+
214
+ == Links
215
+
216
+ Documents :: http://builder.rubyforge.org/
217
+ Github Clone :: git://github.com/jimweirich/builder.git
218
+ Issue / Bug Reports :: https://github.com/jimweirich/builder/issues?state=open
219
+
220
+ == Contact
221
+
222
+ Author:: Jim Weirich
223
+ Email:: jim.weirich@gmail.com
224
+ Home Page:: http://onestepback.org
225
+ License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
data/Rakefile CHANGED
@@ -1,13 +1,189 @@
1
+ # Rakefile for rake -*- ruby -*-
1
2
 
2
- require 'bundler'
3
- Bundler::GemHelper.install_tasks
3
+ # Copyright 2004, 2005, 2006 by Jim Weirich (jim@weirichhouse.org).
4
+ # All rights reserved.
4
5
 
5
- task :default => :spec
6
+ # Permission is granted for use, copying, modification, distribution,
7
+ # and distribution of modified versions of this work as long as the
8
+ # above copyright notice is included.
6
9
 
10
+ require 'rake/clean'
7
11
  require 'rake/testtask'
8
- Rake::TestTask.new(:spec) do |test|
9
- test.libs << '.'
10
- test.ruby_opts = ['-rubygems']
11
- test.pattern = 'spec/*_spec.rb'
12
- test.verbose = true
12
+ require 'rdoc/task'
13
+ begin
14
+ require 'rubygems'
15
+ require 'rubygems/package_task'
16
+ rescue Exception
17
+ nil
18
+ end
19
+
20
+ require './lib/builder/version'
21
+
22
+ # Determine the current version of the software
23
+
24
+ CLOBBER.include('pkg')
25
+ CLEAN.include('pkg/builder-*').include('pkg/blankslate-*').exclude('pkg/*.gem')
26
+
27
+ PKG_VERSION = Builder::VERSION
28
+
29
+ SRC_RB = FileList['lib/**/*.rb']
30
+
31
+ # The default task is run if rake is given no explicit arguments.
32
+
33
+ desc "Default Task"
34
+ task :default => :test_all
35
+
36
+ # Test Tasks ---------------------------------------------------------
37
+
38
+ desc "Run all tests"
39
+ task :test_all => [:test_units]
40
+ task :ta => [:test_all]
41
+
42
+ task :tu => [:test_units]
43
+
44
+ Rake::TestTask.new("test_units") do |t|
45
+ t.test_files = FileList['test/test*.rb']
46
+ t.libs << "."
47
+ t.verbose = false
48
+ end
49
+
50
+ # Create a task to build the RDOC documentation tree.
51
+
52
+ rd = RDoc::Task.new("rdoc") { |rdoc|
53
+ rdoc.rdoc_dir = 'html'
54
+ rdoc.title = "Builder for Markup"
55
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
56
+ rdoc.rdoc_files.include('lib/**/*.rb', '[A-Z]*', 'doc/**/*.rdoc').exclude("TAGS")
57
+ rdoc.template = 'doc/jamis.rb'
58
+ }
59
+
60
+ # ====================================================================
61
+ # Create a task that will package the Rake software into distributable
62
+ # gem files.
63
+
64
+ PKG_FILES = FileList[
65
+ 'lib/**/*.rb',
66
+ 'test/**/*.rb',
67
+ 'scripts/**/*.rb'
68
+ ]
69
+ PKG_FILES.exclude('test/test_cssbuilder.rb')
70
+ PKG_FILES.exclude('lib/builder/css.rb')
71
+ PKG_FILES.exclude('TAGS')
72
+
73
+ BLANKSLATE_FILES = FileList[
74
+ 'lib/blankslate.rb',
75
+ 'test/test_blankslate.rb'
76
+ ]
77
+
78
+ if ! defined?(Gem)
79
+ puts "Package Target requires RubyGEMs"
80
+ else
81
+ spec = Gem::Specification.new do |s|
82
+
83
+ #### Basic information.
84
+
85
+ s.name = 'builder'
86
+ s.version = PKG_VERSION
87
+ s.summary = "Builders for MarkUp."
88
+ s.description = %{\
89
+ Builder provides a number of builder objects that make creating structured data
90
+ simple to do. Currently the following builder objects are supported:
91
+
92
+ * XML Markup
93
+ * XML Events
94
+ }
95
+
96
+ s.files = PKG_FILES.to_a
97
+ s.require_path = 'lib'
98
+
99
+ s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
100
+
101
+ s.has_rdoc = true
102
+ s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
103
+ s.rdoc_options <<
104
+ '--title' << 'Builder -- Easy XML Building' <<
105
+ '--main' << 'README.rdoc' <<
106
+ '--line-numbers'
107
+
108
+ s.author = "Jim Weirich"
109
+ s.email = "jim.weirich@gmail.com"
110
+ s.homepage = "http://onestepback.org"
111
+ s.license = 'MIT'
112
+ end
113
+
114
+ blankslate_spec = Gem::Specification.new do |s|
115
+
116
+ #### Basic information.
117
+
118
+ s.name = 'blankslate'
119
+ s.version = PKG_VERSION
120
+ s.summary = "Blank Slate base class."
121
+ s.description = %{\
122
+ BlankSlate provides a base class where almost all of the methods from Object and
123
+ Kernel have been removed. This is useful when providing proxy object and other
124
+ classes that make heavy use of method_missing.
125
+ }
126
+
127
+ s.files = BLANKSLATE_FILES.to_a
128
+ s.require_path = 'lib'
129
+
130
+ s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
131
+
132
+ s.has_rdoc = true
133
+ s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
134
+ s.rdoc_options <<
135
+ '--title' << 'BlankSlate -- Base Class for building proxies.' <<
136
+ '--main' << 'README.rdoc' <<
137
+ '--line-numbers'
138
+
139
+ s.author = "Jim Weirich"
140
+ s.email = "jim.weirich@gmail.com"
141
+ s.homepage = "http://onestepback.org"
142
+ s.license = 'MIT'
143
+ end
144
+
145
+ namespace 'builder' do
146
+ Gem::PackageTask.new(spec) do |t|
147
+ t.need_tar = false
148
+ end
149
+ end
150
+
151
+ namespace 'blankslate' do
152
+ Gem::PackageTask.new(blankslate_spec) do |t|
153
+ t.need_tar = false
154
+ end
155
+ end
156
+
157
+ task :package => [:remove_tags, 'builder:package', 'blankslate:package']
158
+ end
159
+
160
+ task :remove_tags do
161
+ rm "TAGS" rescue nil
162
+ end
163
+
164
+ # RCov ---------------------------------------------------------------
165
+ begin
166
+ require 'rcov/rcovtask'
167
+
168
+ Rcov::RcovTask.new do |t|
169
+ t.libs << "test"
170
+ t.rcov_opts = [
171
+ '-xRakefile', '--text-report'
172
+ ]
173
+ t.test_files = FileList[
174
+ 'test/test*.rb'
175
+ ]
176
+ t.output_dir = 'coverage'
177
+ t.verbose = true
178
+ end
179
+ rescue LoadError
180
+ # No rcov available
181
+ end
182
+
183
+ desc "Install the jamis RDoc template"
184
+ task :install_jamis_template do
185
+ require 'rbconfig'
186
+ dest_dir = File.join(Config::CONFIG['rubylibdir'], "rdoc/generators/template/html")
187
+ fail "Unabled to write to #{dest_dir}" unless File.writable?(dest_dir)
188
+ install "doc/jamis.rb", dest_dir, :verbose => true
13
189
  end