Class: Twig::Loader::Filesystem

Inherits:
Base
  • Object
show all
Defined in:
lib/twig/loader/filesystem.rb

Instance Method Summary collapse

Methods inherited from Base

#exists?

Constructor Details

#initialize(root_path, paths = []) ⇒ Filesystem

Returns a new instance of Filesystem.



6
7
8
9
10
11
# File 'lib/twig/loader/filesystem.rb', line 6

def initialize(root_path, paths = [])
  super()

  @root_path = root_path.to_s
  @paths = paths.map(&:to_s)
end

Instance Method Details

#fresh?(name, time) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# File 'lib/twig/loader/filesystem.rb', line 27

def fresh?(name, time)
  if (file = find_template(name))
    return File.mtime(file).to_i < time
  end

  false
end

#get_cache_key(name) ⇒ Object



21
22
23
24
25
# File 'lib/twig/loader/filesystem.rb', line 21

def get_cache_key(name)
  return unless (path = find_template(name))

  path.delete_prefix(@root_path)
end

#get_source_context(name) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/twig/loader/filesystem.rb', line 13

def get_source_context(name)
  if (file = find_template(name))
    return Source.new(File.read(file), name)
  end

  raise "Unable to find '#{name}'"
end