xbel 0.1.0 → 0.1.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.
data/.watchr ADDED
@@ -0,0 +1,47 @@
1
+ require 'open3'
2
+
3
+ Dir.chdir File.dirname(__FILE__)
4
+
5
+ watch(/(?:lib|test).*\.rb$/) { |something|
6
+
7
+ Dir['lib/**/*.rb'].inject(true) do |check, path|
8
+ Open3.popen3('ruby', '-c', path) { |_, o, stderr|
9
+ errors = stderr.read
10
+
11
+ if errors.empty? then check
12
+ else
13
+ puts errors
14
+ false
15
+ end
16
+ }
17
+ end and begin
18
+
19
+ messages = Dir['test/**/test_*.rb'].inject([]) do |messages, path|
20
+ if path !~ /test_helper\.rb$/
21
+ Open3.popen3('rake test') do |_, o, e|
22
+ puts e.read, message = o.read
23
+
24
+ result = message.split($/).last
25
+ tests, assertions, failures, errors =
26
+ result.split(', ').map! { |r| r.to_i }
27
+
28
+ failures ||= 0
29
+ errors ||= 0
30
+
31
+ unless failures.zero? and errors.zero?
32
+ # Open3.popen3(bad_message) { |i, *| i << message[0, 160] }
33
+ else
34
+ # system(good_message)
35
+ end
36
+
37
+ messages << message
38
+ end
39
+ end
40
+
41
+ messages
42
+ end
43
+
44
+
45
+ end
46
+
47
+ }
data/README.markdown ADDED
@@ -0,0 +1,21 @@
1
+ # xbel
2
+
3
+ Introduces XBEL decorations for Nokogiri. Write support is still in
4
+ development.
5
+
6
+ ## Installation
7
+
8
+ gem install xbel
9
+
10
+ ### Note on Patches/Pull Requests
11
+
12
+ 1. Fork the project.
13
+ 2. Make your feature addition or bug fix.
14
+ 3. Add tests for it. This is important so I don't break it in a
15
+ future version unintentionally.
16
+ 4. Commit, do not mess with rakefile, version, or history.
17
+ 5. Send me a pull request.
18
+
19
+ ### Copyright
20
+
21
+ Copyright (c) 2009 Florian Aßmann. See LICENSE for details.
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ begin
8
8
  gem.summary = %Q{Ruby API for XBEL based on Nokogiri and Watchr.}
9
9
  gem.description = %Q{}
10
10
  gem.email = "florian.assmann@email.de"
11
- gem.homepage = "http://github.com/boof/xbel"
11
+ gem.homepage = "http://xbel.monkey-patch.me"
12
12
  gem.authors = ["Florian Aßmann"]
13
13
  gem.add_development_dependency "shoulda", ">= 0"
14
14
  gem.add_dependency 'watchr', '>= 0'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,68 @@
1
+ module Nokogiri::Decorators::XBEL
2
+
3
+ autoload :Folder, "#{ File.dirname __FILE__ }/xbel/folder.rb"
4
+ autoload :Seperator, "#{ File.dirname __FILE__ }/xbel/folder.rb"
5
+ autoload :Bookmark, "#{ File.dirname __FILE__ }/xbel/bookmark.rb"
6
+ autoload :Alias, "#{ File.dirname __FILE__ }/xbel/alias.rb"
7
+
8
+ def self.extended(base)
9
+ case base.name
10
+ when 'title'
11
+ when 'desc'
12
+ when 'bookmark'
13
+ base.extend Bookmark
14
+ when 'folder'
15
+ base.extend Folder
16
+ when 'separator'
17
+ base.extend Separator
18
+ when 'alias'
19
+ base.extend Alias
20
+ when 'xbel'
21
+ base.extend Folder
22
+ end
23
+ end
24
+
25
+ module Entry
26
+ def desc
27
+ if node = at('./desc') then node.content end
28
+ end
29
+ def desc=(value)
30
+ node = at './desc'
31
+ node ||= add_child Nokogiri::XML::Node.new('desc', document)
32
+
33
+ node.content = value
34
+ end
35
+ alias_method :description, :desc
36
+ alias_method :description=, :desc=
37
+
38
+ def title
39
+ if node = at('./title') then node.content end
40
+ end
41
+ def title=(value)
42
+ node = at './title'
43
+ node ||= add_child Nokogiri::XML::Node.new('title', document)
44
+
45
+ node.content = value
46
+ end
47
+ alias_method :to_s, :title
48
+
49
+ def id
50
+ if id = attribute('id') then id.content end
51
+ end
52
+ def id=(value)
53
+ set_attribute 'id', value.to_s
54
+ end
55
+
56
+ def added
57
+ if value = attribute('added') then Date.parse value.content end
58
+ end
59
+ def added=(value)
60
+ set_attribute 'added', value.to_s
61
+ end
62
+
63
+ def alias?; end
64
+ def bookmark?; end
65
+ def folder?; end
66
+ end
67
+
68
+ end
@@ -0,0 +1,25 @@
1
+ module Nokogiri::Decorators::XBEL
2
+ module Alias
3
+ extend Forwardable
4
+ def_delegators :entry,
5
+ :description, :title, :to_s, :id, :added, :bookmark?, :folder?
6
+
7
+ def ref
8
+ attribute('ref').content
9
+ end
10
+ def ref=(value)
11
+ set_attribute 'ref', value.to_s
12
+ end
13
+ alias_method :reference, :ref
14
+ alias_method :reference=, :ref=
15
+
16
+ def entry
17
+ at %Q'//*[@id="#{ ref }"]'
18
+ end
19
+
20
+ def alias?
21
+ true
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ module Nokogiri::Decorators::XBEL
2
+ module Bookmark
3
+ include Entry
4
+
5
+ def modified
6
+ if value = attribute('modified') then Date.parse value.content end
7
+ end
8
+ def modified=(value)
9
+ set_attribute 'modified', value.to_s
10
+ end
11
+ def visited
12
+ if value = attribute('visited') then Date.parse value.content end
13
+ end
14
+ def visited=(value)
15
+ set_attribute 'visited', value.to_s
16
+ end
17
+ def visit
18
+ self.visited = Date.today
19
+ end
20
+ def href
21
+ if value = attribute('href') then value.content end
22
+ end
23
+ def href=(value)
24
+ self.modified = Date.today
25
+ set_attribute 'href', value
26
+ end
27
+ def bookmark?
28
+ true
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,59 @@
1
+ module Nokogiri::Decorators::XBEL
2
+ module Folder
3
+ include Entry
4
+
5
+ def entries
6
+ xpath './alias', './bookmark', './folder', './separator'
7
+ end
8
+ def aliases
9
+ xpath './alias'
10
+ end
11
+ def bookmarks
12
+ xpath './bookmark'
13
+ end
14
+ def folders
15
+ xpath './folder'
16
+ end
17
+
18
+ def folder?
19
+ true
20
+ end
21
+
22
+ def add_child(node)
23
+ node.added = Date.today if node.is_a? Entry
24
+ super
25
+ end
26
+
27
+ def build_bookmark(attributes = {}, &block)
28
+ node = Nokogiri::XML::Node.new('bookmark', document)
29
+ assign_to node, attributes
30
+
31
+ add_child node
32
+ end
33
+ def build_folder(attributes = {}, &block)
34
+ node = Nokogiri::XML::Node.new('folder', document)
35
+ assign_to node, attributes
36
+
37
+ add_child node
38
+ end
39
+ def build_alias(ref)
40
+ node = Nokogiri::XML::Node.new('alias', document)
41
+ node.ref = (Entry === ref) ? ref.id : ref.to_s
42
+
43
+ add_child node
44
+ end
45
+ def add_seperator
46
+ add_child Nokogiri::XML::Node.new('separator', document)
47
+ end
48
+
49
+ protected
50
+
51
+ def assign_to(node, attributes)
52
+ attributes.each do |key, value|
53
+ node.send "#{ key }=", value
54
+ end
55
+ yield node if block_given?
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,9 @@
1
+ module Nokogiri::Decorators::XBEL
2
+ module Separator
3
+
4
+ def to_s
5
+ ''
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ class XBEL::Writer
2
+ DOCTYPE = '<!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">'
3
+
4
+ attr_reader :document, :lockfile_path, :path
5
+ def new(document, path)
6
+ @document, @path = document, path
7
+ @lockfile_path = "#{ path }.lock"
8
+ end
9
+
10
+ def write
11
+ synchronize do
12
+ File.open path, 'w' do |file|
13
+ file.puts DOCTYPE
14
+ file << document
15
+ end
16
+ end
17
+ end
18
+
19
+ protected
20
+
21
+ def locked?(path)
22
+ File.exists? lockfile_path
23
+ end
24
+ def lock
25
+ File.open(lockfile_path, 'w') { |*| yield }
26
+ ensure
27
+ File.unlink lockfile_path
28
+ end
29
+
30
+ def synchronize
31
+ current_thread = Thread.current
32
+
33
+ while locked?
34
+ watch(lockfile_path, :delete) { |*| current_thread.run }
35
+ current_thread.sleep
36
+ end
37
+
38
+ lock { yield }
39
+ end
40
+
41
+ end
data/test/complex.xbel ADDED
@@ -0,0 +1,165 @@
1
+ <?xml version="1.0"?>
2
+ <!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange
3
+ Language 1.0//EN//XML"
4
+ "http://www.python.org/topics/xml/dtds/xbel-1.0.dtd">
5
+ <xbel version="1.0">
6
+ <title>Some of David's Bookmarks</title>
7
+
8
+ <folder>
9
+ <title>HTTP Clients</title>
10
+
11
+ <bookmark href="http://www.netscape.com/download/" id="bookmark-1">
12
+ <title>Netscape</title>
13
+
14
+ <desc>Netscape 6.2 is the latest update to the Internet
15
+ browsing, email and instant messagin software suite from
16
+ Netscape.</desc>
17
+ </bookmark>
18
+
19
+ <bookmark href="http://www.opera.com/">
20
+ <title>Opera</title>
21
+
22
+ <desc>Opera -- Simply the Best Internet Experience</desc>
23
+ </bookmark>
24
+
25
+ <alias ref="bookmark-5"></alias>
26
+
27
+ <bookmark href="http://www.microsoft.com/ie/">
28
+ <title>Microsoft Internet Explorer</title>
29
+
30
+ <desc>Internet Explorer 6 sets a new standard in privacy,
31
+ reliability, and flexibility. Come see how Internet Explorer
32
+ is leading the way on the Web.</desc>
33
+ </bookmark>
34
+
35
+ <bookmark href="http://lynx.browser.org/">
36
+ <title>Lynx</title>
37
+
38
+ <desc>Lynx is a fully-featured World Wide Web (WWW) client
39
+ for users running cursor-addressable, character-cell display
40
+ devices (e.g., vt100 terminals, vt100 emulators running on
41
+ PCs or Macs, or any other character-cell display). It will
42
+ display Hypertext Markup Language (HTML) documents containing
43
+ links to files on the local system, as well as files on
44
+ remote systems running http, gopher, ftp, wais, nntp, finger,
45
+ or cso/ph/qi servers, and services accessible via logins to
46
+ telnet, tn3270 or rlogin accounts. Current versions of Lynx
47
+ run on Unix, VMS, Windows95/NT, 386DOS and OS/2 EMX.</desc>
48
+ </bookmark>
49
+
50
+ <bookmark href="http://www.w3.org/Amaya/" id="bookmark-5">
51
+ <title>Amaya</title>
52
+
53
+ <desc>Amaya is a browser/authoring tool that allows you to
54
+ publish documents on the Web. It is used to demonstrate and
55
+ test many of the new developments in Web protocols and data
56
+ formats. Given the very fast moving nature of Web technology,
57
+ Amaya has a central role to play. It is versatile and
58
+ extensible and is available on both Unix and Windows '95/NT
59
+ platforms.</desc>
60
+ </bookmark>
61
+
62
+ <alias ref="bookmark-1"></alias>
63
+
64
+ </folder>
65
+
66
+ <folder>
67
+ <title>Extensible Markup Language (XML)</title>
68
+
69
+ <bookmark
70
+ href="http://www.sciam.com/1999/0599issue/0599bosak.html">
71
+ <title>Scientific American: Feature Article: XML and the
72
+ Second Generation Web: May 1999</title>
73
+
74
+ <desc>The combination of hypertext and a global Internet
75
+ started a revolution. A new ingredient, XML, is poised to
76
+ finish the job. by Jon Bosak and Tim Bray</desc>
77
+
78
+ </bookmark>
79
+
80
+ <bookmark
81
+ href="http://www.sciam.com/2001/0501issue/0501berners-lee.html">
82
+
83
+ <title>Scientific American: Feature Article: The Semantic
84
+ Web: May 2001</title>
85
+
86
+ <desc>A new form of Web content that is meaningful to
87
+ computers will unleash a revolution of new possibilities . by
88
+ TIM BERNERS-LEE, JAMES HENDLER and ORA LASSILA</desc>
89
+ </bookmark>
90
+
91
+ <bookmark href="http://www.w3.org/XML/1999/XML-in-10-points">
92
+
93
+ <title>XML in 10 Points</title>
94
+ </bookmark>
95
+
96
+ <folder>
97
+ <title>Building XML Documents</title>
98
+
99
+ <bookmark
100
+ href="http://www.webreview.com/2000/08_04/webauthors/08_04_00_4.shtml">
101
+
102
+ <title>Well-Formed XML Documents (webreview.com)</title>
103
+
104
+ <desc>Still trying to tame the XML beast? Begin with this
105
+ tutorial that will show you in clear terms how to build a
106
+ simple XML document that is well-formed and valid.</desc>
107
+ </bookmark>
108
+ </folder>
109
+
110
+ <folder>
111
+ <title>RSS</title>
112
+
113
+ <bookmark
114
+ href="http://www.webreference.com/authoring/languages/xml/rss/intro/">
115
+
116
+ <title>Introduction to RSS - WebReference.com</title>
117
+
118
+ <desc>Rich Site Summary (RSS) is a lightweight XML format
119
+ designed for sharing headlines and other Web
120
+ content.</desc>
121
+ </bookmark>
122
+
123
+ <bookmark
124
+ href="http://www.WebReview.com/1999/10_29/webauthors/10_29_99_2a.shtml">
125
+
126
+ <title>WebReview.com: RSS Delivers the XML Promise</title>
127
+
128
+ <desc>RSS is a content syndication format that uses the
129
+ power of XML to share data over the Internet.</desc>
130
+ </bookmark>
131
+ </folder>
132
+
133
+ <folder>
134
+ <title>Extensible Stylesheet Language (XSL)</title>
135
+
136
+ <bookmark
137
+ href="http://www.webreview.com/2001/08_03/developers/index01.shtml">
138
+
139
+ <title>WebReview.com: August 3, 2001: Introduction to
140
+ XSLT</title>
141
+
142
+ <desc>An introduction to XSLT</desc>
143
+ </bookmark>
144
+ </folder>
145
+
146
+ <folder>
147
+ <title>Recommended Books</title>
148
+
149
+ <bookmark href="http://www.oreilly.com/catalog/learnxml/">
150
+ <title>Learning XML : (Guide to) Creating Self-Describing
151
+ Data</title>
152
+
153
+ <desc>Eric T. Ray, (O'Reilly)</desc>
154
+ </bookmark>
155
+
156
+ <bookmark
157
+ href="http://www.amazon.com/exec/obidos/ASIN/0789725045/">
158
+ <title>XML By Example</title>
159
+
160
+ <desc>Benoit Marchal</desc>
161
+ </bookmark>
162
+ </folder>
163
+ </folder>
164
+ </xbel>
165
+
data/test/test_xbel.rb CHANGED
@@ -10,7 +10,7 @@ class TestXBEL < Test::Unit::TestCase
10
10
  assert_equal [1, 0], xbel.version
11
11
  end
12
12
  should "have title 'Some of David's Bookmarks'" do
13
- assert_equal %Q"Some of David's Bookmarks", xbel.title
13
+ assert_equal %Q{Some of David's Bookmarks}, xbel.title
14
14
  end
15
15
  should "return all root folders" do
16
16
  results = xbel.root.folders
@@ -21,7 +21,9 @@ class TestXBEL < Test::Unit::TestCase
21
21
  should "return all bookmarks of 'HTTP Clients'" do
22
22
  results = xbel.root.folders.first.bookmarks
23
23
  results = results.map { |entry| entry.title }
24
- expect = ['Netscape', 'Opera', 'Microsoft Internet Explorer', 'Lynx', 'Amaya']
24
+ expect = [
25
+ 'Netscape', 'Opera', 'Microsoft Internet Explorer', 'Lynx', 'Amaya'
26
+ ]
25
27
  assert_equal expect, results
26
28
  end
27
29
  should "return aliased bookmark" do
data/xbel.gemspec ADDED
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{xbel}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Florian A\303\237mann"]
12
+ s.date = %q{2009-10-28}
13
+ s.description = %q{}
14
+ s.email = %q{florian.assmann@email.de}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".watchr",
23
+ "LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/nokogiri/decorators/xbel.rb",
28
+ "lib/nokogiri/decorators/xbel/alias.rb",
29
+ "lib/nokogiri/decorators/xbel/bookmark.rb",
30
+ "lib/nokogiri/decorators/xbel/folder.rb",
31
+ "lib/nokogiri/decorators/xbel/seperator.rb",
32
+ "lib/xbel.rb",
33
+ "lib/xbel/writer.rb",
34
+ "test/complex.xbel",
35
+ "test/helper.rb",
36
+ "test/test_xbel.rb",
37
+ "xbel.gemspec"
38
+ ]
39
+ s.homepage = %q{http://xbel.monkey-patch.me}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.5}
43
+ s.summary = %q{Ruby API for XBEL based on Nokogiri and Watchr.}
44
+ s.test_files = [
45
+ "test/helper.rb",
46
+ "test/test_xbel.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_runtime_dependency(%q<watchr>, [">= 0"])
56
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_dependency(%q<watchr>, [">= 0"])
60
+ s.add_dependency(%q<nokogiri>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<shoulda>, [">= 0"])
64
+ s.add_dependency(%q<watchr>, [">= 0"])
65
+ s.add_dependency(%q<nokogiri>, [">= 0"])
66
+ end
67
+ end
68
+
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Florian A\xC3\x9Fmann"
@@ -50,19 +50,28 @@ extensions: []
50
50
 
51
51
  extra_rdoc_files:
52
52
  - LICENSE
53
- - README.rdoc
53
+ - README.markdown
54
54
  files:
55
55
  - .document
56
56
  - .gitignore
57
+ - .watchr
57
58
  - LICENSE
58
- - README.rdoc
59
+ - README.markdown
59
60
  - Rakefile
60
61
  - VERSION
62
+ - lib/nokogiri/decorators/xbel.rb
63
+ - lib/nokogiri/decorators/xbel/alias.rb
64
+ - lib/nokogiri/decorators/xbel/bookmark.rb
65
+ - lib/nokogiri/decorators/xbel/folder.rb
66
+ - lib/nokogiri/decorators/xbel/seperator.rb
61
67
  - lib/xbel.rb
68
+ - lib/xbel/writer.rb
69
+ - test/complex.xbel
62
70
  - test/helper.rb
63
71
  - test/test_xbel.rb
72
+ - xbel.gemspec
64
73
  has_rdoc: true
65
- homepage: http://github.com/boof/xbel
74
+ homepage: http://xbel.monkey-patch.me
66
75
  licenses: []
67
76
 
68
77
  post_install_message:
data/README.rdoc DELETED
@@ -1,18 +0,0 @@
1
- = xbel
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but
13
- bump version in a commit by itself I can ignore when I pull)
14
- * Send me a pull request. Bonus points for topic branches.
15
-
16
- == Copyright
17
-
18
- Copyright (c) 2009 Florian Aßmann. See LICENSE for details.