Skip to content
This repository
Browse code

Merge branch 'add_hammer' into experimental

closes #267

* add_hammer:
  Rakefile: Gem.source_index is also deperecated, use Gem::Specification but be backward-compatible with older versions of rubygems.
  Janus tools/hammer: Fix the installation script for using find_gem instead.
  Rakefile: Add a method to find an installed gem.
  Janus tools/hammer: Add installation task.
  Janus Tools: Add hammer.

Conflicts:
	.gitmodules
	Rakefile
  • Loading branch information...
commit 50fb70e05f752a8adf25095a24f18f1cbdfc93aa 2 parents 3a904dd + baad78a
Wael M. Nasreddine eMxyzptlk authored
3  .gitmodules
@@ -73,3 +73,6 @@
73 73 [submodule "janus-core/surround"]
74 74 path = janus-core/surround
75 75 url = git://github.com/tpope/vim-surround.git
  76 +[submodule "janus-tools/hammer"]
  77 + path = janus-tools/hammer
  78 + url = git://github.com/robgleeson/hammer.vim.git
23 Rakefile
... ... @@ -1,4 +1,8 @@
1 1 module Janus
  2 + # Errors
  3 + JanusError = Class.new Exception
  4 + RubyGemsNotFoundError = Class.new JanusError
  5 +
2 6 module VIM
3 7 extend self
4 8
@@ -24,6 +28,25 @@ def expand(file)
24 28 File.expand_path(file)
25 29 end
26 30
  31 +# Find an installed gem
  32 +#
  33 +# @param [String] The gem name to search for
  34 +# @return [Array] The found gems
  35 +def find_gem(gem_name)
  36 + begin
  37 + require 'rubygems'
  38 + if Gem.const_defined?(:Specification)
  39 + Gem::Specification.find_all_by_name(gem_name)
  40 + elsif Gem.respond_to?(:source_index)
  41 + Gem.source_index.find_name(gem_name)
  42 + else
  43 + Gem.cache.find_name(gem_name)
  44 + end
  45 + rescue LoadError
  46 + raise Janus::RubyGemsNotFoundError
  47 + end
  48 +end
  49 +
27 50 namespace :plugins do
28 51 task :install do
29 52 # dummy task for plugin installation tasks.
1  janus-tools/hammer
... ... @@ -0,0 +1 @@
  1 +Subproject commit 8cf24763ed792fe54ab4afb42c1dde896341a325
13 janus-tools/janus/plugin/hammer.vim
... ... @@ -0,0 +1,13 @@
  1 +function s:setupMarkup()
  2 + map <buffer> <Leader>p :Hammer<CR>
  3 +endfunction
  4 +
  5 +if executable("redcarpet")
  6 + " define buffer-local preview for markdown files
  7 + au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup()
  8 +endif
  9 +
  10 +if executable("redcloth")
  11 + " define buffer-local preview for textile files
  12 + au BufRead,BufNewFile *.textile call s:setupMarkup()
  13 +endif
18 janus-tools/tasks/hammer.rake
... ... @@ -0,0 +1,18 @@
  1 +namespace :plugins do
  2 + desc "Install the hammer plugin."
  3 + task :install_hammer do
  4 + begin
  5 + if find_gem('github-markup').length == 0
  6 + sh "gem install github-markup"
  7 + end
  8 + if find_gem('redcarpet').length == 0
  9 + sh "gem install redcarpet"
  10 + end
  11 + rescue Janus::RubyGemsNotFoundError
  12 + puts "Could not install github-markup and redcarpet, please install them manually."
  13 + puts "gem install github-markup redcarpet"
  14 + end
  15 + end
  16 +
  17 + task :install => :install_hammer
  18 +end

0 comments on commit 50fb70e

Please sign in to comment.
Something went wrong with that request. Please try again.