Skip to content

Commit

Permalink
Use vim TOhtml command as fallback when GitHub::Markup cannot render
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitronx committed Jan 24, 2013
1 parent 3bb1623 commit 801c11b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions plugin/hammer.vim/lib/hammer.rb
Expand Up @@ -105,7 +105,10 @@ def render! buffer
return nil
end

unless GitHub::Markup.can_render?(buffer.basename)
has_tohtml = if Vim.evaluate('!&cp && exists(":TOhtml") && has("user_commands")') == 1 then true else nil end
cleanup = nil

unless GitHub::Markup.can_render?(buffer.basename) || has_tohtml
msg = "Cannot render '#{buffer.extname}' files. Missing renderer?"
Vim.message(msg)
return nil
Expand All @@ -116,10 +119,20 @@ def render! buffer
File.open path, 'w' do |f|
tilt = Tilt.new(Hammer::ENV.template)
output = tilt.render do
GitHub::Markup.render(buffer.basename, buffer[1..-1])
if ! GitHub::Markup.can_render?(buffer.basename) && has_tohtml
Vim.command 'TOhtml'
tohtml_buffer = Vim::Buffer.current.extend Vim::ImprovedBuffer
cleanup = if tohtml_buffer != buffer then true else nil end
GitHub::Markup.render(tohtml_buffer.basename, tohtml_buffer[1..-1])

else
GitHub::Markup.render(buffer.basename, buffer[1..-1])
end
end

f.write(output)

Vim.command 'bdelete!' if cleanup
end

Hammer.open_browser path
Expand Down

0 comments on commit 801c11b

Please sign in to comment.