Module: Hologram::Utils

Defined in:
lib/hologram/utils.rb

Class Method Summary collapse

Class Method Details

.get_class_name(file) ⇒ Object



17
18
19
# File 'lib/hologram/utils.rb', line 17

def self.get_class_name(file)
  File.basename(file, '.rb').split(/_/).map(&:capitalize).join
end

.get_markdown_renderer(custom_markdown = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/hologram/utils.rb', line 3

def self.get_markdown_renderer(custom_markdown = nil)
  return MarkdownRenderer if custom_markdown.nil?

  md_file = Pathname.new(custom_markdown).realpath
  load md_file
  renderer_class = self.get_class_name(custom_markdown)
  DisplayMessage.info("Custom markdown renderer #{renderer_class} loaded.")
  Module.const_get(renderer_class)
rescue LoadError => e
  DisplayMessage.error("Could not load #{custom_markdown}.")
rescue NameError => e
  DisplayMessage.error("Class #{renderer_class} not found in #{custom_markdown}.")
end