@@ -213,7 +213,7 @@ module XML
213
213
# xml.foo
214
214
# end
215
215
# end
216
- #
216
+ #
217
217
# puts builder.to_xml
218
218
#
219
219
# Will output this xml:
@@ -250,7 +250,7 @@ class Builder
250
250
# xml.awesome # add the "awesome" tag below "some_tag"
251
251
# end
252
252
#
253
- def self . with root , &block
253
+ def self . with ( root , &block )
254
254
new ( { } , root , &block )
255
255
end
256
256
@@ -263,31 +263,30 @@ def self.with root, &block
263
263
# Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
264
264
# ...
265
265
# end
266
- def initialize options = { } , root = nil , &block
267
-
266
+ def initialize ( options = { } , root = nil , &block )
268
267
if root
269
- @doc = root . document
268
+ @doc = root . document
270
269
@parent = root
271
270
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
276
275
end
277
276
278
- @context = nil
279
- @arity = nil
280
- @ns = nil
277
+ @context = nil
278
+ @arity = nil
279
+ @ns = nil
281
280
282
- options . each do |k , v |
281
+ options . each do |k , v |
283
282
@doc . send ( :"#{ k } =" , v )
284
283
end
285
284
286
285
return unless block_given?
287
286
288
287
@arity = block . arity
289
288
if @arity <= 0
290
- @context = eval ( ' self' , block . binding )
289
+ @context = eval ( " self" , block . binding )
291
290
instance_eval ( &block )
292
291
else
293
292
yield self
@@ -298,26 +297,26 @@ def initialize options = {}, root = nil, &block
298
297
299
298
###
300
299
# Create a Text Node with content of +string+
301
- def text string
300
+ def text ( string )
302
301
insert @doc . create_text_node ( string )
303
302
end
304
303
305
304
###
306
305
# Create a CDATA Node with content of +string+
307
- def cdata string
306
+ def cdata ( string )
308
307
insert doc . create_cdata ( string )
309
308
end
310
309
311
310
###
312
311
# Create a Comment Node with content of +string+
313
- def comment string
312
+ def comment ( string )
314
313
insert doc . create_comment ( string )
315
314
end
316
315
317
316
###
318
317
# Build a tag that is associated with namespace +ns+. Raises an
319
318
# ArgumentError if +ns+ has not been defined higher in the tree.
320
- def [] ns
319
+ def []( ns )
321
320
if @parent != @doc
322
321
@ns = @parent . namespace_definitions . find { |x | x . prefix == ns . to_s }
323
322
end
@@ -348,15 +347,15 @@ def to_xml(*args)
348
347
349
348
###
350
349
# Append the given raw XML +string+ to the document
351
- def << string
350
+ def <<( string )
352
351
@doc . fragment ( string ) . children . each { |x | insert ( x ) }
353
352
end
354
353
355
- def method_missing method , *args , &block # :nodoc:
354
+ def method_missing ( method , *args , &block ) # :nodoc:
356
355
if @context && @context . respond_to? ( method )
357
356
@context . send ( method , *args , &block )
358
357
else
359
- node = @doc . create_element ( method . to_s . sub ( /[_!]$/ , '' ) , *args ) { |n |
358
+ node = @doc . create_element ( method . to_s . sub ( /[_!]$/ , "" ) , *args ) { |n |
360
359
# Set up the namespace
361
360
if @ns . is_a? Nokogiri ::XML ::Namespace
362
361
n . namespace = @ns
@@ -377,13 +376,14 @@ def method_missing method, *args, &block # :nodoc:
377
376
end
378
377
379
378
private
379
+
380
380
###
381
381
# Insert +node+ as a child of the current Node
382
382
def insert ( node , &block )
383
383
node = @parent . add_child ( node )
384
384
if block_given?
385
385
old_parent = @parent
386
- @parent = node
386
+ @parent = node
387
387
@arity ||= block . arity
388
388
if @arity <= 0
389
389
instance_eval ( &block )
@@ -396,36 +396,36 @@ def insert(node, &block)
396
396
end
397
397
398
398
class NodeBuilder # :nodoc:
399
- def initialize node , doc_builder
399
+ def initialize ( node , doc_builder )
400
400
@node = node
401
401
@doc_builder = doc_builder
402
402
end
403
403
404
- def []= k , v
404
+ def []=( k , v )
405
405
@node [ k ] = v
406
406
end
407
407
408
- def [] k
408
+ def []( k )
409
409
@node [ k ]
410
410
end
411
411
412
412
def method_missing ( method , *args , &block )
413
413
opts = args . last . is_a? ( Hash ) ? args . pop : { }
414
414
case method . to_s
415
415
when /^(.*)!$/
416
- @node [ 'id' ] = $1
416
+ @node [ "id" ] = $1
417
417
@node . content = args . first if args . first
418
418
when /^(.*)=/
419
419
@node [ $1] = args . first
420
420
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 ( " " )
423
423
@node . content = args . first if args . first
424
424
end
425
425
426
426
# 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 ( " " )
429
429
end
430
430
431
431
if block_given?
0 commit comments