markio 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/lib/markio.rb +12 -0
- data/lib/markio/bookmark.rb +3 -0
- data/lib/markio/folder.rb +3 -0
- data/lib/markio/parser.rb +41 -0
- data/lib/markio/version.rb +3 -0
- data/markio.gemspec +24 -0
- data/spec/parser_spec.rb +17 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/test_data/one_bookmark.html +10 -0
- metadata +111 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tomas Varaneckas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Markio
|
2
|
+
|
3
|
+
A ruby gem for parsing Netscape Bookmark File Format
|
4
|
+
http://msdn.microsoft.com/en-us/library/aa753582(v=vs.85).aspx
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'markio'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install markio
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
bookmarks = Markio::parse('/path/to/bookmarks.html')
|
23
|
+
bookmarks.each do |b|
|
24
|
+
b.title # String with bookmark title
|
25
|
+
b.href # String with bookmark URL
|
26
|
+
b.folders # Array of strings - folders (tags)
|
27
|
+
end
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/markio.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "markio/version"
|
2
|
+
require "markio/parser"
|
3
|
+
require "markio/bookmark"
|
4
|
+
require "markio/folder"
|
5
|
+
module Markio
|
6
|
+
def parse(file)
|
7
|
+
parser = Markio::Parser.new(file)
|
8
|
+
result = []
|
9
|
+
parser.each { |bookmark| result << bookmark }
|
10
|
+
result
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
class Markio::Parser
|
3
|
+
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize(file)
|
7
|
+
file = File.open(file) unless file.is_a? File
|
8
|
+
@document = Nokogiri::HTML(file)
|
9
|
+
end
|
10
|
+
|
11
|
+
def each
|
12
|
+
node = @document.at_xpath('//html/body')
|
13
|
+
@folders = []
|
14
|
+
traverse(node) { |bookmark| yield bookmark }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def traverse(node, &block)
|
20
|
+
bookmarks = node.search './dt//a'
|
21
|
+
folder_names = node.search './dt/h3'
|
22
|
+
folder_items = node.search './dl'
|
23
|
+
|
24
|
+
bookmarks.each do |data|
|
25
|
+
bookmark = Markio::Bookmark.new
|
26
|
+
bookmark.title = data.text
|
27
|
+
bookmark.href = data['href']
|
28
|
+
bookmark.folders = Array.new(@folders)
|
29
|
+
yield bookmark
|
30
|
+
end
|
31
|
+
|
32
|
+
folder_items.size.times do |i|
|
33
|
+
folder_name = folder_names[i]
|
34
|
+
folder_item = folder_items[i]
|
35
|
+
@folders << folder_name unless folder_name.nil?
|
36
|
+
traverse(folder_item, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/markio.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'markio/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "markio"
|
8
|
+
gem.version = Markio::VERSION
|
9
|
+
gem.authors = ["Tomas Varaneckas"]
|
10
|
+
gem.email = ["tomas.varaneckas@gmail.com"]
|
11
|
+
gem.description = %q{Import/export utility for Netscape Bookmark Format}
|
12
|
+
gem.summary = %q{Import/export utility for Netscape Bookmark Format}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'nokogiri'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 2.11'
|
22
|
+
gem.add_development_dependency 'pry-nav'
|
23
|
+
|
24
|
+
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Markio::Parser do
|
4
|
+
it 'should parse single bookmark' do
|
5
|
+
parser = Markio::Parser.new("spec/test_data/one_bookmark.html")
|
6
|
+
bookmarks = []
|
7
|
+
parser.each { |b| bookmarks << b }
|
8
|
+
|
9
|
+
bookmarks.should_not be_nil
|
10
|
+
bookmarks.class.should be Array
|
11
|
+
bookmarks.length.should eq 1
|
12
|
+
bookmark = bookmarks[0]
|
13
|
+
bookmark.title.should eq 'Save It - Simple, secure bookmarks'
|
14
|
+
bookmark.href.should eq 'https://saveit.in/'
|
15
|
+
bookmark.folders.length.should eq 0
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
2
|
+
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
|
3
|
+
<!-- This is an automatically generated file.
|
4
|
+
It will be read and overwritten.
|
5
|
+
Do Not Edit! -->
|
6
|
+
<TITLE>Bookmarks</TITLE>
|
7
|
+
<H1>Bookmarks</H1>
|
8
|
+
<DL><p>
|
9
|
+
<DT><A HREF="https://saveit.in/" ADD_DATE="1350743281" PRIVATE="0" TAGS="Bookmarking">Save It - Simple, secure bookmarks</A>
|
10
|
+
</DL><p>
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tomas Varaneckas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.11'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.11'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry-nav
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Import/export utility for Netscape Bookmark Format
|
63
|
+
email:
|
64
|
+
- tomas.varaneckas@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/markio.rb
|
75
|
+
- lib/markio/bookmark.rb
|
76
|
+
- lib/markio/folder.rb
|
77
|
+
- lib/markio/parser.rb
|
78
|
+
- lib/markio/version.rb
|
79
|
+
- markio.gemspec
|
80
|
+
- spec/parser_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
- spec/test_data/one_bookmark.html
|
83
|
+
homepage: ''
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.24
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Import/export utility for Netscape Bookmark Format
|
107
|
+
test_files:
|
108
|
+
- spec/parser_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/test_data/one_bookmark.html
|
111
|
+
has_rdoc:
|