module Docker::Template

Constants

VERSION

Public Instance Methods

_require(what) { |true| ... } click to toggle source

# File lib/docker/template.rb, line 78
def _require(what)
  require what
  if block_given?
    yield true
  end
rescue LoadError
  if block_given?
    yield false
  end
end
gem_root() click to toggle source

# File lib/docker/template.rb, line 44
def gem_root
  @gem_root ||= begin
    Pathutil.new("../../").expand_path(
      __dir__
    )
  end
end
get(name, data = {}) click to toggle source

– Pull a `template` from the `template_root` to parse it's data. TODO: Rename this to get_template! –

# File lib/docker/template.rb, line 65
def get(name, data = {})
  data = ERB::Context.new(data)
  template = template_root.join("#{name}.erb").read unless name.is_a?(Pathutil)
  template = name.read if name.is_a?(Pathutil)
  template = ERB.new(template)

  return template.result(
    data._binding
  )
end
project?() click to toggle source

# File lib/docker/template.rb, line 26
def project?
  dir = root.join("docker")
  any = Builder.all.dup.keep_if(&:projects_allowed?)
  any = any.map(&:files).reduce(&:|).any? { |file| root.join(file).file? }
  return true if any && root.join(Meta.opts_file(:force => \
    :project)).file?
end
root() click to toggle source

# File lib/docker/template.rb, line 36
def root
  @root ||= begin
    Pathutil.new(Dir.pwd).realpath
  end
end
template_root() click to toggle source

# File lib/docker/template.rb, line 54
def template_root
  @template_root ||= begin
    gem_root.join("templates")
  end
end
tmpdir() click to toggle source

# File lib/docker/template.rb, line 91
def tmpdir
  if ENV["DOCKER_TEMPLATE_TMPDIR"]
    dir = Pathutil.new(ENV["DOCKER_TEMPLATE_TMPDIR"])
      .tap(&:mkdir_p)
  else
    dir = root.join("tmp")
    if !dir.exist?
      # Make the directory and then throw it out at exit.
      dir.mkdir_p; ObjectSpace.define_finalizer(dir, proc do
        dir.rm_rf
      end)
    end

    dir
  end

  dir.realpath
end