Skip to content

Commit 47a7bc7

Browse files
committed
rufo formatting
1 parent 094ecb1 commit 47a7bc7

File tree

2 files changed

+98
-99
lines changed

2 files changed

+98
-99
lines changed

lib/nokogiri/xml/builder.rb

+30-30
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ module XML
213213
# xml.foo
214214
# end
215215
# end
216-
#
216+
#
217217
# puts builder.to_xml
218218
#
219219
# Will output this xml:
@@ -250,7 +250,7 @@ class Builder
250250
# xml.awesome # add the "awesome" tag below "some_tag"
251251
# end
252252
#
253-
def self.with root, &block
253+
def self.with(root, &block)
254254
new({}, root, &block)
255255
end
256256

@@ -263,31 +263,30 @@ def self.with root, &block
263263
# Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
264264
# ...
265265
# end
266-
def initialize options = {}, root = nil, &block
267-
266+
def initialize(options = {}, root = nil, &block)
268267
if root
269-
@doc = root.document
268+
@doc = root.document
270269
@parent = root
271270
else
272-
namespace = self.class.name.split('::')
273-
namespace[-1] = 'Document'
274-
@doc = eval(namespace.join('::')).new
275-
@parent = @doc
271+
namespace = self.class.name.split("::")
272+
namespace[-1] = "Document"
273+
@doc = eval(namespace.join("::")).new
274+
@parent = @doc
276275
end
277276

278-
@context = nil
279-
@arity = nil
280-
@ns = nil
277+
@context = nil
278+
@arity = nil
279+
@ns = nil
281280

282-
options.each do |k,v|
281+
options.each do |k, v|
283282
@doc.send(:"#{k}=", v)
284283
end
285284

286285
return unless block_given?
287286

288287
@arity = block.arity
289288
if @arity <= 0
290-
@context = eval('self', block.binding)
289+
@context = eval("self", block.binding)
291290
instance_eval(&block)
292291
else
293292
yield self
@@ -298,26 +297,26 @@ def initialize options = {}, root = nil, &block
298297

299298
###
300299
# Create a Text Node with content of +string+
301-
def text string
300+
def text(string)
302301
insert @doc.create_text_node(string)
303302
end
304303

305304
###
306305
# Create a CDATA Node with content of +string+
307-
def cdata string
306+
def cdata(string)
308307
insert doc.create_cdata(string)
309308
end
310309

311310
###
312311
# Create a Comment Node with content of +string+
313-
def comment string
312+
def comment(string)
314313
insert doc.create_comment(string)
315314
end
316315

317316
###
318317
# Build a tag that is associated with namespace +ns+. Raises an
319318
# ArgumentError if +ns+ has not been defined higher in the tree.
320-
def [] ns
319+
def [](ns)
321320
if @parent != @doc
322321
@ns = @parent.namespace_definitions.find { |x| x.prefix == ns.to_s }
323322
end
@@ -348,15 +347,15 @@ def to_xml(*args)
348347

349348
###
350349
# Append the given raw XML +string+ to the document
351-
def << string
350+
def <<(string)
352351
@doc.fragment(string).children.each { |x| insert(x) }
353352
end
354353

355-
def method_missing method, *args, &block # :nodoc:
354+
def method_missing(method, *args, &block) # :nodoc:
356355
if @context && @context.respond_to?(method)
357356
@context.send(method, *args, &block)
358357
else
359-
node = @doc.create_element(method.to_s.sub(/[_!]$/, ''),*args) { |n|
358+
node = @doc.create_element(method.to_s.sub(/[_!]$/, ""), *args) { |n|
360359
# Set up the namespace
361360
if @ns.is_a? Nokogiri::XML::Namespace
362361
n.namespace = @ns
@@ -377,13 +376,14 @@ def method_missing method, *args, &block # :nodoc:
377376
end
378377

379378
private
379+
380380
###
381381
# Insert +node+ as a child of the current Node
382382
def insert(node, &block)
383383
node = @parent.add_child(node)
384384
if block_given?
385385
old_parent = @parent
386-
@parent = node
386+
@parent = node
387387
@arity ||= block.arity
388388
if @arity <= 0
389389
instance_eval(&block)
@@ -396,36 +396,36 @@ def insert(node, &block)
396396
end
397397

398398
class NodeBuilder # :nodoc:
399-
def initialize node, doc_builder
399+
def initialize(node, doc_builder)
400400
@node = node
401401
@doc_builder = doc_builder
402402
end
403403

404-
def []= k, v
404+
def []=(k, v)
405405
@node[k] = v
406406
end
407407

408-
def [] k
408+
def [](k)
409409
@node[k]
410410
end
411411

412412
def method_missing(method, *args, &block)
413413
opts = args.last.is_a?(Hash) ? args.pop : {}
414414
case method.to_s
415415
when /^(.*)!$/
416-
@node['id'] = $1
416+
@node["id"] = $1
417417
@node.content = args.first if args.first
418418
when /^(.*)=/
419419
@node[$1] = args.first
420420
else
421-
@node['class'] =
422-
((@node['class'] || '').split(/\s/) + [method.to_s]).join(' ')
421+
@node["class"] =
422+
((@node["class"] || "").split(/\s/) + [method.to_s]).join(" ")
423423
@node.content = args.first if args.first
424424
end
425425

426426
# Assign any extra options
427-
opts.each do |k,v|
428-
@node[k.to_s] = ((@node[k.to_s] || '').split(/\s/) + [v]).join(' ')
427+
opts.each do |k, v|
428+
@node[k.to_s] = ((@node[k.to_s] || "").split(/\s/) + [v]).join(" ")
429429
end
430430

431431
if block_given?

0 commit comments

Comments
 (0)