atom-tools 1.0.0 → 2.0.0
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.
- data/COPYING +3 -3
- data/README +4 -44
- data/Rakefile +9 -2
- data/bin/atom-cp +159 -0
- data/bin/atom-grep +78 -0
- data/bin/atom-post +72 -0
- data/bin/atom-purge +82 -0
- data/lib/atom/cache.rb +178 -0
- data/lib/atom/collection.rb +77 -17
- data/lib/atom/element.rb +520 -166
- data/lib/atom/entry.rb +82 -142
- data/lib/atom/feed.rb +48 -66
- data/lib/atom/http.rb +115 -35
- data/lib/atom/service.rb +56 -113
- data/lib/atom/text.rb +79 -63
- data/lib/atom/tools.rb +163 -0
- data/test/conformance/order.rb +11 -10
- data/test/conformance/title.rb +9 -9
- data/test/test_constructs.rb +23 -10
- data/test/test_feed.rb +0 -44
- data/test/test_general.rb +0 -40
- data/test/test_http.rb +18 -0
- data/test/test_protocol.rb +60 -22
- data/test/test_xml.rb +73 -41
- metadata +47 -37
- data/bin/atom-client.rb +0 -275
- data/lib/atom/xml.rb +0 -213
- data/lib/atom/yaml.rb +0 -116
data/lib/atom/yaml.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
require "atom/entry"
|
2
|
-
require "yaml"
|
3
|
-
|
4
|
-
module Atom
|
5
|
-
class Time
|
6
|
-
def taguri; nil end
|
7
|
-
end
|
8
|
-
|
9
|
-
class Element < Hash
|
10
|
-
def taguri # :nodoc:
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_yaml_properties # :nodoc:
|
14
|
-
self.class.elements.find_all do |n,k,r|
|
15
|
-
v = get(n)
|
16
|
-
v and not (v.respond_to? :empty? and v.empty?)
|
17
|
-
end.map { |n,k,r| "@#{n}" }
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_yaml( opts = {} ) # :nodoc:
|
21
|
-
YAML::quick_emit( object_id, opts ) do |out|
|
22
|
-
out.map( taguri, to_yaml_style ) do |map|
|
23
|
-
self.to_yaml_properties.each do |m|
|
24
|
-
map.add( m[1..-1], instance_variable_get( m ) )
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class AttrEl < Atom::Element
|
32
|
-
def to_yaml( opts = {} )
|
33
|
-
YAML::quick_emit( object_id, opts ) do |out|
|
34
|
-
out.map( nil, to_yaml_style ) do |map|
|
35
|
-
self.class.attrs.each do |n,r|
|
36
|
-
map.add( n.to_s, self[n.to_s] ) if self[n.to_s]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class Text < Atom::Element
|
44
|
-
def taguri # :nodoc:
|
45
|
-
end
|
46
|
-
|
47
|
-
def to_yaml( opts = {} ) # :nodoc:
|
48
|
-
YAML::quick_emit( object_id, opts ) do |out|
|
49
|
-
out.scalar(taguri, to_s, to_yaml_style)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
def to_yaml_style # :nodoc:
|
53
|
-
if @content.to_s.match("\n")
|
54
|
-
:fold
|
55
|
-
else
|
56
|
-
:plain
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class Entry
|
62
|
-
def to_yaml_type # :nodoc:
|
63
|
-
'!necronomicorp.com,2006/entry'
|
64
|
-
end
|
65
|
-
|
66
|
-
def to_yaml( opts = {} ) # :nodoc:
|
67
|
-
YAML::quick_emit( object_id, opts ) do |out|
|
68
|
-
out.map( taguri, to_yaml_style ) do |map|
|
69
|
-
self.to_yaml_properties.each do |m|
|
70
|
-
map.add( m[1..-1], instance_variable_get( m ) )
|
71
|
-
end
|
72
|
-
map.add("draft", true) if self.draft
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# parses an Atom::Entry from YAML
|
78
|
-
def self.from_yaml yaml
|
79
|
-
hash = if yaml.kind_of?(Hash); yaml else YAML.load(yaml); end
|
80
|
-
|
81
|
-
entry = Atom::Entry.new
|
82
|
-
|
83
|
-
["id", "published", "updated", "title", "summary", "draft"].each do |name|
|
84
|
-
entry.send("#{name}=".to_sym, hash[name])
|
85
|
-
end
|
86
|
-
|
87
|
-
elem_constructs = {"authors" => entry.authors,
|
88
|
-
"contributors" => entry.contributors,
|
89
|
-
"links" => entry.links,
|
90
|
-
"categories" => entry.categories}
|
91
|
-
|
92
|
-
elem_constructs.each do |type,ary|
|
93
|
-
hash[type] ||= []
|
94
|
-
|
95
|
-
hash[type].each do |yelem|
|
96
|
-
elem = ary.new
|
97
|
-
|
98
|
-
elem.class.attrs.each do |attrb,req|
|
99
|
-
elem[attrb.to_s] = yelem[attrb.to_s]
|
100
|
-
end
|
101
|
-
|
102
|
-
elem.class.elements.each do |name,kind,req|
|
103
|
-
elem.send("#{name}=".to_sym, yelem[name.to_s])
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
entry.tag_with hash["tags"]
|
109
|
-
|
110
|
-
entry.content = hash["content"]
|
111
|
-
entry.content["type"] = hash["type"] if hash["type"]
|
112
|
-
|
113
|
-
entry
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|