xommelier 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/xommelier/atom.rb +1 -0
- data/lib/xommelier/atom/content.rb +13 -0
- data/lib/xommelier/atom/entry.rb +1 -1
- data/lib/xommelier/version.rb +1 -1
- data/lib/xommelier/xml.rb +6 -5
- data/lib/xommelier/xml/element/serialization.rb +34 -2
- data/lib/xommelier/xml/element/structure.rb +1 -1
- data/spec/functional/atom_feed_parsing_spec.rb +7 -4
- data/spec/spec_helper.rb +4 -0
- metadata +3 -2
data/lib/xommelier/atom.rb
CHANGED
@@ -13,6 +13,7 @@ module Xommelier
|
|
13
13
|
autoload :Link, 'xommelier/atom/link'
|
14
14
|
autoload :Person, 'xommelier/atom/person'
|
15
15
|
autoload :Category, 'xommelier/atom/category'
|
16
|
+
autoload :Content, 'xommelier/atom/content'
|
16
17
|
autoload :Generator, 'xommelier/atom/generator'
|
17
18
|
autoload :Source, 'xommelier/atom/source'
|
18
19
|
autoload :Feed, 'xommelier/atom/feed'
|
data/lib/xommelier/atom/entry.rb
CHANGED
data/lib/xommelier/version.rb
CHANGED
data/lib/xommelier/xml.rb
CHANGED
@@ -51,14 +51,15 @@ module Xommelier
|
|
51
51
|
instance_variable_set :@_xmlns, nil
|
52
52
|
end
|
53
53
|
|
54
|
+
# Define XML default namespace
|
54
55
|
extend ClassMethods
|
55
56
|
xmlns DEFAULT_NS, as: :xml
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
# Inject common XML attributes to every XML element
|
59
|
+
require 'xommelier/xml/element'
|
60
|
+
class Element
|
61
|
+
attribute :lang, ns: Xml.xmlns, as: 'xml:lang'
|
62
|
+
attribute :base, type: Uri, ns: Xml.xmlns, as: 'xml:base'
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
@@ -48,8 +48,8 @@ module Xommelier
|
|
48
48
|
@_xml_node = options.delete(:node) { xml.at_xpath(element_xpath(xml.document, element_name)) }
|
49
49
|
validate if options[:validate]
|
50
50
|
|
51
|
-
if text? && @_xml_node.
|
52
|
-
self.text = @_xml_node.
|
51
|
+
if text? && @_xml_node.inner_html.present?
|
52
|
+
self.text = @_xml_node.inner_html
|
53
53
|
end
|
54
54
|
|
55
55
|
self.class.attributes.each do |name, options|
|
@@ -132,6 +132,38 @@ module Xommelier
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
def <=>(other)
|
136
|
+
if text? && other.is_a?(String)
|
137
|
+
text.to_s <=> other
|
138
|
+
else
|
139
|
+
super
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def ==(other)
|
144
|
+
if text? && other.is_a?(String)
|
145
|
+
text.to_s == other
|
146
|
+
else
|
147
|
+
super
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def =~(other)
|
152
|
+
if text? && other.is_a?(Regexp)
|
153
|
+
text.to_s =~ other
|
154
|
+
else
|
155
|
+
super
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def to_s
|
160
|
+
if text?
|
161
|
+
text.to_s
|
162
|
+
else
|
163
|
+
super
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
135
167
|
protected
|
136
168
|
|
137
169
|
delegate :ns_element, to: 'self.class'
|
@@ -68,7 +68,6 @@ module Xommelier
|
|
68
68
|
def inherited(child)
|
69
69
|
child.elements = elements.dup
|
70
70
|
child.attributes = attributes.dup
|
71
|
-
child.send(:include, Xml::CommonAttributes)
|
72
71
|
end
|
73
72
|
|
74
73
|
# Defines containing element
|
@@ -171,6 +170,7 @@ module Xommelier
|
|
171
170
|
read_text
|
172
171
|
end
|
173
172
|
alias_method :text=, :text
|
173
|
+
alias_attribute :content, :text
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -37,7 +37,7 @@ describe 'Atom feed' do
|
|
37
37
|
its(:rights) { should == '© Mark Pilgrim, 2003' }
|
38
38
|
describe 'Generator' do
|
39
39
|
subject { feed.generator }
|
40
|
-
|
40
|
+
context '#to_s' do
|
41
41
|
it { should == 'Example Toolkit' }
|
42
42
|
its(:text) { should == 'Example Toolkit' }
|
43
43
|
end
|
@@ -89,12 +89,15 @@ describe 'Atom feed' do
|
|
89
89
|
it { entry.contributors[0].name.should == 'Sam Ruby' }
|
90
90
|
it { entry.contributors[1].name.should == 'Joe Gregorio' }
|
91
91
|
its(:summary) { should == 'Some text.' }
|
92
|
-
|
93
|
-
pending 'should parse text-based elements\' attributes' do
|
92
|
+
context 'Content' do
|
94
93
|
subject { entry.content }
|
94
|
+
it { should =~ /#{Regexp.escape('[Update: The Atom draft is finished.]')}/ }
|
95
|
+
its(:text) do
|
96
|
+
should == "\n <div xmlns=\"http://www.w3.org/1999/xhtml\">\n <p><i>[Update: The Atom draft is finished.]</i></p>\n </div>\n "
|
97
|
+
end
|
95
98
|
its(:type) { should == 'xhtml' }
|
96
99
|
its(:lang) { should == 'en' }
|
97
|
-
its(:base) { should == 'http://diveintomark.org/' }
|
100
|
+
its(:base) { should == URI.parse('http://diveintomark.org/') }
|
98
101
|
its(:content) { should ~ Regexp.new(Regexp.escape('<p><i>[Update: The Atom draft is fiished.]</i></p>')) }
|
99
102
|
end
|
100
103
|
its(:total) { should == 1 }
|
data/spec/spec_helper.rb
CHANGED
@@ -10,4 +10,8 @@ ATOM_XMLNS = 'http://www.w3.org/2005/Atom'
|
|
10
10
|
|
11
11
|
RSpec.configure do |config|
|
12
12
|
config.mock_with :rspec
|
13
|
+
config.order = 'random'
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.filter_run focus: true
|
16
|
+
config.run_all_when_everything_filtered = true
|
13
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xommelier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.16
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/xommelier.rb
|
82
82
|
- lib/xommelier/atom.rb
|
83
83
|
- lib/xommelier/atom/category.rb
|
84
|
+
- lib/xommelier/atom/content.rb
|
84
85
|
- lib/xommelier/atom/entry.rb
|
85
86
|
- lib/xommelier/atom/feed.rb
|
86
87
|
- lib/xommelier/atom/full.rb
|