vpm 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +1 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile.lock +13 -5
  4. data/README.md +13 -11
  5. data/Rakefile +26 -6
  6. data/bin/vpm +1 -1
  7. data/lib/transaction.rb +27 -0
  8. data/lib/vpm.rb +52 -16
  9. data/lib/vpm/command_options.rb +15 -0
  10. data/lib/vpm/command_options/abstract_command_options.rb +25 -0
  11. data/lib/vpm/command_options/install.rb +18 -0
  12. data/lib/vpm/command_options/list.rb +9 -0
  13. data/lib/vpm/commands.rb +18 -0
  14. data/lib/vpm/commands/install.rb +37 -0
  15. data/lib/vpm/commands/install_all_plugins.rb +8 -0
  16. data/lib/vpm/commands/invalid_command.rb +10 -0
  17. data/lib/vpm/commands/list.rb +8 -0
  18. data/lib/vpm/commands/setup.rb +63 -0
  19. data/lib/vpm/git.rb +17 -0
  20. data/lib/vpm/manifest_parser.rb +19 -1
  21. data/lib/vpm/plugin.rb +29 -5
  22. data/lib/vpm/plugins.rb +55 -0
  23. data/lib/vpm/runner.rb +55 -0
  24. data/lib/vpm/tasks.rb +7 -0
  25. data/lib/vpm/tasks/clone_pathogen.rb +13 -0
  26. data/lib/vpm/tasks/create_autoload_dir.rb +5 -0
  27. data/lib/vpm/tasks/create_bundle_dir.rb +5 -0
  28. data/lib/vpm/tasks/create_directory.rb +16 -0
  29. data/lib/vpm/tasks/create_our_rc_file.rb +16 -0
  30. data/lib/vpm/tasks/inject_our_load_script.rb +28 -0
  31. data/lib/vpm/tasks/move_pathogen_file.rb +17 -0
  32. data/lib/vpm/version.rb +1 -1
  33. data/spec/commands/install_spec.rb +10 -0
  34. data/spec/manifest_parser_spec.rb +3 -13
  35. data/spec/plugins_spec.rb +41 -0
  36. data/spec/spec_helper.rb +2 -4
  37. data/spec/tasks/create_bundle_dir_spec.rb +26 -0
  38. data/spec/tasks/create_directory_spec.rb +33 -0
  39. data/spec/tasks/create_our_rc_file_spec.rb +31 -0
  40. data/spec/tasks/inject_our_load_script_spec.rb +39 -0
  41. data/spec/tasks/move_pathogen_file_spec.rb +42 -0
  42. data/spec/transaction_spec.rb +65 -0
  43. data/vpm.gemspec +6 -4
  44. metadata +63 -17
  45. data/lib/vpm/git_plugin.rb +0 -22
  46. data/spec/git_plugin_spec.rb +0 -12
  47. data/spec/vpm_test.rb +0 -13
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  pkg
2
+ .DS_Store
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3
data/Gemfile.lock CHANGED
@@ -1,20 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vpm (0.0.1)
4
+ vpm (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- ansi (1.4.1)
9
+ diff-lcs (1.1.3)
10
+ fakefs (0.4.0)
10
11
  rake (0.9.2.2)
11
- turn (0.8.3)
12
- ansi
12
+ rspec (2.8.0)
13
+ rspec-core (~> 2.8.0)
14
+ rspec-expectations (~> 2.8.0)
15
+ rspec-mocks (~> 2.8.0)
16
+ rspec-core (2.8.0)
17
+ rspec-expectations (2.8.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.8.0)
13
20
 
14
21
  PLATFORMS
15
22
  ruby
16
23
 
17
24
  DEPENDENCIES
25
+ fakefs
18
26
  rake
19
- turn
27
+ rspec
20
28
  vpm!
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  Vim Plugin Manager
2
2
  ==================
3
3
 
4
+ Vim Plugin Manager is an awesome utility for managing Vim plugins
5
+
4
6
  Vim Plugin
5
7
  ----------
6
8
 
7
9
  ### What?
8
10
 
9
- A Vim Plugin is a package that contains vim scripts and a vim plugin specification, a.k.a. "vbspec".
11
+ A Vim plugin is a package that contains vim scripts and a vim plugin specification, a.k.a. "vpspec".
10
12
 
11
13
 
12
14
  ### Why?
@@ -16,12 +18,12 @@ vim scripts.
16
18
 
17
19
  ### How?
18
20
 
19
- A vbspec, like a [gemspec](http://docs.rubygems.org/read/chapter/20), consists of several attributes.
21
+ A vpspec, like a [gemspec](http://docs.rubygems.org/read/chapter/20), consists of several attributes.
20
22
  For example, a description, example usage, notes, and more.
21
23
 
22
- The directory structure of a vim bundle constains a file ending with *.vbspec in the root directory:
24
+ The directory structure of a vim plugin constains a file ending with *.vpspec in the root directory:
23
25
 
24
- - command-t.vbspec
26
+ - command-t.vpspec
25
27
  - ...
26
28
 
27
29
  Vim Plugin Manager
@@ -40,26 +42,26 @@ installing or updating a version of a vim script.
40
42
 
41
43
  ### How?
42
44
 
43
- With Vim Plugin Manager, you are able to manipulate Vim Plugins like this:
45
+ With Vim Plugin Manager, you are able to manipulate Vim plugins like this:
44
46
 
45
47
  $ vpm install command-t
46
48
  $ vpm update command-t
47
49
  $ vpm list
48
50
  $ vpm search command-t
49
- $ vpm uninstall command-t
51
+ $ vpm remove command-t
50
52
 
51
53
  You are also able to install a certain version of a vim bundle:
52
54
 
53
55
  $ vpm install command-t v1.0
54
56
 
55
57
  Vim-Plugins.org
56
- --------------
58
+ ---------------
57
59
 
58
- Vim-Plugins.org is a community vim bundle host. Vim Plugin authors
59
- publish their bundled vim scripts to the host and keep track of basic statistics
60
- of their vim bundles.
60
+ [vim-plugins.org](http://vim-plugins.org) is a community vim plugin host. Vim plugin authors
61
+ publish their vim scripts to the host and keep track of basic statistics
62
+ of their vim plugins.
61
63
 
62
- To publish/yank a Vim Plugin:
64
+ To publish/yank a Vim plugin:
63
65
 
64
66
  $ vpm publish
65
67
  $ vpm yank
data/Rakefile CHANGED
@@ -1,10 +1,30 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
- task :default => :test
3
+ #############################################################################
4
+ #
5
+ # Helper functions
6
+ #
7
+ #############################################################################
4
8
 
5
- require 'rake/testtask'
6
- Rake::TestTask.new(:test) do |test|
7
- test.libs << 'lib' << 'spec'
8
- test.pattern = 'spec/**/*_spec.rb'
9
- test.verbose = true
9
+ def name
10
+ @name ||= Dir['*.gemspec'].first.split('.').first
11
+ end
12
+
13
+ #############################################################################
14
+ #
15
+ # Standard tasks
16
+ #
17
+ #############################################################################
18
+
19
+ task :default => :spec
20
+
21
+ require 'rspec/core/rake_task'
22
+ RSpec::Core::RakeTask.new(:spec) do |t|
23
+ t.rspec_opts = ["--format documentation", "--color"]
24
+ t.pattern = "./spec/**/*_spec.rb"
25
+ end
26
+
27
+ desc "Open an irb session preloaded with this library"
28
+ task :console do
29
+ sh "irb -rubygems -r ./lib/#{name}.rb -I ./lib"
10
30
  end
data/bin/vpm CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'vpm'
4
- VPM.run(ARGV)
4
+ VPM::Runner.autorun
@@ -0,0 +1,27 @@
1
+ class Transaction
2
+ def initialize
3
+ @tasks = []
4
+ end
5
+
6
+ def <<(task)
7
+ @tasks << task
8
+ end
9
+
10
+ def tasks
11
+ @tasks
12
+ end
13
+
14
+ def perform
15
+ completed_tasks = []
16
+ @tasks.each do |task|
17
+ completed_tasks.unshift task
18
+ unless task.perform
19
+ completed_tasks.each &:undo
20
+ break
21
+ end
22
+ end
23
+ rescue Exception => e
24
+ completed_tasks.each &:undo
25
+ raise
26
+ end
27
+ end
data/lib/vpm.rb CHANGED
@@ -1,29 +1,65 @@
1
1
  require 'fileutils'
2
+ require 'tmpdir'
3
+ require 'transaction'
2
4
  require 'vpm/version'
3
5
  require 'vpm/manifest_parser'
4
6
  require 'vpm/plugin'
5
- require 'vpm/git_plugin'
7
+ require 'vpm/plugins'
8
+ require 'vpm/git'
9
+ require 'vpm/runner'
10
+ require 'vpm/commands'
11
+ require 'vpm/tasks'
12
+
13
+ # options
14
+ require 'vpm/command_options'
15
+ require 'vpm/command_options/abstract_command_options'
16
+ require 'vpm/command_options/install'
17
+
18
+ # commands
19
+ require 'vpm/commands/install'
6
20
 
7
21
  module VPM
8
22
  def self.run(args)
9
- if args.empty?
10
- install_all_plugins
11
- end
23
+ command = args.shift.to_s.capitalize
24
+ VPM::Commands[command].call args
25
+ end
26
+
27
+ def self.plugins
28
+ @plugins ||= Plugins.load_from_file(plugins_file)
29
+ end
30
+
31
+ def self.vim_dir_path
32
+ @vim_dir_path ||= begin
33
+ dir_path = ENV['VPM_VIM_DIR'] ? File.expand_path(ENV['VPM_VIM_DIR']) : File.join(ENV['HOME'], '.vim')
34
+ FileUtils.mkdir_p dir_path unless Dir.exists?(dir_path)
35
+ dir_path
36
+ end
37
+ end
38
+
39
+ def self.bundle_dir_path
40
+ @bundle_dir_path ||= begin
41
+ dir_path = File.join(vim_dir_path, 'bundle')
42
+ FileUtils.mkdir_p dir_path unless Dir.exists?(dir_path)
43
+ dir_path
44
+ end
45
+ end
46
+
47
+ def self.plugins_file
48
+ @insatlled_plugins_file ||= begin
49
+ vpm_dir_path = File.join(vim_dir, 'vpm')
50
+ FileUtils.mkdir_p vpm_dir_path unless Dir.exists?(vpm_dir_path)
51
+
52
+ plugins_file_path = File.join(vpm_dir_path, 'plugins.yaml')
53
+ FileUtils.touch(plugins_file_path)
54
+ plugins_file_path
55
+ end
12
56
  end
13
57
 
14
- def self.install_all_plugins
15
- vim_plugins_file = File.join(File.expand_path('.'), 'VimPlugins')
16
- content = File.read(vim_plugins_file)
17
- parser = ManifestParser.new
18
- plugins = parser.parse(content)
19
- plugins.each(&:install)
58
+ def self.vpmrc_path
59
+ File.expand_path File.join(ENV['HOME'], '.vpmrc')
20
60
  end
21
61
 
22
- def self.plugin_dir
23
- @dir_path ||= begin
24
- dir_path = ENV['VPM_PLUGIN_DIR'] || File.join(ENV['HOME'], '.vim', 'bundle')
25
- FileUtils.mkdir_p dir_path unless Dir.exists?(dir_path)
26
- dir_path
27
- end
62
+ def self.vimrc_path
63
+ File.expand_path File.join("~", ".vimrc")
28
64
  end
29
65
  end
@@ -0,0 +1,15 @@
1
+ require 'optparse'
2
+
3
+ module VPM
4
+ module CommandOptions
5
+ def self.parser(command)
6
+ if command == "install"
7
+ Install.new
8
+ end
9
+ end
10
+
11
+ def self.parse!(command, args)
12
+ parser(command).parse!(args)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module VPM
2
+ module CommandOptions
3
+ class AbstractCommandOptions
4
+ attr_reader :opts_parser
5
+
6
+ def parse!(args)
7
+ options = {}
8
+ parser(options).parse!(args)
9
+
10
+ options
11
+ end
12
+
13
+ def parser(options)
14
+ @opts_parser ||= OptionParser.new do |parser|
15
+ define_parser(parser, options)
16
+
17
+ parser.on_tail("-h", "--help", "Show help") do |v|
18
+ puts parser
19
+ exit
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module VPM
2
+ module CommandOptions
3
+ class Install < AbstractCommandOptions
4
+ def define_parser(parser, options)
5
+ parser.banner = "Usage: vpm install <plugin> [options]"
6
+
7
+ parser.on("-g", "--git [REMOTE]", "Install from a Git repository") do |git_url|
8
+ options[:type] = :git
9
+ options[:remote] = git_url
10
+ end
11
+
12
+ parser.on("-t", "--tag [TAG]", "Specify a tag for the Git repository") do |tag|
13
+ options[:tag] = tag
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module VPM
2
+ module CommandOptions
3
+ class List < AbstractCommandOptions
4
+ def define_parser(parser, options)
5
+ parser.banner = "Usage: vpm list [plugin]"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module VPM::Commands
2
+ def self.[](command)
3
+ if command.empty?
4
+ InstallAllPlugins
5
+ elsif self.const_defined?(command)
6
+ self.const_get(command).new
7
+ else
8
+ InvalidCommand.new(command)
9
+ end
10
+ end
11
+ end
12
+
13
+ this_directory = File.expand_path File.dirname(__FILE__)
14
+ commands_directory = File.join(this_directory, "commands")
15
+
16
+ Dir.glob(File.join(commands_directory, "**", "*.rb")).each do |filename|
17
+ require filename
18
+ end
@@ -0,0 +1,37 @@
1
+ module VPM
2
+ module VPM::Commands
3
+ module Install
4
+ def self.run(plugin)
5
+ type = plugin.type
6
+ if type == :git
7
+ GitInstall.run(plugin)
8
+ end
9
+ end
10
+
11
+ module GitInstall
12
+ def self.run(plugin)
13
+ plugin_name = plugin.name
14
+ options = plugin.options
15
+
16
+ chdir(VPM.bundle_dir_path) do
17
+ result = VPM::Git.clone(options[:remote], plugin_name)
18
+
19
+ chdir(File.join(VPM.plugin_dir, plugin_name)) do
20
+ if options[:tag]
21
+ result = VPM::Git.checkout_tag(options[:tag])
22
+ end
23
+
24
+ plugin.options[:revision] = VPM::Git.current_revision
25
+ end
26
+
27
+ result
28
+ end
29
+ end
30
+
31
+ def self.chdir(dir)
32
+ Dir.chdir(dir) { yield }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ module VPM::Commands::InstallAllPlugins
2
+ def self.call(args)
3
+ vim_plugins_file = File.join(File.expand_path('.'), 'VimPlugins')
4
+ content = File.read(vim_plugins_file)
5
+ plugins = VPM::ManifestParser.parse(content)
6
+ plugins.each(&:install)
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ class VPM::Commands::InvalidCommand
2
+ def initialize(invalid_command)
3
+ @invalid_command = invalid_command
4
+ end
5
+
6
+ def call(args)
7
+ puts "'#{@invalid_command}' is not a valid command."
8
+ exit 1
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module VPM
2
+ module Commands
3
+ module List
4
+ def self.run(plugin)
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,63 @@
1
+ class VPM::Commands::Setup
2
+ attr_accessor :pathogen_cloner
3
+ attr_accessor :bundle_dir_creator
4
+ attr_accessor :autoload_dir_creator
5
+ attr_accessor :pathogen_file_mover
6
+ attr_accessor :rc_file_creator
7
+ attr_accessor :rc_file_injector
8
+
9
+ def initialize
10
+ self.pathogen_cloner = ClonePathogen
11
+ self.bundle_dir_creator = CreateBundleDir
12
+ self.autoload_dir_creator = CreateAutoloadDir
13
+ self.pathogen_file_mover = MovePathogenFile
14
+ self.rc_file_creator = CreateOurRCFile
15
+ self.rc_file_injector = InjectOurLoadScript
16
+ end
17
+
18
+ def call(args = nil)
19
+ install_pathogen unless pathogen_installed?
20
+ create_vpmrc
21
+ inject_vimrc unless vimrc_setup?
22
+ end
23
+
24
+ private
25
+
26
+ def install_pathogen
27
+ Dir.mktmpdir do |dir|
28
+ transaction = Transaction.new
29
+ transaction << pathogen_cloner.new(dir)
30
+ transaction << bundle_dir_creator.new
31
+ transaction << autoload_dir_creator.new
32
+ transaction << pathogen_file_mover.new(dir)
33
+ transaction.perform
34
+ end
35
+ end
36
+
37
+ def create_vpmrc
38
+ transaction = Transaction.new
39
+ transaction << rc_file_creator.new
40
+ transaction.perform
41
+ end
42
+
43
+ def inject_vimrc
44
+ Dir.mktmpdir do |dir|
45
+ transaction = Transaction.new
46
+ transaction << rc_file_injector.new(dir)
47
+ transaction.perform
48
+ end
49
+ end
50
+
51
+ def pathogen_installed?
52
+ plugin_directory = VPM.bundle_dir
53
+ pathogen_file = File.join(VPM.vim_dir_path, 'autoload', 'pathogen.vim')
54
+ Dir.exists?(plugin_directory) && File.exists?(pathogen_file)
55
+ end
56
+
57
+ def vimrc_setup?
58
+ FileUtils.touch VPM.vimrc_path
59
+ File.open(VPM.vimrc_path, "r") do |file|
60
+ file.lines.any? {|line| line =~ /source #{VPM.vpmrc_path}/}
61
+ end
62
+ end
63
+ end