ratom-nokogiri 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c899ba607457b5fd43308f1b4cd5f70cd90c0a77
4
- data.tar.gz: 0cb7d18ce58a75a08331dea8efae5632abd592d9
3
+ metadata.gz: 0c1f4562fd7cda57a9717866ced5a5172cd4f9b5
4
+ data.tar.gz: e770cfb1f30500c7d878ab2d2cb1d9be3bca14e2
5
5
  SHA512:
6
- metadata.gz: 2c2f6cad975bdb7f1cbee58a6518c4bc882a1327d83d2235593dddcbea2b86d064c2a4174f39975b1ebcddb6fa908975c1851709b92aa654d604caec603bea77
7
- data.tar.gz: 61177c2b8d782e83c58d2ba6d4940b2618fc99d96316682c20d466c16c02d11689671bfef602cd18dc2ae596e66d82fdccf615b92fbe39c4746d3b28b5f9f5f4
6
+ metadata.gz: 9955c94696fda7c38f0d41842806fe616409e8f47f0a0f3af2c3cb968e5b2d4b8b5c9807650e3b65ad3212035d5182231066e3f4a2e6ceb09151b5fec9bc560f
7
+ data.tar.gz: d7c33576255d45aca2d6357d1989d5cae029b8145513a458af122ac2a5072471699db012677e56a5e9503e003dfdd21f0fd4c7406c0dea0465b658977a129c2e
data/README.rdoc CHANGED
@@ -3,8 +3,8 @@
3
3
  rAtom is a library for working with the Atom Syndication Format and
4
4
  the Atom Publishing Protocol (APP).
5
5
 
6
- * Built using libxml so it is _much_ faster than a REXML based library.
7
- * Uses the libxml pull parser so it has much lighter memory usage.
6
+ * Built using nokogiri so it is _much_ faster than a REXML based library.
7
+ * Uses the nokogiri reader parser so it has much lighter memory usage.
8
8
  * Supports {RFC 5005}[http://www.ietf.org/rfc/rfc5005.txt] for feed pagination.
9
9
 
10
10
  rAtom was originally built to support the communication between a number of applications
data/lib/atom.rb CHANGED
@@ -17,10 +17,10 @@ module Atom # :nodoc:
17
17
  module Pub
18
18
  NAMESPACE = 'http://www.w3.org/2007/app'
19
19
  end
20
-
20
+
21
21
  # Raised when a Serialization Error occurs.
22
22
  class SerializationError < StandardError; end
23
-
23
+
24
24
  # Provides support for reading and writing simple extensions as defined by the Atom Syndication Format.
25
25
  #
26
26
  # A Simple extension is an element from a non-atom namespace that has no attributes and only contains
@@ -60,7 +60,7 @@ module Atom # :nodoc:
60
60
  key = "{#{namespace},#{localname}}"
61
61
  @simple_extensions[key] ||= ValueProxy.new
62
62
  end
63
-
63
+
64
64
  class ValueProxy < DelegateClass(Array)
65
65
  attr_accessor :as_attribute
66
66
  def initialize
@@ -69,7 +69,7 @@ module Atom # :nodoc:
69
69
  end
70
70
  end
71
71
  end
72
-
72
+
73
73
  # Represents a Generator as defined by the Atom Syndication Format specification.
74
74
  #
75
75
  # The generator identifies an agent or engine used to a produce a feed.
@@ -77,10 +77,10 @@ module Atom # :nodoc:
77
77
  # See also http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.generator
78
78
  class Generator
79
79
  include Xml::Parseable
80
-
80
+
81
81
  attr_accessor :name
82
82
  attribute :uri, :version
83
-
83
+
84
84
  # Initialize a new Generator.
85
85
  #
86
86
  # +xml+:: An XML::Reader object.
@@ -97,10 +97,10 @@ module Atom # :nodoc:
97
97
  else
98
98
  raise ArgumentError, "Got #{o.class} but expected a Hash or XML::Reader"
99
99
  end
100
-
100
+
101
101
  yield(self) if block_given?
102
102
  end
103
-
103
+
104
104
  def to_xml(builder = nil, name = 'generator', namespace = nil, namespace_handler = nil)
105
105
  builder ||= Nokogiri::XML::Builder.new
106
106
  attrs = {}
@@ -111,15 +111,15 @@ module Atom # :nodoc:
111
111
  builder.doc.root
112
112
  end
113
113
  end
114
-
114
+
115
115
  # Represents a Category as defined by the Atom Syndication Format specification.
116
116
  #
117
- #
117
+ #
118
118
  class Category
119
119
  include Atom::Xml::Parseable
120
120
  include SimpleExtensions
121
121
  attribute :label, :scheme, :term
122
-
122
+
123
123
  def initialize(o = {})
124
124
  case o
125
125
  when Nokogiri::XML::Reader
@@ -131,11 +131,11 @@ module Atom # :nodoc:
131
131
  else
132
132
  raise ArgumentError, "Got #{o.class} but expected a Hash or XML::Reader"
133
133
  end
134
-
134
+
135
135
  yield(self) if block_given?
136
136
  end
137
137
  end
138
-
138
+
139
139
  # Represents a Person as defined by the Atom Syndication Format specification.
140
140
  #
141
141
  # A Person is used for all author and contributor attributes.
@@ -145,7 +145,7 @@ module Atom # :nodoc:
145
145
  class Person
146
146
  include Xml::Parseable
147
147
  element :name, :uri, :email
148
-
148
+
149
149
  # Initialize a new person.
150
150
  #
151
151
  # +o+:: An XML::Reader object or a hash. Valid hash keys are +:name+, +:uri+ and +:email+.
@@ -161,15 +161,15 @@ module Atom # :nodoc:
161
161
  else
162
162
  raise ArgumentError, "Got #{o.class} but expected a Hash or XML::Reader"
163
163
  end
164
-
164
+
165
165
  yield(self) if block_given?
166
166
  end
167
-
167
+
168
168
  def inspect
169
169
  "<Atom::Person name:'#{name}' uri:'#{uri}' email:'#{email}"
170
170
  end
171
171
  end
172
-
172
+
173
173
  class Content # :nodoc:
174
174
  def self.parse(xml)
175
175
  if xml.attributes['src'] && !xml.attributes['src'].empty?
@@ -179,7 +179,7 @@ module Atom # :nodoc:
179
179
  parser.new(xml)
180
180
  end
181
181
  end
182
-
182
+
183
183
  # This is the base class for all content within an atom document.
184
184
  #
185
185
  # Content can be Text, Html or Xhtml.
@@ -187,15 +187,15 @@ module Atom # :nodoc:
187
187
  # A Content object can be treated as a String with type and xml_lang
188
188
  # attributes.
189
189
  #
190
- # For a thorough discussion of atom content see
190
+ # For a thorough discussion of atom content see
191
191
  # http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.content
192
192
  class Base < DelegateClass(String)
193
193
  include Xml::Parseable
194
-
194
+
195
195
  def initialize(c)
196
196
  __setobj__(c)
197
197
  end
198
-
198
+
199
199
  def ==(o)
200
200
  if o.is_a?(self.class)
201
201
  self.type == o.type &&
@@ -205,15 +205,15 @@ module Atom # :nodoc:
205
205
  self.to_s == o
206
206
  end
207
207
  end
208
-
208
+
209
209
  protected
210
210
  def set_content(c) # :nodoc:
211
211
  __setobj__(c)
212
212
  end
213
213
  end
214
-
214
+
215
215
  # External content reference within an Atom document.
216
- class External < Base
216
+ class External < Base
217
217
  attribute :type, :src
218
218
 
219
219
  # this one only works with XML::Reader instances, no strings, since the
@@ -223,7 +223,7 @@ module Atom # :nodoc:
223
223
  super("")
224
224
  parse(o, :once => true)
225
225
  end
226
-
226
+
227
227
  def to_xml(builder = nil , name = 'content', namespace = nil, namespace_handler = nil)
228
228
  builder ||= Nokogiri::XML::Builder.new
229
229
  namespace_handler.prefix(builder, Atom::NAMESPACE) if namespace_handler
@@ -234,9 +234,9 @@ module Atom # :nodoc:
234
234
  builder.doc.root
235
235
  end
236
236
  end
237
-
237
+
238
238
  # Text content within an Atom document.
239
- class Text < Base
239
+ class Text < Base
240
240
  attribute :type, :'xml:lang'
241
241
  def initialize(o)
242
242
  case o
@@ -248,18 +248,18 @@ module Atom # :nodoc:
248
248
  parse(o, :once => true)
249
249
  else
250
250
  raise ArgumentError, "Got #{o} which isn't a String or XML::Reader"
251
- end
251
+ end
252
252
  end
253
-
253
+
254
254
  def to_xml(builder = nil, name = 'content', namespace = nil, namespace_handler = nil)
255
255
  namespace_handler.prefix(builder, Atom::NAMESPACE) if namespace_handler
256
256
  builder.send("#{name}_", self.to_s)
257
257
  builder.doc.root
258
258
  end
259
259
  end
260
-
260
+
261
261
  # Html content within an Atom document.
262
- class Html < Base
262
+ class Html < Base
263
263
  attribute :type, :'xml:lang'
264
264
  # Creates a new Content::Html.
265
265
  #
@@ -275,9 +275,9 @@ module Atom # :nodoc:
275
275
  @type = 'html'
276
276
  else
277
277
  raise ArgumentError, "Got #{o} which isn't a String or XML::Reader"
278
- end
278
+ end
279
279
  end
280
-
280
+
281
281
  def to_xml(builder = nil, name = 'content', namespace = nil, namespace_handler = nil) # :nodoc:
282
282
  builder ||= Nokogiri::XML::Builder.new
283
283
  # Reject content that isn't UTF-8. If we don't check libxml just
@@ -300,19 +300,19 @@ module Atom # :nodoc:
300
300
  end
301
301
  end
302
302
  end
303
-
303
+
304
304
  # XHTML content within an Atom document.
305
305
  class Xhtml < Base
306
- XHTML = 'http://www.w3.org/1999/xhtml'
306
+ XHTML = 'http://www.w3.org/1999/xhtml'
307
307
  attribute :type, :'xml:lang'
308
-
308
+
309
309
  def initialize(o)
310
310
  case o
311
311
  when String
312
312
  super(o)
313
313
  @type = "xhtml"
314
314
  when Nokogiri::XML::Reader
315
- super("")
315
+ super("")
316
316
  xml = o
317
317
  parse(xml, :once => true)
318
318
  starting_depth = xml.depth
@@ -320,7 +320,7 @@ module Atom # :nodoc:
320
320
  # Get the next element - should be a div according to the atom spec
321
321
  while xml.read && xml.node_type != Nokogiri::XML::Reader::TYPE_ELEMENT; end
322
322
 
323
- if xml.local_name == 'div' && xml.namespace_uri == XHTML
323
+ if xml.local_name == 'div' && xml.namespace_uri == XHTML
324
324
  set_content(xml.inner_xml.strip.gsub(/\s+/, ' '))
325
325
  else
326
326
  set_content(xml.outer_xml)
@@ -329,10 +329,10 @@ module Atom # :nodoc:
329
329
  # get back to the end of the element we were created with
330
330
  while xml.read == 1 && xml.depth > starting_depth; end
331
331
  else
332
- raise ArgumentError, "Got #{o} which isn't a String or XML::Reader"
332
+ raise ArgumentError, "Got #{o} which isn't a String or XML::Reader"
333
333
  end
334
334
  end
335
-
335
+
336
336
  def to_xml(builder = nil, name = 'content', namespace = nil, namespace_handler = nil)
337
337
  builder ||= Nokogiri::XML::Builder.new
338
338
  namespace_handler.prefix(builder, Atom::NAMESPACE) if namespace_handler
@@ -350,7 +350,7 @@ module Atom # :nodoc:
350
350
 
351
351
  PARSERS = {'html' => Html, 'xhtml' => Xhtml}
352
352
  end
353
-
353
+
354
354
  # Represents a Source as defined by the Atom Syndication Format specification.
355
355
  #
356
356
  # See also http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.source
@@ -358,13 +358,13 @@ module Atom # :nodoc:
358
358
  extend Forwardable
359
359
  def_delegators :@links, :alternate, :self, :alternates, :enclosures
360
360
  include Xml::Parseable
361
-
361
+
362
362
  element :id
363
363
  element :updated, :class => Time, :content_only => true
364
364
  element :title, :subtitle, :class => Content
365
365
  elements :authors, :contributors, :class => Person
366
366
  elements :links
367
-
367
+
368
368
  def initialize(o = {})
369
369
  @authors, @contributors, @links = [], [], Links.new
370
370
 
@@ -383,18 +383,18 @@ module Atom # :nodoc:
383
383
  else
384
384
  raise ArgumentError, "Got #{o.class} but expected a Hash or XML::Reader"
385
385
  end
386
-
387
- yield(self) if block_given?
386
+
387
+ yield(self) if block_given?
388
388
  end
389
389
  end
390
-
390
+
391
391
  # Represents a Feed as defined by the Atom Syndication Format specification.
392
392
  #
393
393
  # A feed is the top level element in an atom document. It is a container for feed level
394
394
  # metadata and for each entry in the feed.
395
395
  #
396
396
  # This supports pagination as defined in RFC 5005, see http://www.ietf.org/rfc/rfc5005.txt
397
- #
397
+ #
398
398
  # == Parsing
399
399
  #
400
400
  # A feed can be parsed using the Feed.load_feed method. This method accepts a String containing
@@ -405,7 +405,7 @@ module Atom # :nodoc:
405
405
  #
406
406
  # # Using a URL
407
407
  # feed = Feed.load_feed(URI.parse("http://example.org/afeed.atom"))
408
- #
408
+ #
409
409
  # == Encoding
410
410
  #
411
411
  # A feed can be converted to XML using, the to_xml method that returns a valid atom document in a String.
@@ -435,8 +435,8 @@ module Atom # :nodoc:
435
435
  extend Forwardable
436
436
  def_delegators :@links, :alternate, :self, :via, :first_page, :last_page, :next_page, :prev_page
437
437
 
438
- loadable!
439
-
438
+ loadable!
439
+
440
440
  namespace Atom::NAMESPACE
441
441
  element :id, :rights
442
442
  element :generator, :class => Generator
@@ -446,7 +446,12 @@ module Atom # :nodoc:
446
446
  elements :authors, :contributors, :class => Person
447
447
  elements :categories
448
448
  elements :entries
449
-
449
+
450
+ # to_xml as a document, not just a root node
451
+ def document?
452
+ true
453
+ end
454
+
450
455
  # Initialize a Feed.
451
456
  #
452
457
  # This will also yield itself, so a feed can be constructed like this:
@@ -454,12 +459,12 @@ module Atom # :nodoc:
454
459
  # feed = Feed.new do |feed|
455
460
  # feed.title = "My Cool feed"
456
461
  # end
457
- #
462
+ #
458
463
  # +o+:: An XML Reader or a Hash of attributes.
459
464
  #
460
465
  def initialize(o = {})
461
466
  @links, @entries, @authors, @contributors, @categories = Links.new, [], [], [], []
462
-
467
+
463
468
  case o
464
469
  when Nokogiri::XML::Reader
465
470
  if next_node_is?(o, 'feed', Atom::NAMESPACE)
@@ -475,27 +480,27 @@ module Atom # :nodoc:
475
480
  else
476
481
  raise ArgumentError, "Got #{o.class} but expected a Hash or XML::Reader"
477
482
  end
478
-
483
+
479
484
  yield(self) if block_given?
480
485
  end
481
-
486
+
482
487
  # Return true if this is the first feed in a paginated set.
483
488
  def first?
484
489
  links.self == links.first_page
485
- end
486
-
490
+ end
491
+
487
492
  # Returns true if this is the last feed in a paginated set.
488
493
  def last?
489
494
  links.self == links.last_page
490
495
  end
491
-
496
+
492
497
  # Reloads the feed by fetching the self uri.
493
498
  def reload!(opts = {})
494
499
  if links.self
495
500
  Feed.load_feed(URI.parse(links.self.href), opts)
496
501
  end
497
502
  end
498
-
503
+
499
504
  # Iterates over each entry in the feed.
500
505
  #
501
506
  # ==== Options
@@ -509,7 +514,7 @@ module Atom # :nodoc:
509
514
  if options[:paginate]
510
515
  since_reached = false
511
516
  feed = self
512
- loop do
517
+ loop do
513
518
  feed.entries.each do |entry|
514
519
  if options[:since] && entry.updated && options[:since] > entry.updated
515
520
  since_reached = true
@@ -518,7 +523,7 @@ module Atom # :nodoc:
518
523
  block.call(entry)
519
524
  end
520
525
  end
521
-
526
+
522
527
  if since_reached || feed.next_page.nil?
523
528
  break
524
529
  else feed.next_page
@@ -528,9 +533,9 @@ module Atom # :nodoc:
528
533
  else
529
534
  self.entries.each(&block)
530
535
  end
531
- end
536
+ end
532
537
  end
533
-
538
+
534
539
  # Represents an Entry as defined by the Atom Syndication Format specification.
535
540
  #
536
541
  # An Entry represents an individual entry within a Feed.
@@ -545,9 +550,9 @@ module Atom # :nodoc:
545
550
  #
546
551
  # # Using a URL
547
552
  # Entry = Entry.load_entry(URI.parse("http://example.org/afeedentry.atom"))
548
- #
553
+ #
549
554
  # The document must contain a stand alone entry element as described in the Atom Syndication Format.
550
- #
555
+ #
551
556
  # == Encoding
552
557
  #
553
558
  # A Entry can be converted to XML using, the to_xml method that returns a valid atom entry document in a String.
@@ -578,7 +583,7 @@ module Atom # :nodoc:
578
583
  include SimpleExtensions
579
584
  extend Forwardable
580
585
  def_delegators :@links, :alternate, :self, :alternates, :enclosures, :edit_link, :via
581
-
586
+
582
587
  loadable!
583
588
  namespace Atom::NAMESPACE
584
589
  element :title, :id, :summary
@@ -588,7 +593,7 @@ module Atom # :nodoc:
588
593
  elements :authors, :contributors, :class => Person
589
594
  elements :categories, :class => Category
590
595
  element :content, :class => Content
591
-
596
+
592
597
  # Initialize an Entry.
593
598
  #
594
599
  # This will also yield itself, so an Entry can be constructed like this:
@@ -596,7 +601,7 @@ module Atom # :nodoc:
596
601
  # entry = Entry.new do |entry|
597
602
  # entry.title = "My Cool entry"
598
603
  # end
599
- #
604
+ #
600
605
  # +o+:: An XML Reader or a Hash of attributes.
601
606
  #
602
607
  def initialize(o = {})
@@ -604,7 +609,7 @@ module Atom # :nodoc:
604
609
  @authors = []
605
610
  @contributors = []
606
611
  @categories = []
607
-
612
+
608
613
  case o
609
614
  when Nokogiri::XML::Reader
610
615
  if current_node_is?(o, 'entry', Atom::NAMESPACE) || next_node_is?(o, 'entry', Atom::NAMESPACE)
@@ -622,8 +627,8 @@ module Atom # :nodoc:
622
627
  end
623
628
 
624
629
  yield(self) if block_given?
625
- end
626
-
630
+ end
631
+
627
632
  # Reload the Entry by fetching the self link.
628
633
  def reload!(opts = {})
629
634
  if links.self
@@ -637,77 +642,77 @@ module Atom # :nodoc:
637
642
  # Some additional methods to get specific types of links are provided.
638
643
  #
639
644
  # == References
640
- #
645
+ #
641
646
  # See also http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.link
642
647
  # for details on link selection and link attributes.
643
648
  #
644
649
  class Links < DelegateClass(Array)
645
650
  include Enumerable
646
-
651
+
647
652
  # Initialize an empty Links array.
648
653
  def initialize
649
654
  super([])
650
655
  end
651
-
656
+
652
657
  # Get the alternate.
653
658
  #
654
659
  # Returns the first link with rel == 'alternate' that matches the given type.
655
660
  def alternate(type = nil)
656
- detect { |link|
657
- (link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type) && (link.hreflang.nil?)
658
- } || detect { |link|
659
- (link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type)
661
+ detect { |link|
662
+ (link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type) && (link.hreflang.nil?)
663
+ } || detect { |link|
664
+ (link.rel.nil? || link.rel == Link::Rel::ALTERNATE) && (type.nil? || type == link.type)
660
665
  }
661
666
  end
662
-
667
+
663
668
  # Get all alternates.
664
669
  def alternates
665
670
  select { |link| link.rel.nil? || link.rel == Link::Rel::ALTERNATE }
666
671
  end
667
-
672
+
668
673
  # Gets the self link.
669
674
  def self
670
675
  detect { |link| link.rel == Link::Rel::SELF }
671
676
  end
672
-
677
+
673
678
  # Gets the via link.
674
679
  def via
675
680
  detect { |link| link.rel == Link::Rel::VIA }
676
681
  end
677
-
682
+
678
683
  # Gets all links with rel == 'enclosure'
679
684
  def enclosures
680
685
  select { |link| link.rel == Link::Rel::ENCLOSURE }
681
686
  end
682
-
687
+
683
688
  # Gets the link with rel == 'first'.
684
689
  #
685
690
  # This is defined as the first page in a pagination set.
686
691
  def first_page
687
692
  detect { |link| link.rel == Link::Rel::FIRST }
688
693
  end
689
-
694
+
690
695
  # Gets the link with rel == 'last'.
691
696
  #
692
697
  # This is defined as the last page in a pagination set.
693
698
  def last_page
694
699
  detect { |link| link.rel == Link::Rel::LAST }
695
700
  end
696
-
701
+
697
702
  # Gets the link with rel == 'next'.
698
703
  #
699
704
  # This is defined as the next page in a pagination set.
700
705
  def next_page
701
706
  detect { |link| link.rel == Link::Rel::NEXT }
702
707
  end
703
-
708
+
704
709
  # Gets the link with rel == 'prev'.
705
710
  #
706
711
  # This is defined as the previous page in a pagination set.
707
712
  def prev_page
708
713
  detect { |link| link.rel == Link::Rel::PREVIOUS }
709
714
  end
710
-
715
+
711
716
  # Gets the edit link.
712
717
  #
713
718
  # This is the link which can be used for posting updates to an item using the Atom Publishing Protocol.
@@ -716,7 +721,7 @@ module Atom # :nodoc:
716
721
  detect { |link| link.rel == 'edit' }
717
722
  end
718
723
  end
719
-
724
+
720
725
  # Represents a link in an Atom document.
721
726
  #
722
727
  # A link defines a reference from an Atom document to a web resource.
@@ -735,12 +740,12 @@ module Atom # :nodoc:
735
740
  LAST = 'last'
736
741
  PREVIOUS = 'prev'
737
742
  NEXT = 'next'
738
- end
739
-
743
+ end
744
+
740
745
  include Xml::Parseable
741
746
  attribute :rel, :type, :length, :hreflang, :title
742
747
  uri_attribute :href
743
-
748
+
744
749
  # Create a link.
745
750
  #
746
751
  # +o+:: An XML::Reader containing a link element or a Hash of attributes.
@@ -759,22 +764,22 @@ module Atom # :nodoc:
759
764
  end
760
765
  else
761
766
  raise ArgumentError, "Don't know how to handle #{o}"
762
- end
767
+ end
763
768
  end
764
-
769
+
765
770
  remove_method :length=
766
771
  def length=(v)
767
772
  @length = v.to_i
768
773
  end
769
-
774
+
770
775
  def to_s
771
776
  self.href
772
777
  end
773
-
778
+
774
779
  def ==(o)
775
780
  o.respond_to?(:href) && o.href == self.href
776
781
  end
777
-
782
+
778
783
  # This will fetch the URL referenced by the link.
779
784
  #
780
785
  # If the URL contains a valid feed, a Feed will be returned, otherwise,
@@ -789,7 +794,7 @@ module Atom # :nodoc:
789
794
  Net::HTTP.get_response(URI.parse(self.href)).body
790
795
  end
791
796
  end
792
-
797
+
793
798
  def inspect
794
799
  "<Atom::Link href:'#{href}' type:'#{type}'>"
795
800
  end
data/lib/atom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Atom
2
- VERSION = "0.10.0"
2
+ VERSION = "0.10.1"
3
3
  end
@@ -175,9 +175,13 @@ module Atom
175
175
  end
176
176
  end
177
177
 
178
+ def document?
179
+ false
180
+ end
181
+
178
182
  def to_xml(builder = nil, root_name = self.class.name.demodulize.downcase, namespace = nil, namespace_handler = nil)
179
183
  orig_builder = builder
180
- builder ||= Nokogiri::XML::Builder.new
184
+ builder ||= Nokogiri::XML::Builder.new(:encoding => 'utf-8')
181
185
 
182
186
  namespaces = {}
183
187
  namespaces['xmlns'] = self.class.namespace if !orig_builder && self.class.respond_to?(:namespace) && self.class.namespace
@@ -214,7 +218,7 @@ module Atom
214
218
  end
215
219
  end
216
220
  end
217
-
221
+
218
222
  (self.class.attributes + self.class.uri_attributes).each do |attribute|
219
223
  if value = self.send(accessor_name(attribute))
220
224
  if value != 0
@@ -243,8 +247,8 @@ module Atom
243
247
  attributes.each do |k,v|
244
248
  node[k] = v
245
249
  end
246
-
247
- builder.doc.root
250
+
251
+ document? ? builder.doc : builder.doc.root
248
252
  end
249
253
 
250
254
  module DeclarationMethods # :nodoc:
data/spec/atom_spec.rb CHANGED
@@ -193,6 +193,10 @@ describe Atom do
193
193
  @feed = Atom::Feed.load_feed(File.open('spec/fixtures/complex_single_entry.atom'))
194
194
  end
195
195
 
196
+ it "should include an xml declaration" do
197
+ @feed.to_xml.to_s.should(match %r{<\?xml version="1.0" encoding="utf-8"\?>})
198
+ end
199
+
196
200
  describe Atom::Feed do
197
201
  it "should have a title" do
198
202
  @feed.title.should == 'dive into mark'
@@ -1296,7 +1300,7 @@ describe Atom do
1296
1300
  entry.content = Atom::Content::Html.new("Žižek is utf8")
1297
1301
  end.to_xml.to_s
1298
1302
 
1299
- xml.should match(/&#x17D;i&#x17E;ek/)
1303
+ xml.should match(/Žižek/)
1300
1304
  end
1301
1305
  end
1302
1306
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratom-nokogiri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peerworks
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-08-04 00:00:00.000000000 Z
13
+ date: 2015-08-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri