/
vim_dot_org.rb
45 lines (28 loc) · 967 Bytes
/
vim_dot_org.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'json'
module Vimmer
module Installers
VIM_DOT_ORG_URL_PATTERN = %r{https?://(?:www\.)?vim\.org/scripts/script.php\?script_id=(\d{1,5})}
class VimDotOrg
attr_reader :path, :plugin_name, :script_id
def self.match?(url)
!(url =~ VIM_DOT_ORG_URL_PATTERN).nil?
end
def self.for_url(path)
m = VIM_DOT_ORG_URL_PATTERN.match(path)
script_id = m[1]
raise Vimmer::PluginNotFoundError unless repository.key?(script_id)
script_name = repository[script_id]
github_path_template = "https://github.com/vim-scripts/%s.git"
github_path = github_path_template % [script_name]
Github.new(:path => github_path)
end
private
def self.repository
@repository ||= JSON.parse(Net::HTTP.get(repository_uri))
end
def self.repository_uri
URI.parse("http://www.vim-scripts.org/api/script_ids.json")
end
end
end
end