Class: GHPreview::Previewer

Inherits:
Object
  • Object
show all
Defined in:
lib/ghpreview/previewer.rb

Instance Method Summary collapse

Constructor Details

#initialize(md_filepath, options = {}) ⇒ Previewer

Returns a new instance of Previewer.



9
10
11
12
13
14
15
16
# File 'lib/ghpreview/previewer.rb', line 9

def initialize(md_filepath, options = {})
  Wrapper.generate_template_with_fingerprinted_stylesheet_links

  @md_filepath = md_filepath
  @application = options[:application]

  options[:watch] ? listen : open
end

Instance Method Details

#listenObject



18
19
20
21
22
23
# File 'lib/ghpreview/previewer.rb', line 18

def listen
  puts "Previewing #{@md_filepath}. CTRL-C to stop."
  Watcher.watch @md_filepath do
    open
  end
end

#openObject



25
26
27
28
29
# File 'lib/ghpreview/previewer.rb', line 25

def open
  html = Converter.to_html(File.read(@md_filepath))
  html = Wrapper.wrap_html(html)
  Viewer.view_html html, @application
end