license_finder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +22 -0
- data/README.markdown +84 -0
- data/Rakefile +12 -0
- data/bin/license_finder +7 -0
- data/files/license_finder.yml +7 -0
- data/lib/license_finder.rb +15 -0
- data/lib/license_finder/dependency.rb +63 -0
- data/lib/license_finder/dependency_list.rb +55 -0
- data/lib/license_finder/file_parser.rb +32 -0
- data/lib/license_finder/finder.rb +48 -0
- data/lib/license_finder/gem_spec_details.rb +101 -0
- data/lib/license_finder/license_file.rb +77 -0
- data/lib/license_finder/railtie.rb +9 -0
- data/lib/license_finder/version.rb +3 -0
- data/lib/tasks/license_finder.rake +17 -0
- data/lib/templates/Apache-2.0-body +172 -0
- data/lib/templates/GPL-2.0-body +339 -0
- data/lib/templates/MIT-body +9 -0
- data/license_finder.gemspec +23 -0
- data/spec/dependency_list_spec.rb +202 -0
- data/spec/dependency_spec.rb +57 -0
- data/spec/file_parser_spec.rb +16 -0
- data/spec/finder_spec.rb +44 -0
- data/spec/fixtures/APACHE-2-LICENSE +202 -0
- data/spec/fixtures/GPLv2 +339 -0
- data/spec/fixtures/MIT-LICENSE +22 -0
- data/spec/fixtures/MIT-LICENSE-with-varied-disclaimer +22 -0
- data/spec/fixtures/README-with-MIT-LICENSE +222 -0
- data/spec/fixtures/apache_licensed_gem/LICENSE +191 -0
- data/spec/fixtures/gplv2_licensed_gem/LICENSE +339 -0
- data/spec/fixtures/license_directory/COPYING +0 -0
- data/spec/fixtures/license_directory/LICENSE/BSD-2-Clause.txt +25 -0
- data/spec/fixtures/license_directory/LICENSE/GPL-2.0.txt +339 -0
- data/spec/fixtures/license_directory/LICENSE/LICENSE +191 -0
- data/spec/fixtures/license_directory/LICENSE/MIT.txt +21 -0
- data/spec/fixtures/license_directory/LICENSE/RUBY.txt +60 -0
- data/spec/fixtures/license_names/COPYING.txt +0 -0
- data/spec/fixtures/license_names/LICENSE +0 -0
- data/spec/fixtures/license_names/Mit-License +0 -0
- data/spec/fixtures/license_names/README.rdoc +0 -0
- data/spec/fixtures/mit_licensed_gem/LICENSE +22 -0
- data/spec/fixtures/mit_licensed_gem_in_README/README.rdoc +222 -0
- data/spec/fixtures/mit_licensed_gem_via_url/README +210 -0
- data/spec/fixtures/nested_gem/vendor/LICENSE +0 -0
- data/spec/fixtures/nested_readme/vendor/README +0 -0
- data/spec/fixtures/no_license/.gitkeep +0 -0
- data/spec/fixtures/other_licensed_gem/LICENSE +3 -0
- data/spec/fixtures/readme/Project ReadMe b/data/spec/fixtures/readme/Project → ReadMe +0 -0
- data/spec/fixtures/readme/README +0 -0
- data/spec/fixtures/readme/Readme.markdown +0 -0
- data/spec/fixtures/utf8_gem/README +210 -0
- data/spec/gem_spec_details_spec.rb +167 -0
- data/spec/license_file_spec.rb +129 -0
- data/spec/spec_helper.rb +10 -0
- metadata +159 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
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.
|
21
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
The Ruby License
|
2
|
+
|
3
|
+
Ruby is copyrighted free software by <COPYRIGHT HOLDER>.
|
4
|
+
You can redistribute it and/or modify it under either the terms of the GPL
|
5
|
+
(see COPYING.txt file), or the conditions below:
|
6
|
+
|
7
|
+
1. You may make and give away verbatim copies of the source form of the
|
8
|
+
software without restriction, provided that you duplicate all of the
|
9
|
+
original copyright notices and associated disclaimers.
|
10
|
+
|
11
|
+
2. You may modify your copy of the software in any way, provided that
|
12
|
+
you do at least ONE of the following:
|
13
|
+
|
14
|
+
a) place your modifications in the Public Domain or otherwise
|
15
|
+
make them Freely Available, such as by posting said
|
16
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
17
|
+
the author to include your modifications in the software.
|
18
|
+
|
19
|
+
b) use the modified software only within your corporation or
|
20
|
+
organization.
|
21
|
+
|
22
|
+
c) rename any non-standard executables so the names do not conflict
|
23
|
+
with standard executables, which must also be provided.
|
24
|
+
|
25
|
+
d) make other distribution arrangements with the author.
|
26
|
+
|
27
|
+
3. You may distribute the software in object code or executable
|
28
|
+
form, provided that you do at least ONE of the following:
|
29
|
+
|
30
|
+
a) distribute the executables and library files of the software,
|
31
|
+
together with instructions (in the manual page or equivalent)
|
32
|
+
on where to get the original distribution.
|
33
|
+
|
34
|
+
b) accompany the distribution with the machine-readable source of
|
35
|
+
the software.
|
36
|
+
|
37
|
+
c) give non-standard executables non-standard names, with
|
38
|
+
instructions on where to get the original software distribution.
|
39
|
+
|
40
|
+
d) make other distribution arrangements with the author.
|
41
|
+
|
42
|
+
4. You may modify and include the part of the software into any other
|
43
|
+
software (possibly commercial). But some files in the distribution
|
44
|
+
are not written by the author, so that they are not under this terms.
|
45
|
+
|
46
|
+
They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
|
47
|
+
files under the ./missing directory. See each file for the copying
|
48
|
+
condition.
|
49
|
+
|
50
|
+
5. The scripts and library files supplied as input to or produced as
|
51
|
+
output from the software do not automatically fall under the
|
52
|
+
copyright of the software, but belong to whomever generated them,
|
53
|
+
and may be sold commercially, and may be aggregated with this
|
54
|
+
software.
|
55
|
+
|
56
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
57
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
58
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
59
|
+
PURPOSE.
|
60
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Jacob Maine
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
22
|
+
|
@@ -0,0 +1,222 @@
|
|
1
|
+
= Active Record -- Object-relational mapping put on rails
|
2
|
+
|
3
|
+
Active Record connects classes to relational database tables to establish an
|
4
|
+
almost zero-configuration persistence layer for applications. The library
|
5
|
+
provides a base class that, when subclassed, sets up a mapping between the new
|
6
|
+
class and an existing table in the database. In context of an application,
|
7
|
+
these classes are commonly referred to as *models*. Models can also be
|
8
|
+
connected to other models; this is done by defining *associations*.
|
9
|
+
|
10
|
+
Active Record relies heavily on naming in that it uses class and association
|
11
|
+
names to establish mappings between respective database tables and foreign key
|
12
|
+
columns. Although these mappings can be defined explicitly, it's recommended
|
13
|
+
to follow naming conventions, especially when getting started with the
|
14
|
+
library.
|
15
|
+
|
16
|
+
A short rundown of some of the major features:
|
17
|
+
|
18
|
+
* Automated mapping between classes and tables, attributes and columns.
|
19
|
+
|
20
|
+
class Product < ActiveRecord::Base
|
21
|
+
end
|
22
|
+
|
23
|
+
The Product class is automatically mapped to the table named "products",
|
24
|
+
which might look like this:
|
25
|
+
|
26
|
+
CREATE TABLE products (
|
27
|
+
id int(11) NOT NULL auto_increment,
|
28
|
+
name varchar(255),
|
29
|
+
PRIMARY KEY (id)
|
30
|
+
);
|
31
|
+
|
32
|
+
This would also define the following accessors: `Product#name` and
|
33
|
+
`Product#name=(new_name)`
|
34
|
+
|
35
|
+
{Learn more}[link:classes/ActiveRecord/Base.html]
|
36
|
+
|
37
|
+
|
38
|
+
* Associations between objects defined by simple class methods.
|
39
|
+
|
40
|
+
class Firm < ActiveRecord::Base
|
41
|
+
has_many :clients
|
42
|
+
has_one :account
|
43
|
+
belongs_to :conglomerate
|
44
|
+
end
|
45
|
+
|
46
|
+
{Learn more}[link:classes/ActiveRecord/Associations/ClassMethods.html]
|
47
|
+
|
48
|
+
|
49
|
+
* Aggregations of value objects.
|
50
|
+
|
51
|
+
class Account < ActiveRecord::Base
|
52
|
+
composed_of :balance, :class_name => "Money",
|
53
|
+
:mapping => %w(balance amount)
|
54
|
+
composed_of :address,
|
55
|
+
:mapping => [%w(address_street street), %w(address_city city)]
|
56
|
+
end
|
57
|
+
|
58
|
+
{Learn more}[link:classes/ActiveRecord/Aggregations/ClassMethods.html]
|
59
|
+
|
60
|
+
|
61
|
+
* Validation rules that can differ for new or existing objects.
|
62
|
+
|
63
|
+
class Account < ActiveRecord::Base
|
64
|
+
validates_presence_of :subdomain, :name, :email_address, :password
|
65
|
+
validates_uniqueness_of :subdomain
|
66
|
+
validates_acceptance_of :terms_of_service, :on => :create
|
67
|
+
validates_confirmation_of :password, :email_address, :on => :create
|
68
|
+
end
|
69
|
+
|
70
|
+
{Learn more}[link:classes/ActiveRecord/Validations.html]
|
71
|
+
|
72
|
+
|
73
|
+
* Callbacks available for the entire life cycle (instantiation, saving, destroying, validating, etc.)
|
74
|
+
|
75
|
+
class Person < ActiveRecord::Base
|
76
|
+
before_destroy :invalidate_payment_plan
|
77
|
+
# the `invalidate_payment_plan` method gets called just before Person#destroy
|
78
|
+
end
|
79
|
+
|
80
|
+
{Learn more}[link:classes/ActiveRecord/Callbacks.html]
|
81
|
+
|
82
|
+
|
83
|
+
* Observers that react to changes in a model
|
84
|
+
|
85
|
+
class CommentObserver < ActiveRecord::Observer
|
86
|
+
def after_create(comment) # is called just after Comment#save
|
87
|
+
Notifications.deliver_new_comment("david@loudthinking.com", comment)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
{Learn more}[link:classes/ActiveRecord/Observer.html]
|
92
|
+
|
93
|
+
|
94
|
+
* Inheritance hierarchies
|
95
|
+
|
96
|
+
class Company < ActiveRecord::Base; end
|
97
|
+
class Firm < Company; end
|
98
|
+
class Client < Company; end
|
99
|
+
class PriorityClient < Client; end
|
100
|
+
|
101
|
+
{Learn more}[link:classes/ActiveRecord/Base.html]
|
102
|
+
|
103
|
+
|
104
|
+
* Transactions
|
105
|
+
|
106
|
+
# Database transaction
|
107
|
+
Account.transaction do
|
108
|
+
david.withdrawal(100)
|
109
|
+
mary.deposit(100)
|
110
|
+
end
|
111
|
+
|
112
|
+
{Learn more}[link:classes/ActiveRecord/Transactions/ClassMethods.html]
|
113
|
+
|
114
|
+
|
115
|
+
* Reflections on columns, associations, and aggregations
|
116
|
+
|
117
|
+
reflection = Firm.reflect_on_association(:clients)
|
118
|
+
reflection.klass # => Client (class)
|
119
|
+
Firm.columns # Returns an array of column descriptors for the firms table
|
120
|
+
|
121
|
+
{Learn more}[link:classes/ActiveRecord/Reflection/ClassMethods.html]
|
122
|
+
|
123
|
+
|
124
|
+
* Database abstraction through simple adapters
|
125
|
+
|
126
|
+
# connect to SQLite3
|
127
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "dbfile.sqlite3")
|
128
|
+
|
129
|
+
# connect to MySQL with authentication
|
130
|
+
ActiveRecord::Base.establish_connection(
|
131
|
+
:adapter => "mysql",
|
132
|
+
:host => "localhost",
|
133
|
+
:username => "me",
|
134
|
+
:password => "secret",
|
135
|
+
:database => "activerecord"
|
136
|
+
)
|
137
|
+
|
138
|
+
{Learn more}[link:classes/ActiveRecord/Base.html] and read about the built-in support for
|
139
|
+
MySQL[link:classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html],
|
140
|
+
PostgreSQL[link:classes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter.html], and
|
141
|
+
SQLite3[link:classes/ActiveRecord/ConnectionAdapters/SQLite3Adapter.html].
|
142
|
+
|
143
|
+
|
144
|
+
* Logging support for Log4r[http://log4r.sourceforge.net] and Logger[http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc]
|
145
|
+
|
146
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
147
|
+
ActiveRecord::Base.logger = Log4r::Logger.new("Application Log")
|
148
|
+
|
149
|
+
|
150
|
+
* Database agnostic schema management with Migrations
|
151
|
+
|
152
|
+
class AddSystemSettings < ActiveRecord::Migration
|
153
|
+
def self.up
|
154
|
+
create_table :system_settings do |t|
|
155
|
+
t.string :name
|
156
|
+
t.string :label
|
157
|
+
t.text :value
|
158
|
+
t.string :type
|
159
|
+
t.integer :position
|
160
|
+
end
|
161
|
+
|
162
|
+
SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.down
|
166
|
+
drop_table :system_settings
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
{Learn more}[link:classes/ActiveRecord/Migration.html]
|
171
|
+
|
172
|
+
|
173
|
+
== Philosophy
|
174
|
+
|
175
|
+
Active Record is an implementation of the object-relational mapping (ORM)
|
176
|
+
pattern[http://www.martinfowler.com/eaaCatalog/activeRecord.html] by the same
|
177
|
+
name described by Martin Fowler:
|
178
|
+
|
179
|
+
"An object that wraps a row in a database table or view,
|
180
|
+
encapsulates the database access, and adds domain logic on that data."
|
181
|
+
|
182
|
+
Active Record attempts to provide a coherent wrapper as a solution for the inconvenience that is
|
183
|
+
object-relational mapping. The prime directive for this mapping has been to minimize
|
184
|
+
the amount of code needed to build a real-world domain model. This is made possible
|
185
|
+
by relying on a number of conventions that make it easy for Active Record to infer
|
186
|
+
complex relations and structures from a minimal amount of explicit direction.
|
187
|
+
|
188
|
+
Convention over Configuration:
|
189
|
+
* No XML-files!
|
190
|
+
* Lots of reflection and run-time extension
|
191
|
+
* Magic is not inherently a bad word
|
192
|
+
|
193
|
+
Admit the Database:
|
194
|
+
* Lets you drop down to SQL for odd cases and performance
|
195
|
+
* Doesn't attempt to duplicate or replace data definitions
|
196
|
+
|
197
|
+
|
198
|
+
== Download and installation
|
199
|
+
|
200
|
+
The latest version of Active Record can be installed with Rubygems:
|
201
|
+
|
202
|
+
% [sudo] gem install activerecord
|
203
|
+
|
204
|
+
Source code can be downloaded as part of the Rails project on GitHub
|
205
|
+
|
206
|
+
* http://github.com/rails/rails/tree/master/activerecord/
|
207
|
+
|
208
|
+
|
209
|
+
== License
|
210
|
+
|
211
|
+
Active Record is released under the MIT license.
|
212
|
+
|
213
|
+
|
214
|
+
== Support
|
215
|
+
|
216
|
+
API documentation is at
|
217
|
+
|
218
|
+
* http://api.rubyonrails.com
|
219
|
+
|
220
|
+
Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
|
221
|
+
|
222
|
+
* https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets
|
@@ -0,0 +1,210 @@
|
|
1
|
+
= Project: Builder
|
2
|
+
|
3
|
+
== Goal
|
4
|
+
|
5
|
+
Provide a simple way to create XML markup and data structures.
|
6
|
+
|
7
|
+
== Classes
|
8
|
+
|
9
|
+
Builder::XmlMarkup:: Generate XML markup notiation
|
10
|
+
Builder::XmlEvents:: Generate XML events (i.e. SAX-like)
|
11
|
+
|
12
|
+
<b>Notes</b>::
|
13
|
+
|
14
|
+
* An <tt>Builder::XmlTree</tt> class to generate XML tree
|
15
|
+
(i.e. DOM-like) structures is also planned, but not yet implemented.
|
16
|
+
Also, the events builder is currently lagging the markup builder in
|
17
|
+
features.
|
18
|
+
|
19
|
+
== Usage
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
require_gem 'builder', '~> 2.0'
|
23
|
+
|
24
|
+
builder = Builder::XmlMarkup.new
|
25
|
+
xml = builder.person { |b| b.name("Jim"); b.phone("555-1234") }
|
26
|
+
xml #=> <person><name>Jim</name><phone>555-1234</phone></person>
|
27
|
+
|
28
|
+
or
|
29
|
+
|
30
|
+
require 'rubygems'
|
31
|
+
require_gem 'builder'
|
32
|
+
|
33
|
+
builder = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>2)
|
34
|
+
builder.person { |b| b.name("Jim"); b.phone("555-1234") }
|
35
|
+
#
|
36
|
+
# Prints:
|
37
|
+
# <person>
|
38
|
+
# <name>Jim</name>
|
39
|
+
# <phone>555-1234</phone>
|
40
|
+
# </person>
|
41
|
+
|
42
|
+
== Compatibility
|
43
|
+
|
44
|
+
=== Version 2.0.0 Compatibility Changes
|
45
|
+
|
46
|
+
Version 2.0.0 introduces automatically escaped attribute values for
|
47
|
+
the first time. Versions prior to 2.0.0 did not insert escape
|
48
|
+
characters into attribute values in the XML markup. This allowed
|
49
|
+
attribute values to explicitly reference entities, which was
|
50
|
+
occasionally used by a small number of developers. Since strings
|
51
|
+
could always be explicitly escaped by hand, this was not a major
|
52
|
+
restriction in functionality.
|
53
|
+
|
54
|
+
However, it did suprise most users of builder. Since the body text is
|
55
|
+
normally escaped, everybody expected the attribute values to be
|
56
|
+
escaped as well. Escaped attribute values were the number one support
|
57
|
+
request on the 1.x Builder series.
|
58
|
+
|
59
|
+
Starting with Builder version 2.0.0, all attribute values expressed as
|
60
|
+
strings will be processed and the appropriate characters will be
|
61
|
+
escaped (e.g. "&" will be tranlated to "&"). Attribute values
|
62
|
+
that are expressed as Symbol values will not be processed for escaped
|
63
|
+
characters and will be unchanged in output. (Yes, this probably counts
|
64
|
+
as Symbol abuse, but the convention is convenient and flexible).
|
65
|
+
|
66
|
+
Example:
|
67
|
+
|
68
|
+
xml = Builder::XmlMarkup.new
|
69
|
+
xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There")
|
70
|
+
xml.target! =>
|
71
|
+
<sample escaped="This&That" unescaped="Here&There"/>
|
72
|
+
|
73
|
+
=== Version 1.0.0 Compatibility Changes
|
74
|
+
|
75
|
+
Version 1.0.0 introduces some changes that are not backwards
|
76
|
+
compatible with earlier releases of builder. The main areas of
|
77
|
+
incompatibility are:
|
78
|
+
|
79
|
+
* Keyword based arguments to +new+ (rather than positional based). It
|
80
|
+
was found that a developer would often like to specify indentation
|
81
|
+
without providing an explicit target, or specify a target without
|
82
|
+
indentation. Keyword based arguments handle this situation nicely.
|
83
|
+
|
84
|
+
* Builder must now be an explicit target for markup tags. Instead of
|
85
|
+
writing
|
86
|
+
|
87
|
+
xml_markup = Builder::XmlMarkup.new
|
88
|
+
xml_markup.div { strong("text") }
|
89
|
+
|
90
|
+
you need to write
|
91
|
+
|
92
|
+
xml_markup = Builder::XmlMarkup.new
|
93
|
+
xml_markup.div { xml_markup.strong("text") }
|
94
|
+
|
95
|
+
* The builder object is passed as a parameter to all nested markup
|
96
|
+
blocks. This allows you to create a short alias for the builder
|
97
|
+
object that can be used within the block. For example, the previous
|
98
|
+
example can be written as:
|
99
|
+
|
100
|
+
xml_markup = Builder::XmlMarkup.new
|
101
|
+
xml_markup.div { |xml| xml.strong("text") }
|
102
|
+
|
103
|
+
* If you have both a pre-1.0 and a post-1.0 gem of builder installed,
|
104
|
+
you can choose which version to use through the RubyGems
|
105
|
+
+require_gem+ facility.
|
106
|
+
|
107
|
+
require_gem 'builder', "~> 0.0" # Gets the old version
|
108
|
+
require_gem 'builder', "~> 1.0" # Gets the new version
|
109
|
+
|
110
|
+
== Features
|
111
|
+
|
112
|
+
* XML Comments are supported ...
|
113
|
+
|
114
|
+
xml_markup.comment! "This is a comment"
|
115
|
+
#=> <!-- This is a comment -->
|
116
|
+
|
117
|
+
* XML processing instructions are supported ...
|
118
|
+
|
119
|
+
xml_markup.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
|
120
|
+
#=> <?xml version="1.0" encoding="UTF-8"?>
|
121
|
+
|
122
|
+
If the processing instruction is omitted, it defaults to "xml".
|
123
|
+
When the processing instruction is "xml", the defaults attributes
|
124
|
+
are:
|
125
|
+
|
126
|
+
<b>version</b>:: 1.0
|
127
|
+
<b>encoding</b>:: "UTF-8"
|
128
|
+
|
129
|
+
* XML entity declarations are now supported to a small degree.
|
130
|
+
|
131
|
+
xml_markup.declare! :DOCTYPE, :chapter, :SYSTEM, "../dtds/chapter.dtd"
|
132
|
+
#=> <!DOCTYPE chapter SYSTEM "../dtds/chapter.dtd">
|
133
|
+
|
134
|
+
The parameters to a declare! method must be either symbols or
|
135
|
+
strings. Symbols are inserted without quotes, and strings are
|
136
|
+
inserted with double quotes. Attribute-like arguments in hashes are
|
137
|
+
not allowed.
|
138
|
+
|
139
|
+
If you need to have an argument to declare! be inserted without
|
140
|
+
quotes, but the arguement does not conform to the typical Ruby
|
141
|
+
syntax for symbols, then use the :"string" form to specify a symbol.
|
142
|
+
|
143
|
+
For example:
|
144
|
+
|
145
|
+
xml_markup.declare! :ELEMENT, :chapter, :"(title,para+)"
|
146
|
+
#=> <!ELEMENT chapter (title,para+)>
|
147
|
+
|
148
|
+
Nested entity declarations are allowed. For example:
|
149
|
+
|
150
|
+
@xml_markup.declare! :DOCTYPE, :chapter do |x|
|
151
|
+
x.declare! :ELEMENT, :chapter, :"(title,para+)"
|
152
|
+
x.declare! :ELEMENT, :title, :"(#PCDATA)"
|
153
|
+
x.declare! :ELEMENT, :para, :"(#PCDATA)"
|
154
|
+
end
|
155
|
+
|
156
|
+
#=>
|
157
|
+
|
158
|
+
<!DOCTYPE chapter [
|
159
|
+
<!ELEMENT chapter (title,para+)>
|
160
|
+
<!ELEMENT title (#PCDATA)>
|
161
|
+
<!ELEMENT para (#PCDATA)>
|
162
|
+
]>
|
163
|
+
|
164
|
+
* Some support for XML namespaces is now available. If the first
|
165
|
+
argument to a tag call is a symbol, it will be joined to the tag to
|
166
|
+
produce a namespace:tag combination. It is easier to show this than
|
167
|
+
describe it.
|
168
|
+
|
169
|
+
xml.SOAP :Envelope do ... end
|
170
|
+
|
171
|
+
Just put a space before the colon in a namespace to produce the
|
172
|
+
right form for builder (e.g. "<tt>SOAP:Envelope</tt>" =>
|
173
|
+
"<tt>xml.SOAP :Envelope</tt>")
|
174
|
+
|
175
|
+
* String attribute values are <em>now</em> escaped by default by
|
176
|
+
Builder (<b>NOTE:</b> this is _new_ behavior as of version 2.0).
|
177
|
+
|
178
|
+
However, occasionally you need to use entities in attribute values.
|
179
|
+
Using a symbols (rather than a string) for an attribute value will
|
180
|
+
cause Builder to not run its quoting/escaping algorithm on that
|
181
|
+
particular value.
|
182
|
+
|
183
|
+
(<b>Note:</b> The +escape_attrs+ option for builder is now
|
184
|
+
obsolete).
|
185
|
+
|
186
|
+
Example:
|
187
|
+
|
188
|
+
xml = Builder::XmlMarkup.new
|
189
|
+
xml.sample(:escaped=>"This&That", :unescaped=>:"Here&There")
|
190
|
+
xml.target! =>
|
191
|
+
<sample escaped="This&That" unescaped="Here&There"/>
|
192
|
+
|
193
|
+
* UTF-8 Support
|
194
|
+
|
195
|
+
Builder correctly translates UTF-8 characters into valid XML. (New
|
196
|
+
in version 2.0.0). Thanks to Sam Ruby for the translation code.
|
197
|
+
|
198
|
+
Example:
|
199
|
+
|
200
|
+
xml = Builder::Markup.new
|
201
|
+
xml.sample("I?t?rn?ti?n?l")
|
202
|
+
xml.target! =>
|
203
|
+
"<sample>Iñtërnâtiônàl</sample>"
|
204
|
+
|
205
|
+
== Contact
|
206
|
+
|
207
|
+
Author:: Jim Weirich
|
208
|
+
Email:: jim@weirichhouse.org
|
209
|
+
Home Page:: http://onestepback.org
|
210
|
+
License:: MIT Licence (http://www.opensource.org/licenses/mit-license.html)
|