Class: Vim::Jar::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/vim-jar/config.rb

Instance Method Summary collapse

Instance Method Details

#autoload_homeObject



44
45
46
# File 'lib/vim-jar/config.rb', line 44

def autoload_home 
  Pathname.new(vim_home.join("autoload"))
end

#bundle_file_pathObject



56
57
58
# File 'lib/vim-jar/config.rb', line 56

def bundle_file_path
  vim_home.join("BundleFile")
end

#bundle_homeObject



39
40
41
# File 'lib/vim-jar/config.rb', line 39

def bundle_home 
  Pathname.new(vim_home.join("bundle"))
end

#bundle_template_file_pathObject



60
61
62
# File 'lib/vim-jar/config.rb', line 60

def bundle_template_file_path 
  vim_jar_lib.join("templates", "BundleFile")
end

#checkObject



64
65
66
67
68
69
70
# File 'lib/vim-jar/config.rb', line 64

def check 
  check_vim_pathes!
  self.init_git_repo unless under_git?
  self.setup_pathogen unless File.exist?(self.pathogen_path)
  self.create_bundle_home unless File.exist?(self.bundle_home)
  self.init_bundle_file unless File.exists?(self.bundle_file_path)
end

#check_vim_pathes!Object



72
73
74
75
76
77
# File 'lib/vim-jar/config.rb', line 72

def check_vim_pathes!
  %w[vim_home vimrc_path].each do |method_name|
    path = self.send(method_name)
    raise InitError.new("#{path} doesn't exist") unless File.exist?(path)
  end
end

#create_bundle_homeObject



92
93
94
95
# File 'lib/vim-jar/config.rb', line 92

def create_bundle_home 
  FileUtils.mkdir_p(bundle_home) 
  STDOUT.puts "create folder for pathogen in #{bundle_home}"
end

#gitconfig_file_pathObject



35
36
37
# File 'lib/vim-jar/config.rb', line 35

def gitconfig_file_path
  vim_home.join(".git",'config')
end

#gitmodules_file_pathObject



31
32
33
# File 'lib/vim-jar/config.rb', line 31

def gitmodules_file_path
  vim_home.join(".gitmodules")
end

#init_bundle_fileObject



115
116
117
118
119
120
121
122
123
# File 'lib/vim-jar/config.rb', line 115

def init_bundle_file
  FileUtils.cp bundle_template_file_path, bundle_file_path
  STDOUT.puts <<-EOF

  Writing new BundleFile to #{self.bundle_file_path}. 

  You can add more plugins by modify this file
  EOF
end

#init_git_repoObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/vim-jar/config.rb', line 79

def init_git_repo
  Dir.chdir(self.vim_home) do 
    message = <<-EOF
  your .vim folder is not a git repository.  we'll init git repository for you.

    You can make use of git submodule to manage your plugins.
    Futher more you can push your git repository to www.github.com.
    EOF
    STDOUT.puts message
    system("git init")
  end
end

#install_pathogenObject



110
111
112
113
# File 'lib/vim-jar/config.rb', line 110

def install_pathogen
  FileUtils.mkdir_p(autoload_home) if !File.exist?(autoload_home)
  FileUtils.cp pathogen_vim_path, pathogen_path
end

#pathogen_pathObject



48
49
50
# File 'lib/vim-jar/config.rb', line 48

def pathogen_path
  Pathname.new(vim_home.join("autoload",'pathogen.vim'))
end

#pathogen_vim_path(version = "1.2") ⇒ Object



52
53
54
# File 'lib/vim-jar/config.rb', line 52

def pathogen_vim_path(version="1.2") 
  vim_jar_lib.join("vim-jar","pathogen","pathogen_v#{version}.vim")
end

#setup_pathogenObject



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/vim-jar/config.rb', line 97

def setup_pathogen
  self.install_pathogen
  STDOUT.puts <<-EOF

  Pathogen is installed into #{self.pathogen_path}. 

  NOTICE: you need copy line below into #{self.vimrc_path}.

  call pathogen#runtime_append_all_bundles() 

  EOF
end

#under_git?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/vim-jar/config.rb', line 27

def under_git?
  @under_git ||= File.exist?(vim_home.join(".git"))
end

#user_homeObject



15
16
17
# File 'lib/vim-jar/config.rb', line 15

def user_home 
  Pathname.new(ENV['VIM_JAR_USER_HOME'] || ::Gem.user_home)
end

#vim_homeObject



19
20
21
# File 'lib/vim-jar/config.rb', line 19

def vim_home 
  Pathname.new(user_home.join(".vim"))
end

#vim_jar_libObject



11
12
13
# File 'lib/vim-jar/config.rb', line 11

def vim_jar_lib 
  Pathname.new(vim_jar_root.join("lib"))
end

#vim_jar_rootObject



7
8
9
# File 'lib/vim-jar/config.rb', line 7

def vim_jar_root 
  Pathname.new(File.expand_path("../../",File.dirname(__FILE__)))
end

#vimrc_pathObject



23
24
25
# File 'lib/vim-jar/config.rb', line 23

def vimrc_path
  user_home.join(".vimrc")
end