bkmrq 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74e53ea64f34ff615830f694cb0ee20c81bdff858f231675a427bf10e17edb47
4
- data.tar.gz: f0e3fe29ddd97c9a4623c924112dc26c10d2513179fad931b2c88398206f52e5
3
+ metadata.gz: 4ee67957af96bba18676779fe6cb3c818374720d6401483e3b5ff24a760a421b
4
+ data.tar.gz: 312c79e8cf2beb187bebcb1405bcb0e157d867a1fe07cfe4a37745a82920641a
5
5
  SHA512:
6
- metadata.gz: 51a26495b2828cd4a578ed3053644c722485f07231dd6fafef99f0b3055b7907c579e911e2ea101ecd7116cd986c8857e606c784156419448deaf212b584f741
7
- data.tar.gz: 69f84df5c8c0e32e227e51cbe0e03fa5f869ec8c49994535006af0a1b9a388593a9e523c60b735a5058c7f17ebf170fbec14031d556a280a876fb97358d37d28
6
+ metadata.gz: 59cbd60d25856f3c89df44f84efe7f60c3faa3039dfebcca54f8f9865c848fddfd05f0f48bc0ecbd7a9276d4ea23dd2ee82b4a056618bf7d370cda3361800a0c
7
+ data.tar.gz: 91a1b4abaffe181f5af152b26b33a832cbdd364d5bca2f03e2e11b10ae4e4bfd2d9b7d02f4da52bda4ae4fa3e4215342ee5f7951b8687a7049e94f52aada3b48
data/bin/bkmrq CHANGED
@@ -1,5 +1,6 @@
1
- #!/bin/bash
2
- set -e
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
3
 
4
- SELFDIR=$(dirname "$0")
5
- ruby "${SELFDIR}/../lib/app.rb" "$*"
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'bkmrq/cli'
6
+ Bkmrq::Cli.new(ARGV)
data/lib/bkmrq/app.rb ADDED
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'fileutils'
5
+ require 'bkmrq/docs_template'
6
+ require 'bkmrq/browser_config'
7
+
8
+ module Bkmrq
9
+ # Bookmarks Document Generator
10
+ class App
11
+ BLOCKLIST = ENV.fetch('BKMRQ_BLOCKLIST', '(pdf|google|file:)').split(',').map(&:strip)
12
+
13
+ def initialize(browser: nil, input_file: nil, output_path: nil, edit: false)
14
+ @bookmarks_input = input_file || Bkmrq::BROWSER_CONFIG.dig(browser, :bookmark_file_path)
15
+ @output_path = output_path || FileUtils.pwd
16
+ end
17
+
18
+ def export!
19
+ write_template
20
+ export(bookmarks['bookmark_bar'])
21
+ export(bookmarks['other'])
22
+ export(bookmarks['synced'])
23
+ output_file.close
24
+ end
25
+
26
+ private
27
+
28
+ def output_file
29
+ @output_file ||= ::File.open(
30
+ File.join(@output_path, "bkmrq_export_#{String(Integer(Time.now))[0..-2]}.md"),
31
+ 'w+'
32
+ )
33
+ end
34
+
35
+ def bookmarks
36
+ @bookmarks ||= ::File.open(@bookmarks_input, 'r') do |file|
37
+ JSON.parse(file.read)['roots']
38
+ end
39
+ end
40
+
41
+ def write_template
42
+ %i[title subtitle header_image description]
43
+ .map(&Bkmrq::DocsTemplate.method(:public_send))
44
+ .map(&output_file.method(:write))
45
+ end
46
+
47
+ def export(marqs = bookmarks, level = 1)
48
+ return if skip_export?(marqs)
49
+
50
+ output_file.write(generate_formatted_entity(marqs, level))
51
+ marqs.fetch('children', []).empty? ||
52
+ marqs['children'].map { |child| export(child, level + 1) }
53
+ end
54
+
55
+ def skip_export?(bookmark_section)
56
+ [bookmark_section['name'], bookmark_section['name']].any? do |meta|
57
+ BLOCKLIST.any? { |pattern| !meta&.match(pattern).nil? }
58
+ end
59
+ end
60
+
61
+ def generate_formatted_entity(bookmark, level)
62
+ if bookmark['url'].nil?
63
+ generate_bookmark_title(bookmark, level)
64
+ else
65
+ generate_bookmark_link(bookmark, level)
66
+ end
67
+ end
68
+
69
+ def generate_bookmark_title(bookmark, level)
70
+ [
71
+ ' ' * level,
72
+ '#' * level,
73
+ "#{bookmark['name']}\n"
74
+ ].join(' ')
75
+ end
76
+
77
+ def generate_bookmark_link(bookmark, level)
78
+ [
79
+ ' ' * level,
80
+ "[#{bookmark['name']}](#{bookmark['url']}) \n"
81
+ ].join(' ')
82
+ end
83
+ end
84
+ end
@@ -17,7 +17,8 @@ module Bkmrq
17
17
  }.freeze
18
18
 
19
19
  BROWSER_CONFIG = {
20
- brave: BRAVE_BROWSER_CONFIG,
21
- chrome: CHROME_BROWSER_CONFIG
20
+ 'brave' => BRAVE_BROWSER_CONFIG,
21
+ 'chrome' => CHROME_BROWSER_CONFIG,
22
+ 'chromium' => CHROME_BROWSER_CONFIG
22
23
  }.freeze
23
24
  end
@@ -3,27 +3,32 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  require 'optparse'
6
- require 'pry'
7
-
8
- require_relative 'bkmrq'
9
- require_relative 'manual'
6
+ require 'bkmrq/app'
7
+ require 'bkmrq/manual'
10
8
 
11
9
  module Bkmrq
12
10
  # Cli
13
11
  class Cli
14
12
  def initialize(args)
15
13
  @opts = {}
16
- option_parser.parse!(sanitize_args(args), into: @opts)
14
+ option_parser.parse!(default_args(sanitize_args(args)), into: @opts)
15
+ init_app if opts_valid?
17
16
  end
18
17
 
19
18
  private
20
19
 
20
+ def init_app
21
+ Bkmrq::App.new(
22
+ **@opts.slice(*Bkmrq::Manual.options_specs.map(&:last))
23
+ ).export!
24
+ end
25
+
21
26
  def option_parser
22
27
  @option_parser ||= OptionParser.new do |args|
23
28
  # Option Parsing
24
29
  Bkmrq::Manual.options_specs.map do |option_spec|
25
30
  option_key = option_spec.pop
26
- args.on(*option_spec) { |input| @opts.send(:[]=, option_key, input) }
31
+ args.on(*option_spec) { |input| @opts[option_key] = input }
27
32
  end
28
33
 
29
34
  # Manual Printing
@@ -35,5 +40,13 @@ module Bkmrq
35
40
  def sanitize_args(args)
36
41
  args.reject(&:empty?).map(&:scrub).map(&:split).flatten
37
42
  end
43
+
44
+ def default_args(args)
45
+ args.empty? ? ['-H'] : args
46
+ end
47
+
48
+ def opts_valid?
49
+ !@opts.key?(:help)
50
+ end
38
51
  end
39
52
  end
File without changes
@@ -26,7 +26,8 @@ module Bkmrq
26
26
  '-B BROWSER',
27
27
  '--browser BROWSER',
28
28
  String,
29
- 'Browser (Loads Default Configs)', :browser
29
+ 'Browser (Loads Default Configs)',
30
+ :browser
30
31
  ]
31
32
  end
32
33
 
@@ -36,7 +37,7 @@ module Bkmrq
36
37
  '--input-file FILE',
37
38
  String,
38
39
  'Bookmarks file generated by your browser. (JSON FORMAT ONLY)',
39
- :'input-file'
40
+ :input_file
40
41
  ]
41
42
  end
42
43
 
@@ -46,7 +47,7 @@ module Bkmrq
46
47
  '--output-file FILE',
47
48
  String,
48
49
  'Filepath for markdown generated by Bkmrq',
49
- :'output-file'
50
+ :output_path
50
51
  ]
51
52
  end
52
53
 
data/lib/bkmrq.rb CHANGED
@@ -1,82 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
- require_relative 'docs_template'
5
- require_relative 'browser_config'
6
-
7
3
  module Bkmrq
8
- # Bookmarks Document Generator
9
- class App
10
- BLOCKLIST = ENV.fetch('BKMRQ_BLOCKLIST', '(pdf|google|file:)').split(',').map(&:strip)
11
-
12
- def initialize(browser: :brave, bookmarks_input: nil)
13
- @bookmarks_input = bookmarks_input || Bkmrq::BROWSER_CONFIG.dig(browser, :bookmark_file_path)
14
- end
15
-
16
- def export!
17
- write_template
18
- export(bookmarks['bookmark_bar'])
19
- export(bookmarks['other'])
20
- export(bookmarks['synced'])
21
- output_file.close
22
- end
23
-
24
- private
25
-
26
- def output_file
27
- @output_file ||= ::File.open(
28
- "bkmrq_export_#{String(Integer(Time.now))[0..-2]}.md",
29
- 'w+'
30
- )
31
- end
32
-
33
- def bookmarks
34
- @bookmarks ||= ::File.open(@bookmarks_input, 'r') do |file|
35
- JSON.parse(file.read)['roots']
36
- end
37
- end
38
-
39
- def write_template
40
- %i[title subtitle header_image description]
41
- .map(&Bkmrq::DocsTemplate.method(:public_send))
42
- .map(&output_file.method(:write))
43
- end
44
-
45
- def export(marqs = bookmarks, level = 1)
46
- return if skip_export?(marqs)
47
-
48
- output_file.write(generate_formatted_entity(marqs, level))
49
- marqs.fetch('children', []).empty? ||
50
- marqs['children'].map { |child| export(child, level + 1) }
51
- end
52
-
53
- def skip_export?(bookmark_section)
54
- [bookmark_section['name'], bookmark_section['name']].any? do |meta|
55
- BLOCKLIST.any? { |pattern| !meta&.match(pattern).nil? }
56
- end
57
- end
58
-
59
- def generate_formatted_entity(bookmark, level)
60
- if bookmark['url'].nil?
61
- generate_bookmark_title(bookmark, level)
62
- else
63
- generate_bookmark_link(bookmark, level)
64
- end
65
- end
66
-
67
- def generate_bookmark_title(bookmark, level)
68
- [
69
- ' ' * level,
70
- '#' * level,
71
- "#{bookmark['name']}\n"
72
- ].join(' ')
73
- end
74
-
75
- def generate_bookmark_link(bookmark, level)
76
- [
77
- ' ' * level,
78
- "[#{bookmark['name']}](#{bookmark['url']}) \n"
79
- ].join(' ')
80
- end
81
- end
4
+ require 'bkmrq/app'
5
+ require 'bkmrq/browser_config'
6
+ require 'bkmrq/cli'
7
+ require 'bkmrq/docs_template'
8
+ require 'bkmrq/manual'
82
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bkmrq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sreedev Kodichath
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-04 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Bkmrq Converts Bookmarks stored by your browser in JSON format to a readable
14
14
  markdown format
@@ -19,12 +19,12 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - bin/bkmrq
22
- - lib/app.rb
23
22
  - lib/bkmrq.rb
24
- - lib/browser_config.rb
25
- - lib/cli.rb
26
- - lib/docs_template.rb
27
- - lib/manual.rb
23
+ - lib/bkmrq/app.rb
24
+ - lib/bkmrq/browser_config.rb
25
+ - lib/bkmrq/cli.rb
26
+ - lib/bkmrq/docs_template.rb
27
+ - lib/bkmrq/manual.rb
28
28
  homepage: https://rubygems.org/gems/bkmrq
29
29
  licenses:
30
30
  - MIT
data/lib/app.rb DELETED
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'cli'
4
-
5
- Bkmrq::Cli.new(ARGV)