nbf_tools 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -2
- data/Gemfile.lock +1 -1
- data/README.md +5 -6
- data/lib/nbf_tools/html.rb +4 -2
- data/lib/nbf_tools/merge.rb +4 -2
- data/lib/nbf_tools/parse.rb +19 -8
- data/lib/nbf_tools/type.rb +6 -0
- data/lib/nbf_tools/version.rb +1 -1
- data/lib/nbf_tools.rb +7 -23
- data/nbf_tools.gemspec +1 -0
- metadata +5 -4
- data/lib/nbf_tools/configuration.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 885abc5c5af24a8ee6d9d08d83ca302291b14e868684742404f10116c2983b19
|
4
|
+
data.tar.gz: 4806b463cccf40009c29c9ff3d8508a0920dd5a1f91a2f30ab430713f345f4cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c5d27b869913b81e7766544bb033fbf1b5290ff655855e29e608644e27231cf4817b628c80f747afb9bc15bcfde2d14ad1e55b36ab82a4ac7f21fc460379830
|
7
|
+
data.tar.gz: 9765ee19f410e561f083cf754bace377a99f63ad2c30deb072c6caafab40beac993f8f2258352d17f9fdb05f241975751ea1ec4fa99220495f5df8f6b798ed66
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
-
|
1
|
+
# [Changelog]
|
2
|
+
|
3
|
+
## [0.2.0] - 2023-10-11
|
4
|
+
|
5
|
+
- feat: Reomve configuration, add parse options
|
6
|
+
- feat: change method name, `merge_files_to_one_html` -> `merge_files_to_one_html`, `parse_files_to_one` -> `parse_files_to_one`
|
7
|
+
|
8
|
+
## [0.1.1] - 2023-10-06
|
9
|
+
|
10
|
+
- fix: CONTENT_FORMAT `s` char
|
2
11
|
|
3
12
|
## [0.1.0] - 2022-12-17
|
4
13
|
|
5
|
-
- Initial release
|
14
|
+
- Initial release
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# NbfTools
|
2
2
|
|
3
|
-
NETSCAPE Bookmark file tools
|
3
|
+
NETSCAPE Bookmark file tools,file from chrome edge firefox safari browser
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,19 +20,18 @@ Parse NETSCAPE Bookmark file.
|
|
20
20
|
NbfTools.parse bookmark_file_path
|
21
21
|
```
|
22
22
|
|
23
|
-
Merge and parse NETSCAPE Bookmark files.
|
23
|
+
Merge and parse multiple NETSCAPE Bookmark files.
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
NbfTools.
|
26
|
+
NbfTools.parse_files_to_one bookmark_file_path1, bookmark_file_path2
|
27
27
|
```
|
28
28
|
|
29
|
-
|
29
|
+
Merge multiple NETSCAPE Bookmark files into one html string.
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
NbfTools.
|
32
|
+
NbfTools.merge_files_to_one_html bookmark_file_path1, bookmark_file_path2
|
33
33
|
```
|
34
34
|
|
35
|
-
|
36
35
|
## Development
|
37
36
|
|
38
37
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/nbf_tools/html.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "type"
|
4
|
+
|
3
5
|
module NbfTools
|
4
6
|
class HTML
|
5
7
|
CONTENT_FORMAT = "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<!-- This is an automatically generated file.\n It will be read and overwritten.\n DO NOT EDIT! -->\n<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n<TITLE>Bookmarks</TITLE>\n<H1>Bookmarks</H1>\n<DL><p>\n%{content}\n</DL><p>"
|
@@ -22,9 +24,9 @@ module NbfTools
|
|
22
24
|
return if data.nil?
|
23
25
|
data.map do |e|
|
24
26
|
case e["type"]
|
25
|
-
when NbfTools
|
27
|
+
when NbfTools::Type::LINK
|
26
28
|
link_html(e)
|
27
|
-
when NbfTools
|
29
|
+
when NbfTools::Type::FOLDER
|
28
30
|
folder_html(e)
|
29
31
|
end
|
30
32
|
end.join("\n")
|
data/lib/nbf_tools/merge.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "type"
|
4
|
+
|
3
5
|
module NbfTools
|
4
6
|
class Merge
|
5
7
|
def initialize(data)
|
@@ -35,9 +37,9 @@ module NbfTools
|
|
35
37
|
def flat_folder_and_link_map(data, link_map, folder_map)
|
36
38
|
data.map do |e|
|
37
39
|
case e["type"]
|
38
|
-
when NbfTools
|
40
|
+
when NbfTools::Type::LINK
|
39
41
|
choose_latest_element(link_map, "href", e)
|
40
|
-
when NbfTools
|
42
|
+
when NbfTools::Type::FOLDER
|
41
43
|
choose_latest_element(folder_map, "path", e)
|
42
44
|
flat_folder_and_link_map(e["items"], link_map, folder_map)
|
43
45
|
end
|
data/lib/nbf_tools/parse.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "nokogiri"
|
4
|
+
require_relative "type"
|
5
|
+
|
4
6
|
module NbfTools
|
5
7
|
class Parse
|
6
|
-
def initialize
|
7
|
-
@
|
8
|
+
def initialize options = {}
|
9
|
+
@options = options
|
8
10
|
end
|
9
11
|
|
10
|
-
def parse
|
12
|
+
def parse file
|
13
|
+
@document = Nokogiri::HTML(File.open(file))
|
11
14
|
parse_node_children(@document.xpath("/html/body/dl").first, Pathname.new("/"))
|
12
15
|
end
|
13
16
|
|
@@ -17,18 +20,26 @@ module NbfTools
|
|
17
20
|
when "dt"
|
18
21
|
items.push(*parse_node_children(c, path))
|
19
22
|
when "a"
|
20
|
-
bookmark = c.to_h.merge("text" => c.text, "type" => NbfTools
|
23
|
+
bookmark = c.to_h.merge("text" => c.text, "type" => NbfTools::Type::LINK, "path" => path.to_s)
|
21
24
|
items.push bookmark
|
22
25
|
when "h3"
|
23
|
-
|
24
|
-
|
25
|
-
folder = c.to_h.merge("text" => folder_name, "type" => NbfTools.config.folder_type_text, "path" => (path + folder_name).to_s, "items" => [])
|
26
|
+
text = folder_text(c)
|
27
|
+
folder = c.to_h.merge("text" => text, "type" => NbfTools::Type::FOLDER, "path" => (path + text).to_s, "items" => [])
|
26
28
|
items.push folder
|
27
29
|
when "dl"
|
28
|
-
folder = items.
|
30
|
+
folder = items.reverse.find { |e| e["type"] == "folder" }
|
29
31
|
folder.nil? ? items.push(*parse_node_children(c), path) : folder["items"] = parse_node_children(c, path + folder["text"])
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
35
|
+
|
36
|
+
def folder_text item
|
37
|
+
return item.text unless item["personal_toolbar_folder"] == "true"
|
38
|
+
if @options[:personal_toolbar_folder_text].to_s.empty?
|
39
|
+
@options[:personal_toolbar_folder_text] = item.text
|
40
|
+
else
|
41
|
+
@options[:personal_toolbar_folder_text]
|
42
|
+
end
|
43
|
+
end
|
33
44
|
end
|
34
45
|
end
|
data/lib/nbf_tools/version.rb
CHANGED
data/lib/nbf_tools.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "nbf_tools/configuration"
|
4
3
|
require_relative "nbf_tools/html"
|
5
4
|
require_relative "nbf_tools/merge"
|
6
5
|
require_relative "nbf_tools/parse"
|
@@ -8,37 +7,22 @@ require_relative "nbf_tools/version"
|
|
8
7
|
|
9
8
|
module NbfTools
|
10
9
|
class Error < StandardError; end
|
11
|
-
# Your code goes here...
|
12
10
|
|
13
11
|
class << self
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
@config = Configuration.new
|
18
|
-
@config.personal_toolbar_folder_text = "personal toolbar"
|
19
|
-
@config.link_type_text = "link"
|
20
|
-
@config.folder_type_text = "folder"
|
21
|
-
|
22
|
-
@config
|
23
|
-
end
|
24
|
-
|
25
|
-
def configure(&block)
|
26
|
-
config.instance_exec(&block)
|
27
|
-
end
|
28
|
-
|
29
|
-
def parse(file)
|
30
|
-
Parse.new(file).parse
|
12
|
+
def parse(file, **options)
|
13
|
+
Parse.new(**options).parse(file)
|
31
14
|
end
|
32
15
|
|
33
|
-
def
|
34
|
-
|
16
|
+
def parse_files_to_one(*files, **options)
|
17
|
+
parse_tool = Parse.new(**options)
|
18
|
+
data = files.map { |file| parse_tool.parse(file) }
|
35
19
|
return data[0] if files.size < 2
|
36
20
|
Merge.new(data).to_a
|
37
21
|
end
|
38
22
|
|
39
|
-
def
|
23
|
+
def merge_files_to_one_html(*files, **custom_options)
|
40
24
|
return File.read(files[0]) if files.size < 2
|
41
|
-
data =
|
25
|
+
data = parse_files_to_one(*files)
|
42
26
|
HTML.new(data).to_s
|
43
27
|
end
|
44
28
|
end
|
data/nbf_tools.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = "NETSCAPE Bookmark file tools."
|
13
13
|
spec.homepage = "https://github.com/sapeu/nbf_tools"
|
14
14
|
spec.required_ruby_version = ">= 2.7.0"
|
15
|
+
spec.license = "MIT"
|
15
16
|
|
16
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nbf_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sapeu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -52,15 +52,16 @@ files:
|
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
54
|
- lib/nbf_tools.rb
|
55
|
-
- lib/nbf_tools/configuration.rb
|
56
55
|
- lib/nbf_tools/html.rb
|
57
56
|
- lib/nbf_tools/merge.rb
|
58
57
|
- lib/nbf_tools/parse.rb
|
58
|
+
- lib/nbf_tools/type.rb
|
59
59
|
- lib/nbf_tools/version.rb
|
60
60
|
- nbf_tools.gemspec
|
61
61
|
- sig/nbf_tools.rbs
|
62
62
|
homepage: https://github.com/sapeu/nbf_tools
|
63
|
-
licenses:
|
63
|
+
licenses:
|
64
|
+
- MIT
|
64
65
|
metadata:
|
65
66
|
homepage_uri: https://github.com/sapeu/nbf_tools
|
66
67
|
source_code_uri: https://github.com/sapeu/nbf_tools
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module NbfTools
|
4
|
-
class Configuration
|
5
|
-
# personal toolbar folder text, default: ''
|
6
|
-
attr_accessor :personal_toolbar_folder_text
|
7
|
-
# link type text, default: 'link'
|
8
|
-
attr_accessor :link_type_text
|
9
|
-
# folder type text, default: 'folder'
|
10
|
-
attr_accessor :folder_type_text
|
11
|
-
end
|
12
|
-
end
|