vimjar 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +85 -0
  7. data/Guardfile +21 -0
  8. data/LICENSE +21 -0
  9. data/README.md +89 -0
  10. data/Rakefile +2 -0
  11. data/bin/vimjar +10 -0
  12. data/cucumber.yml +6 -0
  13. data/features/init.feature +37 -0
  14. data/features/install.feature +8 -0
  15. data/features/list.feature +7 -0
  16. data/features/step_definitions/command_steps.rb +21 -0
  17. data/features/step_definitions/environment_steps.rb +34 -0
  18. data/features/step_definitions/file_check_steps.rb +20 -0
  19. data/features/step_definitions/message_steps.rb +23 -0
  20. data/features/step_definitions/plugin_steps.rb +4 -0
  21. data/features/support/env.rb +22 -0
  22. data/features/support/hook.rb +8 -0
  23. data/features/support/stubs.rb +0 -0
  24. data/features/uninstall.feature +12 -0
  25. data/features/update.feature +7 -0
  26. data/lib/templates/BundleFile +1 -0
  27. data/lib/vim-jar/cli.rb +91 -0
  28. data/lib/vim-jar/config.rb +126 -0
  29. data/lib/vim-jar/installer/base.rb +9 -0
  30. data/lib/vim-jar/installer/git.rb +66 -0
  31. data/lib/vim-jar/installer.rb +7 -0
  32. data/lib/vim-jar/loader.rb +32 -0
  33. data/lib/vim-jar/pathogen/pathogen_v1.2.vim +139 -0
  34. data/lib/vim-jar/plugin/git.rb +41 -0
  35. data/lib/vim-jar/plugin.rb +23 -0
  36. data/lib/vim-jar/version.rb +5 -0
  37. data/lib/vim-jar.rb +24 -0
  38. data/script/github_crawler.rb +76 -0
  39. data/spec/spec_helper.rb +24 -0
  40. data/spec/vim-jar/config_spec.rb +126 -0
  41. data/spec/vim-jar/git-config +16 -0
  42. data/spec/vim-jar/gitmodules +6 -0
  43. data/spec/vim-jar/installer/git_spec.rb +51 -0
  44. data/spec/vim-jar/loader_spec.rb +43 -0
  45. data/spec/vim-jar/plugin/git-config +1 -0
  46. data/spec/vim-jar/plugin/git_spec.rb +41 -0
  47. data/spec/vim-jar/plugin/gitmodules +1 -0
  48. data/spec/vim-jar/plugin_spec.rb +11 -0
  49. data/spec/vim-jar_test.rb +17 -0
  50. data/vimjar.gemspec +33 -0
  51. metadata +302 -0
@@ -0,0 +1,126 @@
1
+ module Vim
2
+ module Jar
3
+ class Config
4
+ require 'singleton'
5
+ include Singleton
6
+
7
+ def vim_jar_root
8
+ Pathname.new(File.expand_path("../../",File.dirname(__FILE__)))
9
+ end
10
+
11
+ def vim_jar_lib
12
+ Pathname.new(vim_jar_root.join("lib"))
13
+ end
14
+
15
+ def user_home
16
+ Pathname.new(ENV['VIM_JAR_USER_HOME'] || ::Gem.user_home)
17
+ end
18
+
19
+ def vim_home
20
+ Pathname.new(user_home.join(".vim"))
21
+ end
22
+
23
+ def vimrc_path
24
+ user_home.join(".vimrc")
25
+ end
26
+
27
+ def under_git?
28
+ @under_git ||= File.exist?(vim_home.join(".git"))
29
+ end
30
+
31
+ def gitmodules_file_path
32
+ vim_home.join(".gitmodules")
33
+ end
34
+
35
+ def gitconfig_file_path
36
+ vim_home.join(".git",'config')
37
+ end
38
+
39
+ def bundle_home
40
+ Pathname.new(vim_home.join("bundle"))
41
+ end
42
+
43
+
44
+ def autoload_home
45
+ Pathname.new(vim_home.join("autoload"))
46
+ end
47
+
48
+ def pathogen_path
49
+ Pathname.new(vim_home.join("autoload",'pathogen.vim'))
50
+ end
51
+
52
+ def pathogen_vim_path(version="1.2")
53
+ vim_jar_lib.join("vim-jar","pathogen","pathogen_v#{version}.vim")
54
+ end
55
+
56
+ def bundle_file_path
57
+ vim_home.join("BundleFile")
58
+ end
59
+
60
+ def bundle_template_file_path
61
+ vim_jar_lib.join("templates", "BundleFile")
62
+ end
63
+
64
+ def check
65
+ check_vim_pathes!
66
+ self.init_git_repo unless under_git?
67
+ self.setup_pathogen unless File.exist?(self.pathogen_path)
68
+ self.create_bundle_home unless File.exist?(self.bundle_home)
69
+ self.init_bundle_file unless File.exists?(self.bundle_file_path)
70
+ end
71
+
72
+ def check_vim_pathes!
73
+ %w[vim_home vimrc_path].each do |method_name|
74
+ path = self.send(method_name)
75
+ raise InitError.new("#{path} doesn't exist") unless File.exist?(path)
76
+ end
77
+ end
78
+
79
+ def init_git_repo
80
+ Dir.chdir(self.vim_home) do
81
+ message = <<-EOF
82
+ your .vim folder is not a git repository. we'll init git repository for you.
83
+
84
+ You can make use of git submodule to manage your plugins.
85
+ Futher more you can push your git repository to www.github.com.
86
+ EOF
87
+ STDOUT.puts message
88
+ system("git init")
89
+ end
90
+ end
91
+
92
+ def create_bundle_home
93
+ FileUtils.mkdir_p(bundle_home)
94
+ STDOUT.puts "create folder for pathogen in #{bundle_home}"
95
+ end
96
+
97
+ def setup_pathogen
98
+ self.install_pathogen
99
+ STDOUT.puts <<-EOF
100
+
101
+ Pathogen is installed into #{self.pathogen_path}.
102
+
103
+ NOTICE: you need copy line below into #{self.vimrc_path}.
104
+
105
+ call pathogen#runtime_append_all_bundles()
106
+
107
+ EOF
108
+ end
109
+
110
+ def install_pathogen
111
+ FileUtils.mkdir_p(autoload_home) if !File.exist?(autoload_home)
112
+ FileUtils.cp pathogen_vim_path, pathogen_path
113
+ end
114
+
115
+ def init_bundle_file
116
+ FileUtils.cp bundle_template_file_path, bundle_file_path
117
+ STDOUT.puts <<-EOF
118
+
119
+ Writing new BundleFile to #{self.bundle_file_path}.
120
+
121
+ You can add more plugins by modify this file
122
+ EOF
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,9 @@
1
+ module Vim
2
+ module Jar
3
+ module Installer
4
+ class Base
5
+ end
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,66 @@
1
+ module Vim
2
+ module Jar
3
+ module Installer
4
+ module Git
5
+ extend self
6
+
7
+ def install_to(source, output_path)
8
+ Dir.chdir(config.vim_home) do
9
+ system("git submodule add #{source} #{Pathname.new(output_path).relative_path_from(config.vim_home)}")
10
+ system("git submodule init")
11
+ end
12
+ end
13
+
14
+ def uninstall_for(name)
15
+ remove_ref_from_gitmodules(name)
16
+ remove_ref_from_git_config(name)
17
+ remove_from_cache(name)
18
+ end
19
+
20
+ def remove_from_cache(name)
21
+ Dir.chdir(config.vim_home) do
22
+ system("git rm -r --cached bundle/#{name}")
23
+ end
24
+ end
25
+
26
+ def remove_ref_from_gitmodules(name)
27
+ #TODO bundle name is different to submodule name
28
+ f = File.new(config.gitmodules_file_path)
29
+ lines = f.lines.to_a
30
+ lines.delete_if do |x|
31
+ x =~ /bundle\/#{name}/ || x =~ /#{name}\.git$/
32
+ end
33
+ f.close
34
+
35
+ File.open(config.gitmodules_file_path, "w") do |ff|
36
+ lines.each do |l|
37
+ ff.puts l
38
+ end
39
+ end
40
+ end
41
+
42
+ def remove_ref_from_git_config(name)
43
+ #TODO bundle name is different to submodule name
44
+ f = File.new(config.gitconfig_file_path)
45
+ lines = f.lines.to_a
46
+ lines.delete_if do |x|
47
+ x =~ /bundle\/#{name}/ || x =~ /#{name}\.git$/
48
+ end
49
+ f.close
50
+
51
+ File.open(config.gitconfig_file_path, "w") do |ff|
52
+ lines.each do |l|
53
+ ff.puts l
54
+ end
55
+ end
56
+ end
57
+
58
+ def config
59
+ ::Vim::Jar::Config.instance
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+
@@ -0,0 +1,7 @@
1
+ module Vim
2
+ module Jar
3
+ module Installer
4
+ autoload :Git, 'vim-jar/installer/git'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ module Vim
2
+ module Jar
3
+ class Loader
4
+
5
+ def execute
6
+ self.instance_eval read_bundle_file
7
+ end
8
+
9
+ def read_bundle_file
10
+ if File.exist? config.bundle_file_path
11
+ File.read config.bundle_file_path
12
+ else
13
+ raise Vim::Jar::InstallError.new("Can not find BundleFile in #{config.bundle_file_path}")
14
+ end
15
+ end
16
+
17
+ def plugin(repo_url, args={})
18
+ p = Plugin::Git.new(repo_url)
19
+ p.install
20
+ end
21
+
22
+ def theme(repo_url, args={})
23
+
24
+ end
25
+
26
+ def config
27
+ ::Vim::Jar::Config.instance
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,139 @@
1
+ " pathogen.vim - path option manipulation
2
+ " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
3
+ " Version: 1.2
4
+
5
+ " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
6
+ "
7
+ " API is documented below.
8
+
9
+ if exists("g:loaded_pathogen") || &cp
10
+ finish
11
+ endif
12
+ let g:loaded_pathogen = 1
13
+
14
+ " Split a path into a list.
15
+ function! pathogen#split(path) abort " {{{1
16
+ if type(a:path) == type([]) | return a:path | endif
17
+ let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
18
+ return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
19
+ endfunction " }}}1
20
+
21
+ " Convert a list to a path.
22
+ function! pathogen#join(...) abort " {{{1
23
+ if type(a:1) == type(1) && a:1
24
+ let i = 1
25
+ let space = ' '
26
+ else
27
+ let i = 0
28
+ let space = ''
29
+ endif
30
+ let path = ""
31
+ while i < a:0
32
+ if type(a:000[i]) == type([])
33
+ let list = a:000[i]
34
+ let j = 0
35
+ while j < len(list)
36
+ let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
37
+ let path .= ',' . escaped
38
+ let j += 1
39
+ endwhile
40
+ else
41
+ let path .= "," . a:000[i]
42
+ endif
43
+ let i += 1
44
+ endwhile
45
+ return substitute(path,'^,','','')
46
+ endfunction " }}}1
47
+
48
+ " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
49
+ function! pathogen#legacyjoin(...) abort " {{{1
50
+ return call('pathogen#join',[1] + a:000)
51
+ endfunction " }}}1
52
+
53
+ " Remove duplicates from a list.
54
+ function! pathogen#uniq(list) abort " {{{1
55
+ let i = 0
56
+ let seen = {}
57
+ while i < len(a:list)
58
+ if has_key(seen,a:list[i])
59
+ call remove(a:list,i)
60
+ else
61
+ let seen[a:list[i]] = 1
62
+ let i += 1
63
+ endif
64
+ endwhile
65
+ return a:list
66
+ endfunction " }}}1
67
+
68
+ " Returns a hash indicating which filetype features are enabled.
69
+ function! pathogen#filetype() abort " {{{1
70
+ redir => output
71
+ silent filetype
72
+ redir END
73
+ let result = {}
74
+ let result.detection = match(output,'detection:ON') >= 0
75
+ let result.indent = match(output,'indent:ON') >= 0
76
+ let result.plugin = match(output,'plugin:ON') >= 0
77
+ return result
78
+ endfunction " }}}1
79
+
80
+ " \ on Windows unless shellslash is set, / everywhere else.
81
+ function! pathogen#separator() abort " {{{1
82
+ return !exists("+shellslash") || &shellslash ? '/' : '\'
83
+ endfunction " }}}1
84
+
85
+ " Convenience wrapper around glob() which returns a list.
86
+ function! pathogen#glob(pattern) abort " {{{1
87
+ let files = split(glob(a:pattern),"\n")
88
+ return map(files,'substitute(v:val,"[".pathogen#separator()."/]$","","")')
89
+ endfunction "}}}1
90
+
91
+ " Like pathogen#glob(), only limit the results to directories.
92
+ function! pathogen#glob_directories(pattern) abort " {{{1
93
+ return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
94
+ endfunction "}}}1
95
+
96
+ " Prepend all subdirectories of path to the rtp, and append all after
97
+ " directories in those subdirectories.
98
+ function! pathogen#runtime_prepend_subdirectories(path) " {{{1
99
+ let sep = pathogen#separator()
100
+ let before = pathogen#glob_directories(a:path.sep."*[^~]")
101
+ let after = pathogen#glob_directories(a:path.sep."*[^~]".sep."after")
102
+ let rtp = pathogen#split(&rtp)
103
+ let path = expand(a:path)
104
+ call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
105
+ let &rtp = pathogen#join(pathogen#uniq(before + rtp + after))
106
+ return &rtp
107
+ endfunction " }}}1
108
+
109
+ " For each directory in rtp, check for a subdirectory named dir. If it
110
+ " exists, add all subdirectories of that subdirectory to the rtp, immediately
111
+ " after the original directory. If no argument is given, 'bundle' is used.
112
+ " Repeated calls with the same arguments are ignored.
113
+ function! pathogen#runtime_append_all_bundles(...) " {{{1
114
+ let sep = pathogen#separator()
115
+ let name = a:0 ? a:1 : 'bundle'
116
+ let list = []
117
+ for dir in pathogen#split(&rtp)
118
+ if dir =~# '\<after$'
119
+ let list += pathogen#glob_directories(substitute(dir,'after$',name.sep.'*[^~]'.sep.'after','')) + [dir]
120
+ else
121
+ let list += [dir] + pathogen#glob_directories(dir.sep.name.sep.'*[^~]')
122
+ endif
123
+ endfor
124
+ let &rtp = pathogen#join(pathogen#uniq(list))
125
+ return 1
126
+ endfunction
127
+
128
+ " }}}1
129
+
130
+ " Invoke :helptags on all non-$VIM doc directories in runtimepath.
131
+ function! pathogen#helptags() " {{{1
132
+ for dir in pathogen#split(&rtp)
133
+ if dir[0 : strlen($VIM)-1] !=# $VIM && isdirectory(dir.'/doc') && (!filereadable(dir.'/doc/tags') || filewritable(dir.'/doc/tags'))
134
+ helptags `=dir.'/doc'`
135
+ endif
136
+ endfor
137
+ endfunction " }}}1
138
+
139
+ " vim:set ft=vim ts=8 sw=2 sts=2:
@@ -0,0 +1,41 @@
1
+ module Vim
2
+ module Jar
3
+ module Plugin
4
+ class Git
5
+ include ::Vim::Jar::Installer::Git
6
+
7
+ attr_reader :name, :url, :target_path
8
+
9
+ def initialize(url, args={})
10
+ if url !~ /(https|git):\/\/github\.com/
11
+ raise InstallError.new("Not support this git repository #{url}.")
12
+ end
13
+ if url !~ /\.git$/
14
+ raise InstallError.new("#{url} is not a valid github repository url.")
15
+ end
16
+ if url.split("/").last =~ /(.+?)\.git$/
17
+ @name = $1
18
+ else
19
+ raise InstallError.new("#{url} is not a valid github repository url.")
20
+ end
21
+ @url = url
22
+ @target_path = config.bundle_home.join(name)
23
+ end
24
+
25
+ def install
26
+ if !File.exist?(target_path)
27
+ install_to(url, target_path)
28
+ end
29
+ end
30
+
31
+ def uninstall
32
+ uninstall_for(self.name)
33
+ end
34
+
35
+ def config
36
+ ::Vim::Jar::Config.instance
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,23 @@
1
+ module Vim
2
+ module Jar
3
+ module Plugin
4
+ autoload :Git, 'vim-jar/plugin/git.rb'
5
+
6
+ def self.update
7
+ Dir.chdir(config.vim_home) do
8
+ system("git submodule update")
9
+ end
10
+ end
11
+
12
+ def self.installed
13
+ @installed ||= Dir[config.bundle_home.join("*")].map { |bundle_path| File.basename(bundle_path) }
14
+ end
15
+
16
+ def self.config
17
+ ::Vim::Jar::Config.instance
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+
@@ -0,0 +1,5 @@
1
+ module Vim
2
+ module Jar
3
+ VERSION = "0.3.0"
4
+ end
5
+ end
data/lib/vim-jar.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require 'yaml'
4
+ require 'thor'
5
+
6
+ module Vim
7
+ module Jar
8
+ autoload :Config, 'vim-jar/config'
9
+ autoload :Plugin, 'vim-jar/plugin'
10
+ autoload :Installer, 'vim-jar/installer'
11
+ autoload :Loader, 'vim-jar/Loader'
12
+
13
+ class InitError < RuntimeError; end
14
+ class InstallError < RuntimeError; end
15
+ class ImportError < RuntimeError; end
16
+
17
+ class << self
18
+ def config
19
+ @config ||= Config.instance
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path("../lib/vim-jar.rb", File.dirname(__FILE__))
2
+ repo_urls = (101..110).map do |n|
3
+ "https://github.com/vim-scripts/repositories?page=#{n.to_s}"
4
+ end
5
+
6
+ plugin_urls = []
7
+ CONCURRENY = 20
8
+ curl_repo = Curl::Multi.new
9
+ #curl_plugin = Curl::Multi.new
10
+
11
+ on_failure_repo = lambda do |ex|
12
+ puts 'Failure.'
13
+ puts ex
14
+ end
15
+
16
+ on_success_repo = lambda do |body|
17
+ puts "finish "
18
+ config = ::Vim::Jar::Config.instance
19
+ body.scan(/<a href=\"(\/vim-scripts\/[\w-]+?)\">/).each do |path|
20
+ puts "import plugin https://github.com#{path} into #{config.yaml_path}"
21
+ url = "https://github.com#{path}"
22
+ name_home_page = ::Vim::Jar::Importer.extract_from_url(url)
23
+ if !::Vim::Jar::Plugin.exist? name_home_page["name"]
24
+ other_info = ::Vim::Jar::Importer.extract_from_page_source(url)
25
+ ::Vim::Jar::Plugin.insert name_home_page.merge!(other_info)
26
+ end
27
+ end
28
+ File.open(config.yaml_path, "w+") do |f|
29
+ f.puts ::Vim::Jar::Plugin.plugins.to_yaml
30
+ end
31
+ repo_urls.pop(CONCURRENY - curl_repo.requests.length).each do |url|
32
+ c = Curl::Easy.new(url) do|curl|
33
+ curl.on_body{|data| on_success_repo.call(data) }
34
+ curl.on_success {|easy| puts "success, add more easy handles" }
35
+ end
36
+
37
+ curl_repo.add(c)
38
+
39
+ end
40
+ end
41
+
42
+ repo_urls.pop(CONCURRENY).each do |url|
43
+ c = Curl::Easy.new(url) do|curl|
44
+ curl.on_body{|data| on_success_repo.call(data) }
45
+ curl.on_success {|easy| puts "success, add more easy handles" }
46
+ end
47
+
48
+ curl_repo.add(c)
49
+ end
50
+
51
+ curl_repo.perform
52
+
53
+ #while curl_repo.size > 0 do
54
+ #sleep 0.5
55
+ #end
56
+ #on_success_repo = lambda do |body|
57
+ #puts body
58
+ #end
59
+ #on_failure_repo = lambda do |ex|
60
+ #puts 'Failure.'
61
+ #puts ex
62
+ #end
63
+
64
+
65
+ #curl.get('http://www.example.org/', on_success, on_failure)
66
+ #curl.select([], []) while curl.size > 0
67
+
68
+ #url = URI.parse("https://github.com/vim-scripts/repositories")
69
+ #http = Net::HTTP.new(url.host, 443)
70
+ #http.use_ssl = true
71
+ #http.get(url.path) do |resp|
72
+ #resp.scan(/<a href=\"(\/vim-scripts\/[\w-]+?)\">/).each do |path|
73
+ #::Vim::Jar::Importer::import("https://github.com#{path}")
74
+ #end
75
+ #end
76
+
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'FileUtils'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'..','lib'))
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'formulars'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+
10
+ ENV['VIM_JAR_USER_HOME'] = File.expand_path("../../tmp", __FILE__)
11
+
12
+ require 'vim-jar'
13
+ #require 'fakefs/spec_helpers'
14
+
15
+ RSpec.configure do |config|
16
+ #config.include FakeFS::SpecHelpers
17
+ config.before(:each) do
18
+ FileUtils.rm_rf ENV["VIM_JAR_USER_HOME"]
19
+ FileUtils.mkdir_p ENV["VIM_JAR_USER_HOME"]
20
+ FileUtils.touch File.join(ENV["VIM_JAR_USER_HOME"], ".vimrc")
21
+ FileUtils.mkdir_p File.join(ENV["VIM_JAR_USER_HOME"], ".vim")
22
+ end
23
+ end
24
+