15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/synvert/core/utils.rb', line 15
def load_snippet(snippet_name)
if is_valid_url?(snippet_name)
uri = URI.parse(format_url(snippet_name))
return uri.open.read if remote_snippet_exists?(uri)
raise Errors::SnippetNotFound.new("#{snippet_name} not found")
elsif is_valid_file?(snippet_name)
return File.read(snippet_name, encoding: 'UTF-8')
else
snippet_path = snippet_expand_path(snippet_name)
return File.read(snippet_path, encoding: 'UTF-8') if File.exist?(snippet_path)
snippet_uri = URI.parse(format_url(remote_snippet_url(snippet_name)))
return snippet_uri.open.read if remote_snippet_exists?(snippet_uri)
raise Errors::SnippetNotFound.new("#{snippet_name} not found")
end
end
|