vimius 0.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ script: "rake spec"
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ notifications:
7
+ recipients:
8
+ - wael.nasreddine@gmail.com
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ # Sources
2
+ source "http://rubygems.org"
3
+
4
+ # Parse vimius.gemspec
5
+ gemspec
6
+
7
+ ####
8
+ # For development or testing
9
+ ###
10
+
11
+ # Require rbconfig to figure out the target OS
12
+ require 'rbconfig'
13
+
14
+ platforms :ruby do
15
+ unless ENV['TRAVIS']
16
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
17
+ gem 'rb-fsevent', :require => false
18
+ gem 'ruby-growl', :require => false
19
+ gem 'growl', :require => false
20
+ end
21
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
22
+ gem 'rb-inotify', :require => false
23
+ gem 'libnotify', :require => false
24
+ end
25
+ end
26
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard 'rspec', :version => 2 do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Vimius [![Build Status](http://travis-ci.org/TechnoGate/vimius-ruby.png)](http://travis-ci.org/TechnoGate/vimius-ruby) [![Still Maintained](http://stillmaintained.com/TechnoGate/vimius-ruby.png)](http://stillmaintained.com/TechnoGate/vimius-ruby)
2
+
3
+ [![Click here to lend your support to: Open Source Projects and make a donation at www.pledgie.com!](http://pledgie.com/campaigns/16123.png?skin_name=chrome)](http://www.pledgie.com/campaigns/16123)
4
+
5
+ # License
6
+
7
+ ## This code is free to use under the terms of the MIT license.
8
+
9
+ Copyright (c) 2011 TechnoGate <support@technogate.fr>
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining
12
+ a copy of this software and associated documentation files (the
13
+ "Software"), to deal in the Software without restriction, including
14
+ without limitation the rights to use, copy, modify, merge, publish,
15
+ distribute, sublicense, and/or sell copies of the Software, and to
16
+ permit persons to whom the Software is furnished to do so, subject to
17
+ the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included
20
+ in all copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/vimius ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ # Add the lib folder to the load path
5
+ $:.push File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ # Load vimius
7
+ require 'vimius'
8
+ # Start the CLI
9
+ TechnoGate::Vimius::CLI::Runner.start
data/lib/vimius.rb ADDED
@@ -0,0 +1,79 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ require "active_support/core_ext"
5
+ require "tg_config"
6
+
7
+ # Setup paths
8
+ USER_VIM_PATH = File.expand_path(File.join ENV['HOME'], '.vim')
9
+ USER_VIMRC_PATH = File.expand_path(File.join ENV['HOME'], '.vimrc')
10
+ USER_GVIMRC_PATH = File.expand_path(File.join ENV['HOME'], '.gvimrc')
11
+ USER_VIMIUS_PATH = File.join USER_VIM_PATH, 'vimius'
12
+ VIMIUS_PATH = File.expand_path(File.join File.dirname(__FILE__), '..')
13
+ VIMIUS_LIB_PATH = File.join VIMIUS_PATH, 'lib'
14
+ VIMIUS_SPEC_PATH = File.join VIMIUS_PATH, 'spec'
15
+ CONFIG_FILE = File.expand_path(File.join ENV['HOME'], '.vimius.yaml')
16
+ MODULES_FILE = File.join(USER_VIMIUS_PATH, 'submodules.yaml')
17
+
18
+ module TechnoGate
19
+ module Vimius
20
+ extend self
21
+
22
+ def config
23
+ @config ||= TgConfig.new(CONFIG_FILE)
24
+ end
25
+
26
+ # Return Vimius path
27
+ #
28
+ # @return [String] The absolute path to Vimius distribution
29
+ def vimius_path
30
+ VIMIUS_PATH
31
+ end
32
+
33
+ # Return the vim's path
34
+ #
35
+ # @return [String] The absolute path to ViM files
36
+ def vim_path
37
+ VIMIUS_VIM_PATH
38
+ end
39
+
40
+ # Return the ruby's path
41
+ #
42
+ # @return [String] The absolute path to Ruby files
43
+ def ruby_path
44
+ VIMIUS_RUBY_PATH
45
+ end
46
+
47
+ # Expand the path of a given file
48
+ #
49
+ # @param [Array] args
50
+ # @return [String] The expanded path to the given file.
51
+ def expand(*args)
52
+ File.expand_path(*args)
53
+ end
54
+
55
+ # Execute a command under root
56
+ #
57
+ # @param [String]* commands to run
58
+ def sudo(*args)
59
+ if ENV["USER"] != "root"
60
+ command = "sudo #{args.join(" ")}"
61
+ puts "Please enter your password (if requested) for executing the command '#{command}'"
62
+ else
63
+ command = args.join(" ")
64
+ end
65
+
66
+ exec command
67
+ end
68
+ end
69
+ end
70
+
71
+ require 'vimius/errors'
72
+ require 'vimius/shell'
73
+ require 'vimius/git'
74
+ require 'vimius/vim'
75
+ require 'vimius/gems'
76
+ require 'vimius/github'
77
+ require 'vimius/plugins'
78
+ require 'vimius/submodules'
79
+ require 'vimius/cli'
data/lib/vimius/cli.rb ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'thor'
4
+
5
+ # Load all modules
6
+ Dir["#{VIMIUS_LIB_PATH}/vimius/cli/**/*.rb"].each { |f| require f }
7
+
8
+ module TechnoGate
9
+ module Vimius
10
+ module CLI
11
+
12
+ ASCII_ART = File.read(File.join(File.dirname(__FILE__), 'vimius_ascii.txt'))
13
+
14
+ class Runner < ::Thor
15
+ # Include cli modules
16
+ include CLI::Version
17
+ include CLI::Install
18
+ include CLI::Submodules
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module TechnoGate
4
+ module Vimius
5
+ module CLI
6
+ module Install
7
+
8
+ def self.included(base)
9
+ base.send :require, 'open-uri'
10
+
11
+ base.class_eval <<-END, __FILE__, __LINE__ + 1
12
+ desc "install", "Install vimius"
13
+ def install
14
+ # Sanity check
15
+ sanity_check
16
+
17
+ # Download the bootstrap file
18
+ File.open('/tmp/vimius_bootstrap.sh', 'w') do |f|
19
+ f.write(open('https://raw.github.com/TechnoGate/vimius/master/bootstrap.sh').read)
20
+ end
21
+
22
+ # Run the bootstrap file
23
+ Shell.exec("cat /tmp/vimius_bootstrap.sh | sh", true)
24
+ end
25
+
26
+ protected
27
+ def sanity_check
28
+ if File.exists?(USER_VIM_PATH)
29
+ abort "\#{USER_VIM_PATH} exists, cannot continue."
30
+ end
31
+
32
+ if File.exists?(USER_VIMRC_PATH)
33
+ abort "\#{USER_VIMRC_PATH} exists, cannot continue."
34
+ end
35
+
36
+ if File.exists?(USER_GVIMRC_PATH)
37
+ abort "\#{USER_GVIMRC_PATH} exists, cannot continue."
38
+ end
39
+ end
40
+ END
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module TechnoGate
4
+ module Vimius
5
+ module CLI
6
+ module Submodules
7
+
8
+ def self.included(base)
9
+ base.send :include, InstanceMethods
10
+ end
11
+
12
+ module InstanceMethods
13
+ def self.included(base)
14
+ base.class_eval <<-END, __FILE__, __LINE__ + 1
15
+ END
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module TechnoGate
4
+ module Vimius
5
+ module CLI
6
+ module Version
7
+
8
+ def self.included(base)
9
+ base.class_eval <<-END, __FILE__, __LINE__ + 1
10
+ desc "version", "Print Vimius version and exit."
11
+ def version
12
+ puts "Vimius version \#{Vimius.version}"
13
+ end
14
+ END
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,12 @@
1
+ module TechnoGate
2
+ module Vimius
3
+ # Errors
4
+ VimiusError = Class.new Exception
5
+ BlockNotGivenError = Class.new VimiusError
6
+ RubyGemsNotFoundError = Class.new VimiusError
7
+
8
+ SubmoduleError = Class.new VimiusError
9
+ SubmodulesNotValidError = Class.new SubmoduleError
10
+ SubmoduleNotFoundError = Class.new SubmoduleError
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ module TechnoGate
2
+ module Vimius
3
+ # Find an installed gem
4
+ #
5
+ # @param [String] The gem name to search for
6
+ # @param [Mixed] The gem requirements
7
+ # @return [Array] The found gems
8
+ def find_gem(gem_name, *requirements)
9
+ begin
10
+ require 'rubygems'
11
+ if Gem.const_defined?(:Specification)
12
+ Gem::Specification.find_all_by_name(gem_name, *requirements)
13
+ elsif Gem.respond_to?(:source_index)
14
+ Gem.source_index.find_name(gem_name, *requirements)
15
+ else
16
+ Gem.cache.find_name(gem_name, *requirements)
17
+ end
18
+ rescue LoadError
19
+ raise RubyGemsNotFoundError
20
+ end
21
+ end
22
+
23
+ # Install a gem
24
+ #
25
+ # @param [String] The gem name
26
+ def install_gem(gem_name)
27
+ require 'rubygems'
28
+
29
+ # Install the gem only if it can't be found
30
+ if find_gem(gem_name).length == 0
31
+ sudo "gem install #{gem_name}"
32
+ end
33
+ rescue RubyGemsNotFoundError
34
+ puts "Could not install the gem #{gem_name}, please do so manually."
35
+ puts "sudo gem install #{gem_name}"
36
+ end
37
+ end
38
+ end
data/lib/vimius/git.rb ADDED
@@ -0,0 +1,26 @@
1
+ module TechnoGate
2
+ module Vimius
3
+ # Get a list of submodules
4
+ #
5
+ # @return [Array] of submodules
6
+ def submodules
7
+ @submodules ||= `git submodule`.split("\n").collect { |s| s.split(" ")[1] }
8
+ end
9
+
10
+ # Update a submodule
11
+ #
12
+ # @param [String] The submodule to update (relative path)
13
+ # @param [String] The branch we're tracking
14
+ def update_submodule(submodule, branch = "master")
15
+ Dir.chdir submodule do
16
+ puts
17
+ puts "*" * 40
18
+ puts "*#{"Updating #{submodule}".center(38)}*"
19
+ puts "*" * 40
20
+ puts
21
+ sh "git checkout #{branch}"
22
+ sh "git pull"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module TechnoGate
2
+ module Vimius
3
+
4
+ # Return a fully-qualified url to the raw page of a file stores inside
5
+ # a repository on github
6
+ #
7
+ # @param [String] Path
8
+ # @return [String] URL
9
+ def github_raw(path)
10
+ "https://raw.github.com/#{path}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,111 @@
1
+ require 'rake'
2
+ require 'open-uri'
3
+
4
+ module TechnoGate
5
+ module Vimius
6
+ module Tasks
7
+ include Rake::DSL
8
+
9
+ def self.included(base)
10
+ # Load all plugin installation tasks
11
+ Dir["#{vim_path}/**/tasks/**.rake"].each do |f|
12
+ base.send :import, f
13
+ end
14
+ end
15
+ end
16
+
17
+ # Install a plugin
18
+ #
19
+ # @param [String] The group the plugin belongs to
20
+ # @param [String] The plugin name
21
+ # @param [&block] The installation block
22
+ def install_vim_plugin(group, name, &block)
23
+ raise Vimius::BlockNotGivenError unless block_given?
24
+
25
+ define_install_plugin_tasks(group, name, &block)
26
+ end
27
+
28
+ # Install a plugin in a submodule
29
+ #
30
+ # @param [String] The group the plugin belongs to
31
+ # @param [String] The plugin name
32
+ # @param [&block] The installation block
33
+ def install_vim_plugin_within_submodule(group, name, &block)
34
+ raise Vimius::BlockNotGivenError unless block_given?
35
+
36
+ define_verify_plugin_tasks(group, name, &block)
37
+ define_install_plugin_tasks(group, name, &block)
38
+ end
39
+
40
+ # Download and save file
41
+ #
42
+ # @param [String] url
43
+ # @param [String] path
44
+ def download_and_save_file(url, path)
45
+ open_and_save_file(path, open(url).read)
46
+ end
47
+
48
+ # Open and save file
49
+ #
50
+ # @param [String] path
51
+ # @param [Value] What to write in the file
52
+ # @param [&block]
53
+ def open_and_save_file(path, value = nil, &block)
54
+ # Make sure the directory up to the folder exists
55
+ mkdir_p File.dirname(path)
56
+ # Open the file and use either the block or the value to write the
57
+ # file
58
+ File.open path, 'w' do |f|
59
+ if block_given?
60
+ f.write(yield)
61
+ else
62
+ f.write(value)
63
+ end
64
+ end
65
+ end
66
+
67
+ protected
68
+
69
+ # Define tasks for verifying plugin rediness
70
+ #
71
+ # @param [String] The group the plugin belongs to
72
+ # @param [String] The plugin name
73
+ # @param [&block] The installation block
74
+ def define_verify_plugin_tasks(group, name, &block)
75
+ # Create a namespace for the plugin
76
+ namespace(name) do
77
+ task :verify_plugin do
78
+ unless Dir["#{vim_path}/#{group}/#{name}/**"].any?
79
+ abort "The submodule #{group}/#{name} is not ready, please run 'git submodule update --init'"
80
+ end
81
+ end
82
+
83
+ task :install => :verify_plugin
84
+ end
85
+ end
86
+
87
+ # Define tasks for installing a plugin
88
+ #
89
+ # @param [String] The group the plugin belongs to
90
+ # @param [String] The plugin name
91
+ # @param [&block] The installation block
92
+ def define_install_plugin_tasks(group, name, &block)
93
+ # Create a namespace for the plugin
94
+ namespace(name) do
95
+ # Define the plugin installation task
96
+ desc "Install #{name} plugin."
97
+ task :install do
98
+ puts
99
+ puts "*" * 40
100
+ puts "*#{"Installing #{name}".center(38)}*"
101
+ puts "*" * 40
102
+ puts
103
+ yield
104
+ end
105
+ end
106
+
107
+ # Hook the plugin's install task to the global install task
108
+ task :install => "#{name}:install"
109
+ end
110
+ end
111
+ end