Class: GfmLivePreview::Server

Inherits:
Sinatra::Application
  • Object
show all
Defined in:
lib/gfm_live_preview/server.rb

Instance Method Summary collapse

Instance Method Details

#doc_pathObject



23
24
25
# File 'lib/gfm_live_preview/server.rb', line 23

def doc_path
  File.expand_path '..', ::GfmLivePreview.file
end

#render_documentObject



17
18
19
20
21
# File 'lib/gfm_live_preview/server.rb', line 17

def render_document
  document = File.read ::GfmLivePreview.file
  syntax_highlight! document
  GitHub::Markdown.render_gfm document
end

#syntax_highlight!(str) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/gfm_live_preview/server.rb', line 8

def syntax_highlight! str
  SyntaxHighlighter.highlight! str do |string, hexcolor|
    "<span style=\"color:##{hexcolor}\">#{string}</span>"
  end
rescue => e
  puts "Exception during syntax highlighting: #{e}"
  e.backtrace.each do |line| puts line; end
end