class Bkmrq::App
Bookmarks Document Generator
Constants
- BLOCKLIST
Public Class Methods
new(browser: nil, input_file: nil, output_path: nil, edit: false)
click to toggle source
# File lib/bkmrq/app.rb, line 13 def initialize(browser: nil, input_file: nil, output_path: nil, edit: false) @bookmarks_input = input_file || Bkmrq::BROWSER_CONFIG.dig(browser, :bookmark_file_path) @output_path = output_path || FileUtils.pwd end
Public Instance Methods
export!()
click to toggle source
# File lib/bkmrq/app.rb, line 18 def export! write_template export(bookmarks['bookmark_bar']) export(bookmarks['other']) export(bookmarks['synced']) output_file.close end
Private Instance Methods
bookmarks()
click to toggle source
# File lib/bkmrq/app.rb, line 35 def bookmarks @bookmarks ||= ::File.open(@bookmarks_input, 'r') do |file| JSON.parse(file.read)['roots'] end end
export(marqs = bookmarks, level = 1)
click to toggle source
# File lib/bkmrq/app.rb, line 47 def export(marqs = bookmarks, level = 1) return if skip_export?(marqs) output_file.write(generate_formatted_entity(marqs, level)) marqs.fetch('children', []).empty? || marqs['children'].map { |child| export(child, level + 1) } end
generate_bookmark_link(bookmark, level)
click to toggle source
# File lib/bkmrq/app.rb, line 76 def generate_bookmark_link(bookmark, level) [ ' ' * (level % 2), "[#{bookmark['name']}](#{bookmark['url']}) \n" ].join(' ') end
generate_bookmark_title(bookmark, level)
click to toggle source
# File lib/bkmrq/app.rb, line 69 def generate_bookmark_title(bookmark, level) [ '#' * level, "#{bookmark['name']}\n" ].join(' ') end
generate_formatted_entity(bookmark, level)
click to toggle source
# File lib/bkmrq/app.rb, line 61 def generate_formatted_entity(bookmark, level) if bookmark['url'].nil? generate_bookmark_title(bookmark, level) else generate_bookmark_link(bookmark, level) end end
output_file()
click to toggle source
# File lib/bkmrq/app.rb, line 28 def output_file @output_file ||= ::File.open( File.join(@output_path, "bkmrq_export_#{String(Integer(Time.now))[0..-2]}.md"), 'w+' ) end
skip_export?(bookmark_section)
click to toggle source
# File lib/bkmrq/app.rb, line 55 def skip_export?(bookmark_section) [bookmark_section['name'], bookmark_section['name']].any? do |meta| BLOCKLIST.any? { |pattern| !meta&.match(pattern).nil? } end end
write_template()
click to toggle source
# File lib/bkmrq/app.rb, line 41 def write_template %i[title subtitle header_image description] .map(&Bkmrq::DocsTemplate.method(:public_send)) .map(&output_file.method(:write)) end