class Roda::RodaPlugins::Render::TemplateMtimeWrapper

the API is subject to change at any time.
template file has been modified. This is an internal class and
time of the template file, and rebuilds the template if the
Wrapper object for the Tilt template, that checks the modified

def compiled_method(locals_keys=EMPTY_ARRAY, roda_class=nil)

Return the compiled method for the current template object.
def compiled_method(locals_keys=EMPTY_ARRAY, roda_class=nil)
  Render.tilt_template_compiled_method(@template, locals_keys, roda_class)
end

def compiled_method_lambda(roda_class, method_name, locals_keys=EMPTY_ARRAY)

unnecessary local variables
is separated into its own method so the lambda does not capture any
Return the lambda used to define the compiled template method. This
def compiled_method_lambda(roda_class, method_name, locals_keys=EMPTY_ARRAY)
  mod = roda_class::RodaCompiledTemplates
  template = self
  lambda do |locals, &block|
    template.if_modified do
      mod.send(:define_method, method_name, Render.tilt_template_compiled_method(template, locals_keys, roda_class))
      mod.send(:private, method_name)
    end
    send(method_name, locals, &block)
  end
end

def define_compiled_method(roda_class, method_name, locals_keys=EMPTY_ARRAY)

call the compiled template method, updating the compiled template method
Compile a method in the given module with the given name that will
def define_compiled_method(roda_class, method_name, locals_keys=EMPTY_ARRAY)
  mod = roda_class::RodaCompiledTemplates
  internal_method_name = :"_#{method_name}"
  begin
    mod.send(:define_method, internal_method_name, compiled_method(locals_keys, roda_class))
  rescue ::NotImplementedError
    return false
  end
  mod.send(:private, internal_method_name)
  mod.send(:define_method, method_name, &compiled_method_lambda(roda_class, internal_method_name, locals_keys))
  mod.send(:private, method_name)
  method_name
end

def if_modified

the template object and the modification time. Other return false.
If the template file has been updated, return true and update
def if_modified
  begin
    mtime = template_last_modified
  rescue
    # ignore errors
  else
    if mtime != @mtime
      reset_template
      yield
      @mtime = mtime
    end
  end
end

def initialize(roda_class, opts, template_opts)

def initialize(roda_class, opts, template_opts)
  @roda_class = roda_class
  @opts = opts
  @template_opts = template_opts
  reset_template
  @path = opts[:path]
  deps = opts[:dependencies]
  @dependencies = ([@path] + Array(deps)) if deps
  @mtime = template_last_modified
end

def render(*args, &block)

changed, rebuild the template file, then call render on it.
If the template file exists and the modification time has
def render(*args, &block)
  res = nil
  modified = false
  if_modified do
    res = @template.render(*args, &block)
    modified = true
  end
  modified ? res : @template.render(*args, &block)
end

def reset_template

dependencies is modified.
Reset the template, done every time the template or one of its
def reset_template
  @template = @roda_class.create_template(@opts, @template_opts)
end

def template_last_modified

return the maximum.
other files, check the modification times of all dependencies and
Return when the template was last modified. If the template depends on any
def template_last_modified
  if deps = @dependencies
    deps.map{|f| File.mtime(f)}.max
  else
    File.mtime(@path)
  end
end