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
46
47
48
49
50
|
# File 'lib/theme/file.rb', line 10
def load path, c = {}, instance = self
cache = Theme.cache.file.fetch(path) {
template = false
ext = path[/\.[^.]*$/][1..-1]
if ext && ::File.file?(path)
if STATIC_TYPES.include? ext
template = Tilt::PlainTemplate.new nil, 1, outvar: '@_output', default_encoding: 'UTF-8' do |t|
::File.read(path)
end
elsif FONT_TYPES.include?(ext) || IMAGE_TYPES.include?(ext)
template = ::File.read path
else
template = Tilt.new path, 1, outvar: '@_output'
end
else
VIEW_TYPES.each do |type|
f = "#{path}.#{type}"
if ::File.file? f
template = Tilt.new f, 1, outvar: '@_output'
break
end
end
end
unless template
raise Theme::No::FileFound,
"Could't find file: #{path} with any of these extensions: #{VIEW_TYPES.join(', ')}."
end
template
}
if defined? cache.render
cache.render instance, c.to_h
else
cache.to_s
end
end
|