hammer.vim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. if has('ruby')
  2. let g:HammerLocation = fnamemodify(expand("<sfile>"), ":p:h")
  3. ruby $LOAD_PATH.unshift Vim.evaluate('g:HammerLocation')
  4. ruby require 'rubygems'
  5. ruby require 'github/markup'
  6. ruby require 'lib/hammer'
  7. ruby require 'lib/hammer/env'
  8. ruby require 'lib/vim/improvedbuffer'
  9. ruby require 'erb'
  10. function! Hammer()
  11. ruby << RUBY
  12. buffer = Vim::Buffer.current.extend Vim::ImprovedBuffer
  13. if GitHub::Markup.can_render? buffer.basename
  14. File.open File.join(Hammer::ENV.directory, "#{buffer.basename}.html"), 'w' do |f|
  15. f.write Hammer.render { GitHub::Markup.render(buffer.basename, buffer[1..-1]) }
  16. end
  17. Vim.command "silent ! #{Hammer::ENV.browser} #{File.join Hammer::ENV.directory, buffer.basename}.html"
  18. Vim.command "redraw!"
  19. elsif buffer.extname =~ /^\.(xhtml|html)$/
  20. Vim.command "silent ! #{Hammer::ENV.browser} #{buffer.name}"
  21. Vim.command "redraw!"
  22. else
  23. Vim.message "It is not possible to render #{buffer.extname} files. Missing dependency?"
  24. end
  25. RUBY
  26. endfunction
  27. else
  28. function! Hammer()
  29. echo "Sorry, hammer.vim requires vim to be built with Ruby support"
  30. endfunction
  31. end
  32. :command! Hammer :call Hammer()