markio 0.0.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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in markio.gemspec
4
+ gemspec
@@ -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.
@@ -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
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task default: :spec
@@ -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,3 @@
1
+ class Markio::Bookmark
2
+ attr_accessor :title, :href, :add_date, :last_visit, :last_modified, :folders
3
+ end
@@ -0,0 +1,3 @@
1
+ class Markio::Folder
2
+ attr_accessor :title, :add_date, :items
3
+ 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
@@ -0,0 +1,3 @@
1
+ module Markio
2
+ VERSION = "0.0.1"
3
+ end
@@ -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
@@ -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
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'markio'
3
+ require 'pry'
4
+ require 'pry-nav'
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ config.formatter = 'documentation'
9
+ end
@@ -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: