class Md2key::CLI
Public Instance Methods
convert(path)
click to toggle source
# File lib/md2key/cli.rb, line 11 def convert(path) abort "md2key: `#{path}` does not exist" unless File.exist?(path) markdown = File.read(path) config = ConfigLoader.load('~/.md2key', './.md2key') ast = Parser.new.parse(markdown) Renderer.new(config).render!(ast) end
init()
click to toggle source
# File lib/md2key/cli.rb, line 22 def init yaml = ConfigBuilder.build(skip_options: options[:skip_options]) File.write('.md2key', yaml) puts "# Successfully generated .md2key!\n#{yaml}" end
listen(path)
click to toggle source
# File lib/md2key/cli.rb, line 29 def listen(path) require 'listen' puts 'Watching the *.md file...' listener = Listen.to('./', only: /\.md$/) do |_| convert(path) && (puts "The *.key file has been updated. let's open *.key file!") end listener.start sleep rescue Interrupt puts 'Bye.' end
Private Instance Methods
method_missing(*args)
click to toggle source
Shorthand for `md2key convert *.md`
Calls superclass method
# File lib/md2key/cli.rb, line 44 def method_missing(*args) path = args.first.to_s if args.length == 1 && path.end_with?('.md') convert(path) else return super(*args) end end