Module: Vim::Jar::Importer

Defined in:
lib/vim-jar/importer.rb,
lib/vim-jar/importer/github.rb

Defined Under Namespace

Classes: Github

Class Method Summary collapse

Class Method Details

.configObject



41
42
43
# File 'lib/vim-jar/importer.rb', line 41

def self.config 
  ::Vim::Jar::Config.instance
end

.extract_from_page_source(url) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/vim-jar/importer.rb', line 22

def self.extract_from_page_source(url)
  page_source = get_page_source(url)
  if is_github?(url)
    return Github.extract(page_source)
  else 
    raise ::Vim::Jar::ImportError.new("Do not support import from #{url}")
  end
end

.extract_from_url(url) ⇒ Object



18
19
20
# File 'lib/vim-jar/importer.rb', line 18

def self.extract_from_url(url) 
  {"homepage" => url, "name" => url.split("/").last}
end

.get_page_source(url) ⇒ Object



35
36
37
38
39
# File 'lib/vim-jar/importer.rb', line 35

def self.get_page_source(url) 
  c = ::Curl::Easy.perform(url)
  return c.body_str
  
end

.import(url) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/vim-jar/importer.rb', line 5

def self.import(url)  
  name_home_page = self.extract_from_url(url)
  if !::Vim::Jar::Plugin.exist? name_home_page["name"]
    other_info = self.extract_from_page_source(url)
    ::Vim::Jar::Plugin.insert name_home_page.merge!(other_info)
    File.open(config.yaml_path, "w+") do |f|
      f.puts ::Vim::Jar::Plugin.plugins.to_yaml
    end
  else
    raise ::Vim::Jar::ImportError.new("plugin #{name_home_page["name"]} exist")
  end
end

.is_github?(url) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.is_github?(url)
  return !!(url =~ /github\.com/ )
end