xbel 0.2.1 → 0.2.2
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/.gitignore +2 -1
- data/Rakefile +7 -8
- data/VERSION +1 -1
- data/lib/nokogiri/decorators/xbel.rb +12 -1
- data/lib/nokogiri/decorators/xbel/alias.rb +10 -2
- data/lib/nokogiri/decorators/xbel/bookmark.rb +8 -0
- data/lib/nokogiri/decorators/xbel/folder.rb +6 -6
- data/lib/nokogiri/decorators/xbel/{seperator.rb → separator.rb} +2 -1
- data/lib/xbel.rb +8 -3
- data/test/test_xbel.rb +21 -5
- data/test/wikipedia.xbel +3 -0
- data/xbel.gemspec +3 -3
- metadata +3 -3
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -40,12 +40,11 @@ end
|
|
40
40
|
|
41
41
|
task :default => :test
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
43
|
+
begin
|
44
|
+
require 'yard'
|
45
|
+
YARD::Rake::YardocTask.new
|
46
|
+
rescue LoadError
|
47
|
+
task :yardoc do
|
48
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
49
|
+
end
|
51
50
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -3,7 +3,7 @@ module Nokogiri::Decorators::XBEL
|
|
3
3
|
autoload :Bookmark, "#{ File.dirname __FILE__ }/xbel/bookmark.rb"
|
4
4
|
autoload :Folder, "#{ File.dirname __FILE__ }/xbel/folder.rb"
|
5
5
|
autoload :Alias, "#{ File.dirname __FILE__ }/xbel/alias.rb"
|
6
|
-
autoload :
|
6
|
+
autoload :Separator, "#{ File.dirname __FILE__ }/xbel/separator.rb"
|
7
7
|
|
8
8
|
def self.extended(base)
|
9
9
|
case base.name
|
@@ -35,9 +35,11 @@ module Nokogiri::Decorators::XBEL
|
|
35
35
|
end
|
36
36
|
attr_reader :info
|
37
37
|
|
38
|
+
# Returns description of node.
|
38
39
|
def desc
|
39
40
|
if node = at('./desc') then node.content end
|
40
41
|
end
|
42
|
+
# Sets description of node.
|
41
43
|
def desc=(value)
|
42
44
|
node = at './desc'
|
43
45
|
node ||= add_child Nokogiri::XML::Node.new('desc', document)
|
@@ -47,9 +49,11 @@ module Nokogiri::Decorators::XBEL
|
|
47
49
|
alias_method :description, :desc
|
48
50
|
alias_method :description=, :desc=
|
49
51
|
|
52
|
+
# Returns title fo node.
|
50
53
|
def title
|
51
54
|
if node = at('./title') then node.content end
|
52
55
|
end
|
56
|
+
# Sets title for node.
|
53
57
|
def title=(value)
|
54
58
|
node = at './title'
|
55
59
|
node ||= add_child Nokogiri::XML::Node.new('title', document)
|
@@ -58,22 +62,29 @@ module Nokogiri::Decorators::XBEL
|
|
58
62
|
end
|
59
63
|
alias_method :to_s, :title
|
60
64
|
|
65
|
+
# Returns id for node.
|
61
66
|
def id
|
62
67
|
if id = attribute('id') then id.content end
|
63
68
|
end
|
69
|
+
# Sets id for node.
|
64
70
|
def id=(value)
|
65
71
|
set_attribute 'id', value.to_s
|
66
72
|
end
|
67
73
|
|
74
|
+
# Returns addition date.
|
68
75
|
def added
|
69
76
|
if value = attribute('added') then Date.parse value.content end
|
70
77
|
end
|
78
|
+
# Sets addition date.
|
71
79
|
def added=(value)
|
72
80
|
set_attribute 'added', value.to_s
|
73
81
|
end
|
74
82
|
|
83
|
+
# Returns nil.
|
75
84
|
def alias?; end
|
85
|
+
# Returns nil.
|
76
86
|
def bookmark?; end
|
87
|
+
# Returns nil.
|
77
88
|
def folder?; end
|
78
89
|
end
|
79
90
|
|
@@ -4,19 +4,27 @@ module Nokogiri::Decorators::XBEL
|
|
4
4
|
def_delegators :entry,
|
5
5
|
:description, :title, :to_s, :id, :added, :bookmark?, :folder?
|
6
6
|
|
7
|
+
# Returns reference to bookmark or folder id.
|
7
8
|
def ref
|
8
9
|
attribute('ref').content
|
9
10
|
end
|
10
|
-
|
11
|
-
|
11
|
+
# Sets reference of bookmark or folder id.
|
12
|
+
def ref=(bookmark_or_folder_id)
|
13
|
+
set_attribute 'ref', bookmark_or_folder_id.to_s
|
12
14
|
end
|
13
15
|
alias_method :reference, :ref
|
14
16
|
alias_method :reference=, :ref=
|
15
17
|
|
18
|
+
# Returns referenced bookmark or folder.
|
16
19
|
def entry
|
17
20
|
at %Q'//*[@id="#{ ref }"]'
|
18
21
|
end
|
22
|
+
# Sets referenced bookmark or folder.
|
23
|
+
def entry=(bookmark_or_folder)
|
24
|
+
self.ref = bookmark_or_folder.id
|
25
|
+
end
|
19
26
|
|
27
|
+
# Returns true.
|
20
28
|
def alias?
|
21
29
|
true
|
22
30
|
end
|
@@ -6,28 +6,36 @@ module Nokogiri::Decorators::XBEL
|
|
6
6
|
node.initialize_decorator
|
7
7
|
end
|
8
8
|
|
9
|
+
# Returns modification date.
|
9
10
|
def modified
|
10
11
|
if value = self['modified'] then Date.parse value end
|
11
12
|
end
|
13
|
+
# Sets modification date.
|
12
14
|
def modified=(value)
|
13
15
|
self['modified'] = value.to_s
|
14
16
|
end
|
17
|
+
# Returns visit date.
|
15
18
|
def visited
|
16
19
|
if value = self['visited'] then Date.parse value end
|
17
20
|
end
|
21
|
+
# Sets visit date.
|
18
22
|
def visited=(value)
|
19
23
|
self['visited'] = value.to_s
|
20
24
|
end
|
25
|
+
# Sets visit to today.
|
21
26
|
def visit
|
22
27
|
self.visited = Date.today
|
23
28
|
end
|
29
|
+
# Returns href value.
|
24
30
|
def href
|
25
31
|
if value = self['href'] then value end
|
26
32
|
end
|
33
|
+
# Sets href value.
|
27
34
|
def href=(value)
|
28
35
|
self.modified = Date.today
|
29
36
|
self['href'] = value
|
30
37
|
end
|
38
|
+
# Returns true.
|
31
39
|
def bookmark?
|
32
40
|
true
|
33
41
|
end
|
@@ -6,19 +6,19 @@ module Nokogiri::Decorators::XBEL
|
|
6
6
|
node.initialize_decorator
|
7
7
|
end
|
8
8
|
|
9
|
-
# Returns an instance of NodeSet with
|
9
|
+
# Returns an instance of NodeSet with possible children in this folder.
|
10
10
|
def entries
|
11
11
|
xpath './alias | ./bookmark | ./folder | ./separator'
|
12
12
|
end
|
13
|
-
# Returns an instance of NodeSet with all aliases
|
13
|
+
# Returns an instance of NodeSet with all aliases in this folder.
|
14
14
|
def aliases
|
15
15
|
xpath './alias'
|
16
16
|
end
|
17
|
-
# Returns an instance of NodeSet with all bookmarks
|
17
|
+
# Returns an instance of NodeSet with all bookmarks in this folder.
|
18
18
|
def bookmarks
|
19
19
|
xpath './bookmark'
|
20
20
|
end
|
21
|
-
# Returns an instance of NodeSet with all folders
|
21
|
+
# Returns an instance of NodeSet with all folders in this folder.
|
22
22
|
def folders
|
23
23
|
xpath './folder'
|
24
24
|
end
|
@@ -56,8 +56,8 @@ module Nokogiri::Decorators::XBEL
|
|
56
56
|
|
57
57
|
add_child node
|
58
58
|
end
|
59
|
-
# Builds a
|
60
|
-
def
|
59
|
+
# Builds a saperator with given attributes and add it.
|
60
|
+
def add_separator
|
61
61
|
add_child Nokogiri::XML::Node.new('separator', document)
|
62
62
|
end
|
63
63
|
|
data/lib/xbel.rb
CHANGED
@@ -7,21 +7,26 @@ class XBEL < Nokogiri::XML::Document
|
|
7
7
|
extend Forwardable
|
8
8
|
def_delegators :root, :title, :title=, :desc, :desc=
|
9
9
|
|
10
|
+
# Returns an instance of XBEL.
|
10
11
|
def self.new(major = 1, minor = 0)
|
11
12
|
parse %Q'<!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML" "http://www.python.org/topics/xml/dtds/xbel-1.0.dtd"><xbel version="%i.%i"></xbel>' % [major, minor]
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
# Reads file at <tt>path</tt> into <tt>parse</tt>.
|
16
|
+
# @yield [XBEL]
|
17
|
+
# @see Nokogiri.parse
|
18
|
+
def self.open(path, &block)
|
19
|
+
parse File.read(path.to_s), &block
|
16
20
|
end
|
17
21
|
|
18
|
-
#
|
22
|
+
# Calls <tt>Nokogiri#initialize</tt> and decorates XBEL nodes.
|
19
23
|
def initialize(*args)
|
20
24
|
super
|
21
25
|
decorators(Nokogiri::XML::Node) << Nokogiri::Decorators::XBEL
|
22
26
|
decorate!
|
23
27
|
end
|
24
28
|
|
29
|
+
# Returns node with given <tt>id</tt>.
|
25
30
|
def [](id)
|
26
31
|
root.at("//*[@id='#{ id }']")
|
27
32
|
end
|
data/test/test_xbel.rb
CHANGED
@@ -52,11 +52,18 @@ context 'XBEL' do
|
|
52
52
|
should('be a folder') { topic.folder? }
|
53
53
|
|
54
54
|
asserts('title') { topic.title }.equals 'Wiki'
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
asserts('entries names') do
|
56
|
+
topic.entries.map { |e| e.name }.uniq.sort
|
57
|
+
end.equals %w[ alias bookmark folder separator ]
|
58
|
+
should('return bookmarks') do
|
59
|
+
not topic.bookmarks.any? { |b| b.name != 'bookmark' }
|
60
|
+
end
|
61
|
+
should('return aliases') do
|
62
|
+
not topic.aliases.any? { |b| b.name != 'alias' }
|
63
|
+
end
|
64
|
+
should('return folders') do
|
65
|
+
not topic.folders.any? { |b| b.name != 'folder' }
|
66
|
+
end
|
60
67
|
|
61
68
|
context 'Bookmark' do
|
62
69
|
setup { topic.bookmarks.first }
|
@@ -100,6 +107,15 @@ context 'XBEL' do
|
|
100
107
|
should('be an alias') { topic.alias? }
|
101
108
|
|
102
109
|
should('reference its folder') { topic.entry == topic.parent }
|
110
|
+
should('set reference by entry') do
|
111
|
+
topic.entry = topic.document[:b1]
|
112
|
+
topic.ref == 'b1'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'Separator' do
|
117
|
+
setup { topic.entries.find { |e| e.name == 'separator' } }
|
118
|
+
asserts('to_s') { topic.to_s }.equals ' '
|
103
119
|
end
|
104
120
|
|
105
121
|
end
|
data/test/wikipedia.xbel
CHANGED
@@ -16,9 +16,12 @@ PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML"
|
|
16
16
|
</info>
|
17
17
|
<title>Wikimedia Foundation</title>
|
18
18
|
</bookmark>
|
19
|
+
<alias ref="f0-1" />
|
20
|
+
<separator />
|
19
21
|
<bookmark href="http://de.wikipedia.org/" id="b1" added="2007-11-11" modified="2007-11-14" visited="2007-12-27">
|
20
22
|
<title>Wikipedia</title>
|
21
23
|
</bookmark>
|
24
|
+
<folder id="f0-1"></folder>
|
22
25
|
</folder>
|
23
26
|
<separator />
|
24
27
|
<alias ref="b1" />
|
data/xbel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{xbel}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Florian A\303\237mann"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-12}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{florian.assmann@email.de}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/nokogiri/decorators/xbel/alias.rb",
|
29
29
|
"lib/nokogiri/decorators/xbel/bookmark.rb",
|
30
30
|
"lib/nokogiri/decorators/xbel/folder.rb",
|
31
|
-
"lib/nokogiri/decorators/xbel/
|
31
|
+
"lib/nokogiri/decorators/xbel/separator.rb",
|
32
32
|
"lib/xbel.rb",
|
33
33
|
"test/helper.rb",
|
34
34
|
"test/test_xbel.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xbel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Florian A\xC3\x9Fmann"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-12 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -53,7 +53,7 @@ files:
|
|
53
53
|
- lib/nokogiri/decorators/xbel/alias.rb
|
54
54
|
- lib/nokogiri/decorators/xbel/bookmark.rb
|
55
55
|
- lib/nokogiri/decorators/xbel/folder.rb
|
56
|
-
- lib/nokogiri/decorators/xbel/
|
56
|
+
- lib/nokogiri/decorators/xbel/separator.rb
|
57
57
|
- lib/xbel.rb
|
58
58
|
- test/helper.rb
|
59
59
|
- test/test_xbel.rb
|