xbel 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +1 -1
- data/README.markdown +10 -0
- data/VERSION +1 -1
- data/lib/nokogiri/decorators/xbel/folder.rb +11 -1
- data/lib/xbel/writer.rb +1 -1
- data/lib/xbel.rb +5 -0
- data/xbel.gemspec +1 -1
- metadata +1 -1
data/.document
CHANGED
data/README.markdown
CHANGED
@@ -7,6 +7,16 @@ development.
|
|
7
7
|
|
8
8
|
gem install xbel
|
9
9
|
|
10
|
+
## Use
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'xbel'
|
14
|
+
|
15
|
+
xbel = XBEL.parse File.read('complex.xbel')
|
16
|
+
|
17
|
+
with_aliases = true # TODO...
|
18
|
+
xbel.root.bookmarks(with_aliases).each { |bm| system 'open', bm.href }
|
19
|
+
|
10
20
|
### Note on Patches/Pull Requests
|
11
21
|
|
12
22
|
1. Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -2,53 +2,63 @@ module Nokogiri::Decorators::XBEL
|
|
2
2
|
module Folder
|
3
3
|
include Entry
|
4
4
|
|
5
|
+
# Returns an instance of NodeSet with all valid children for this folder.
|
5
6
|
def entries
|
6
7
|
xpath './alias', './bookmark', './folder', './separator'
|
7
8
|
end
|
9
|
+
# Returns an instance of NodeSet with all aliases for this folder.
|
8
10
|
def aliases
|
9
11
|
xpath './alias'
|
10
12
|
end
|
13
|
+
# Returns an instance of NodeSet with all bookmarks for this folder.
|
11
14
|
def bookmarks
|
12
15
|
xpath './bookmark'
|
13
16
|
end
|
17
|
+
# Returns an instance of NodeSet with all folders for this folder.
|
14
18
|
def folders
|
15
19
|
xpath './folder'
|
16
20
|
end
|
17
21
|
|
22
|
+
# Returns true.
|
18
23
|
def folder?
|
19
24
|
true
|
20
25
|
end
|
21
26
|
|
27
|
+
# Adds a entry and sets added attribute.
|
22
28
|
def add_child(node)
|
23
29
|
node.added = Date.today if node.is_a? Entry
|
24
30
|
super
|
25
31
|
end
|
26
32
|
|
33
|
+
# Builds a bookmark with given attributes and add it.
|
27
34
|
def build_bookmark(attributes = {}, &block)
|
28
35
|
node = Nokogiri::XML::Node.new('bookmark', document)
|
29
36
|
assign_to node, attributes
|
30
37
|
|
31
38
|
add_child node
|
32
39
|
end
|
40
|
+
# Builds a folder with given attributes and add it.
|
33
41
|
def build_folder(attributes = {}, &block)
|
34
42
|
node = Nokogiri::XML::Node.new('folder', document)
|
35
43
|
assign_to node, attributes
|
36
44
|
|
37
45
|
add_child node
|
38
46
|
end
|
47
|
+
# Builds an alias with given attributes and add it.
|
39
48
|
def build_alias(ref)
|
40
49
|
node = Nokogiri::XML::Node.new('alias', document)
|
41
50
|
node.ref = (Entry === ref) ? ref.id : ref.to_s
|
42
51
|
|
43
52
|
add_child node
|
44
53
|
end
|
54
|
+
# Builds a seperator with given attributes and add it.
|
45
55
|
def add_seperator
|
46
56
|
add_child Nokogiri::XML::Node.new('separator', document)
|
47
57
|
end
|
48
58
|
|
49
59
|
protected
|
50
60
|
|
51
|
-
def assign_to(node, attributes)
|
61
|
+
def assign_to(node, attributes) #:nodoc:
|
52
62
|
attributes.each do |key, value|
|
53
63
|
node.send "#{ key }=", value
|
54
64
|
end
|
data/lib/xbel/writer.rb
CHANGED
data/lib/xbel.rb
CHANGED
@@ -11,6 +11,7 @@ class XBEL < Nokogiri::XML::Document
|
|
11
11
|
|
12
12
|
autoload :Writer, 'xbel/writer'
|
13
13
|
|
14
|
+
# Use <tt>XBEL.parse(string)</tt> create an instance.
|
14
15
|
def initialize(*args)
|
15
16
|
super
|
16
17
|
decorators(Nokogiri::XML::Node) << Nokogiri::Decorators::XBEL
|
@@ -19,14 +20,18 @@ class XBEL < Nokogiri::XML::Document
|
|
19
20
|
# self.root = '<xbel version="1.0"></xbel>'
|
20
21
|
end
|
21
22
|
|
23
|
+
# Returns an array of version numbers.
|
22
24
|
def version
|
23
25
|
root.attribute('version').value.split('.').map { |n| n.to_i }
|
24
26
|
end
|
27
|
+
# Sets version numbers.
|
25
28
|
def version=(*numbers)
|
26
29
|
root.attribute('version').value = numbers.join '.'
|
27
30
|
end
|
28
31
|
|
32
|
+
# Writes XBEL to path.
|
29
33
|
def write(path)
|
34
|
+
# TODO: should start locking write process
|
30
35
|
Writer.new(self, path).write
|
31
36
|
end
|
32
37
|
|
data/xbel.gemspec
CHANGED