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
|
# File 'lib/skeletor/includes.rb', line 13
def self.copy_include(include,target,path)
matches = PROTOCOL_PATTERN.match(include).to_a
if !matches.empty?
protocol = matches[1].to_s.downcase
if !SUPPORTED_PROTOCOLS.find_index(protocol).nil?
case protocol
when 'http'
content = HTTP.get URI.parse(include)
when 'https'
uri = URI.parse(include)
http = HTTPS.new uri.host,443
http.use_ssl = true
req = HTTPS::Get.new uri.path
request = http.request(req)
content = request.body
else
raise TypeError, 'Unsupported protocol ' + protocol + ' for remote file. Only the following are supported: ' + SUPPORTED_PROTOCOLS.join(', ')
end
puts 'Copying remote file ' + include + ' to ' + target
else
raise TypeError, 'Unsupported protocol for remote file. Only the following are supported: ' + SUPPORTED_PROTOCOLS.join(', ')
end
else
puts 'Copying ' + include + ' from template directory to ' + target
file = File.open(File.join(path,include))
content = file.gets
end
File.open(target,'w'){|f| f.write(content)}
end
|