Class: GHPreview::Viewer

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

Constant Summary collapse

HTML_FILEPATH =
'/tmp/ghpreview.html'

Class Method Summary collapse

Class Method Details

.view_html(html, application = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ghpreview/viewer.rb', line 5

def self.view_html(html, application = nil)
  File.open(HTML_FILEPATH, 'w') { |f| f << html }

  if RUBY_PLATFORM =~ /linux/
    command = if application
                `#{application} #{HTML_FILEPATH} </dev/null &>/dev/null &`
                else
                `xdg-open #{HTML_FILEPATH}`
              end
  else
    command = if application
                "open -a #{application}"
              else
                'open'
              end
    `#{command} #{HTML_FILEPATH}`
  end
end