Permalink
Browse files

Merge branch 'refactor/rewrite'

  • Loading branch information...
2 parents ffc45dd + 5900e77 commit 0cab2e61ff6ab5bab14e2353ad56f1a77e25df59 @r-obert r-obert committed Jan 17, 2012
View
@@ -1,14 +1,23 @@
-![Hammer Mario!](http://i.imgur.com/HUuvF.png)
+__OVERVIEW__
-Hammer.vim can translate a bunch of markup languages to HTML, and preview them in your browser of choice. All from within vim!
-By default, the preview is a clone of how GitHub would render _README.md_, but custom templates of your own are supported too.
+| Project | Hammer.vim
+|:----------------|:--------------------------------------------------
+| Homepage | https://github.com/robgleeson/hammer.vim
+| Author | Rob Gleeson
-This project was formerly _vim-markdown-preview_.
+__DESCRITPION__
-Supported Markup
-----------------
+Hammer is a Vim plugin written in Ruby that can be used to render your favorite
+markup language to HTML for viewing in your browser of choice.
-Anything _github-markup_ supports:
+It supports a large number of markup languages out of box but it also supports
+adding custom renderers for markup languages it does not support.
+
+It has support for multiple different layout (with one styled like the GitHub
+README layout). You can use your favorite template language to draw up your own
+layouts (ERB, HAML, …). Layouts are passed the rendered HTML as a partial.
+
+__SUPPORTED MARKUP__
* [.markdown](http://daringfireball.net/projects/markdown/) -- `gem install redcarpet`
* [.textile](http://www.textism.com/tools/textile/) -- `gem install RedCloth`
@@ -24,68 +33,23 @@ Anything _github-markup_ supports:
* .html
* .xhtml
-Requirements
-------------
-* vim built with Ruby support.
-* github-markup (_See install instructions_)
-* You might need to install an extra dependency depending on the markup language you want to render (See Above).
+__INSTALL__
-Install
--------
+You may need to install other dependencies for your markup language (See Above)
- $ [sudo] gem install github-markup
+ $ [sudo] gem install github-markup tilt albino
+ $ [sudo] sudo easy_install pygments
$ git clone git://github.com/robgleeson/hammer.vim.git
$ cp -R hammer.vim/plugin/* $HOME/.vim/plugin
-Usage
------
-
-The `:Hammer` command will try to draw a preview of whatever file is currently in your buffer.
-It helps to map it to a key though, and I personally use: `map <leader>p :Hammer<CR>`
-
-There are a few options, too:
-
-* g:HammerTemplate
- The template to render with. Default is `default`, a GitHub-esque design.
-
-* g:HammerDirectory
- Where previews are written to.
- Default is `%TEMP%` on Windows, and `/tmp` on everything else.
-
-* g:HammerBrowser
- The template to open the preview with. Default is OS-dependent.
- `open` on OSX, `start` on Windows, and `xdg-open` on xorg-running machines.
-
-
-
-Templates!
-----------
-
-If you don't like the default template, you can write your own.
-Templates are ERB layouts with rendered markup passed on as a partial.
-Templates have access to paths used by Hammer, so you can link to assets(CSS, etc) easily.
-
-The [default template](http://bit.ly/jaNkaJ) serves as a good example to get you going.
-Pull requests for new templates would be awesome ;-)
-
-Screenshots
------------
+__SCREENSHOTS__
* [POD](http://d.pr/16YG)
* [Markdown](http://d.pr/GEuT)
+__LICENSE__
-Thanks
-------
-
-Many thanks to the @github team for _github-markup_!
-
-License
---------
-
-_Hammer.vim_ is released under the [_MIT License_](http://en.wikipedia.org/wiki/MIT_License).
-See [LICENSE](http://github.com/robgleeson/hammer.vim/blob/master/LICENSE) for details.
-
+See LICENSE.txt
@@ -0,0 +1,52 @@
+if !exists('g:HAMMER_INSTALL_PATH')
+ let g:HAMMER_INSTALL_PATH = fnamemodify(expand("<sfile>"), ":p:h")
+end
+
+if !exists('g:HAMMER_SILENCE_WARNINGS')
+ let g:HAMMER_SILENCE_WARNINGS = 0
+endif
+
+if !exists('g:HAMMER_DIRECTORY')
+ if has('win32') || has('win64')
+ let g:HAMMER_DIRECTORY = $TEMP
+ else
+ let g:HAMMER_DIRECTORY = '/tmp'
+ end
+endif
+
+if !exists('g:HAMMER_BROWSER')
+ if has('mac')
+ let g:HAMMER_BROWSER = 'open'
+ elseif has('win32') || has('win64')
+ ruby require 'hammer/vim-windows/rubygems'
+ let g:HAMMER_BROWSER = 'start'
+ elseif has('unix') && executable('xdg-open')
+ let g:HAMMER_BROWSER = 'xdg-open'
+ else
+ let g:HAMMER_BROWSER = ''
+ end
+endif
+
+if !exists('g:HAMMER_TEMPLATE')
+ let g:HAMMER_TEMPLATE = 'default'
+endif
+
+ruby $: << File.join(Vim.evaluate('g:HAMMER_INSTALL_PATH'), 'lib')
+ruby require 'hammer'
+ruby Hammer.load_dependencies!
+ruby Hammer.load_renderers!
+
+if has('ruby')
+ function! Hammer()
+ ruby <<RENDER!
+ buffer = Vim::Buffer.current.extend Vim::ImprovedBuffer
+ Hammer.render!(buffer)
+RENDER!
+ endfunction
+else
+ function! Hammer()
+ echo "Sorry, hammer.vim requires vim to be built with Ruby support."
+ endfunction
+end
+
+:command! Hammer :call Hammer()
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings FATAL => 'all';
+use Pod::Simple::HTML;
+
+my $parser = Pod::Simple::HTML->new;
+
+$parser->output_string(\my $html);
+
+my $fh = *STDIN;
+$parser->parse_file( $fh );
+
+print $html;
@@ -1,40 +0,0 @@
-if !exists('g:HammerQuiet')
- let g:HammerQuiet = 0
-end
-
-if !exists('g:HammerDirectory')
- if has('win32') || has('win64')
- let g:HammerDirectory = $TEMP
- else
- let g:HammerDirectory = '/tmp'
- end
-endif
-
-if !exists('g:HammerBrowser')
- if has('mac')
- let g:HammerBrowser = 'open'
- elseif has('win32') || has('win64')
-
- " Crazy hack to be able to load Gems on Vim/Windows.
- " No idea _why_ rubygems can't be loaded from inside vim ...
- ruby << GEM_HACK
- require 'rubygems'
- Gem.source_index.find_name(//).each do |spec|
- spec.require_paths.each do |require_path|
- $LOAD_PATH.push File.join(spec.full_gem_path, require_path)
- end
- end
-GEM_HACK
-
- let g:HammerBrowser = 'start'
- elseif has('unix') && executable('xdg-open')
- let g:HammerBrowser = 'xdg-open'
- else
- let g:HammerBrowser = ''
- end
-endif
-
-if !exists('g:HammerTemplate')
- let g:HammerTemplate = 'default'
-endif
-
@@ -1,49 +0,0 @@
-if has('ruby')
- let g:HammerLocation = fnamemodify(expand("<sfile>"), ":p:h")
-
- ruby $LOAD_PATH.unshift Vim.evaluate('g:HammerLocation')
- ruby require 'rubygems'
- ruby require 'lib/hammer'
- ruby require 'lib/hammer/env'
- ruby require 'lib/vim/improvedbuffer'
- ruby require 'erb'
- ruby require 'shellwords'
- ruby << REQUIRE_GHMARKUP
- begin
- require 'github/markup'
- rescue LoadError => e
- unless Vim.evaluate('g:HammerQuiet') == 1
- Vim.message "github-markup is missing: Please run `gem install github-markup`. " \
- "Set g:HammerQuiet to 1 to silence this message"
- end
- end
-REQUIRE_GHMARKUP
-
-
- function! Hammer()
- ruby << RUBY
- buffer = Vim::Buffer.current.extend Vim::ImprovedBuffer
-
- if GitHub::Markup.can_render? buffer.basename
- path = File.join Hammer::ENV.directory, "#{buffer.basename}.html"
-
- File.open path, 'w' do |f|
- f.write Hammer.render { GitHub::Markup.render(buffer.basename, buffer[0..-1]) }
- end
-
- Hammer.open_browser path
- elsif buffer.extname =~ /^\.(xhtml|html)$/
- Hammer.open_browser buffer.name
- else
- Vim.message "It is not possible to render #{buffer.extname} files. Missing dependency?"
- end
-RUBY
- endfunction
-
-else
- function! Hammer()
- echo "Sorry, hammer.vim requires vim to be built with Ruby support"
- endfunction
-end
-
-:command! Hammer :call Hammer()
Oops, something went wrong.

0 comments on commit 0cab2e6

Please sign in to comment.