Returns the first found template companion file
540249
def find_template_companion(template, extension='', check=True):
    

    if check and not os.path.isfile(template):
        yield ''
        return # May be '<stdin>' (click)

    template = os.path.abspath(template)
    template_dirname = os.path.dirname(template)
    template_basename = os.path.basename(template).split('.')

    current_path = template_dirname
    stop_path = os.path.commonprefix((os.getcwd(), current_path))
    stop_path = os.path.dirname(stop_path)

    token = template_basename[0] + '.'

    while True:

        for file in sorted(os.listdir(current_path)):
            if not file.startswith(token):
                continue
            if not file.endswith(extension):
                continue

            file_parts = file.split('.')
            for i in range(1, len(template_basename)):
                if template_basename[:-i] != file_parts[:-1]:
                    continue
                if current_path == template_dirname:
                    if file_parts == template_basename:
                        continue # Do not accept template itself

                yield os.path.join(current_path, file)

        if current_path == stop_path:
            break

        # cd ..
        current_path = os.path.split(current_path)[0]
139724
def default_template_path():
    
    fdir = os.path.dirname(__file__)
    return os.path.abspath(os.path.join(fdir, '../assets/'))
35216
def grok_template_file(src):
    """"""
    if not src.startswith('builtin:'):
        return abspath(src)

    builtin = src.split(':')[1]
    builtin = "templates/%s.j2" % builtin
    return resource_filename(__name__, builtin)
225382
def _get_template_name(self):
        '''
        '''

        start_pattern = r"sys application template\s+" \
                        r"(\/[\w\.\-]+\/)?" \
                        r"(?P<name>[\w\.\-]+)\s*\{"

        template_start = re.search(start_pattern, self.template_str)
        if template_start:
            return template_start.group('name')

        raise NonextantTemplateNameException('Template name not found.')
667699
def get_template_context(src, container="div", classes="", inner_classes="", alt="", background_image=False, no_css=False, aria_hidden=False):
    """"""
    context = {
        "container": container,
        "classes": classes,
        "aspect_padding_bottom": aspect_ratio_percent(src),
        "alt": alt,
        "background_image": background_image,
        "no_css": no_css,
        "inner_classes": inner_classes,
        "aria_hidden": aria_hidden,
    }

    # We can't do any of the srcset (or JS switching fallback) if we don't
    # have a thumbnail library installed.
    if not get_thumbnail_engine():
        context["image"] = src
        return context

    sizes = get_image_sizes(src)
    context["image_sizes"] = sizes

    # Set the first image in the list as the one to be rendered initially
    # (pre-JS-fallback). `if sizes` might not be a necessary check...
    context["image"] = sizes[0]

    context["image_sizes_json"] = json.dumps(sizes)
    srcset_items = ["{} {}w".format(size["url"], size["width"]) for size in sizes]

    context["image_sizes_srcset"] = ", ".join(srcset_items)
    return context
547195
def template_path(self):
        
        return super(HideCodeHTMLExporter, self).template_path + [os.path.join(os.path.dirname(__file__), "Templates")]
626336
def get_abs_template_path(template_name, directory, extension):
    
    # Get the relative path
    relative_path = join(directory, template_name)
    file_with_ext = template_name

    if extension:
        # If there is a default extension, but no file extension, then add it
        file_name, file_ext = splitext(file_with_ext)
        if not file_ext:
            file_with_ext = extsep.join(
                (file_name, extension.replace(extsep, '')))
            # Rebuild the relative path
            relative_path = join(directory, file_with_ext)

    return abspath(relative_path)
608030
def _get_template(self, template_name, template_file):
        
        template = os.path.join(self.location, 'templates',
                                template_name, template_file)
        return jinja2.Template(open(template).read())
1127326
def get_template_dir():
    """"""
    try:
        template_dir = os.path.expanduser(os.environ["NET_TEXTFSM"])
        index = os.path.join(template_dir, "index")
        if not os.path.isfile(index):
            # Assume only base ./ntc-templates specified
            template_dir = os.path.join(template_dir, "templates")
    except KeyError:
        # Construct path ~/ntc-templates/templates
        home_dir = os.path.expanduser("~")
        template_dir = os.path.join(home_dir, "ntc-templates", "templates")

    index = os.path.join(template_dir, "index")
    if not os.path.isdir(template_dir) or not os.path.isfile(index):
        msg = """
Valid ntc-templates not found, please install https://github.com/networktocode/ntc-templates
and then set the NET_TEXTFSM environment variable to point to the ./ntc-templates/templates
directory."""
        raise ValueError(msg)
    return os.path.abspath(template_dir)
1213857
def get_template(name):
    
    path = os.path.join(base_dir, name)

    if path not in templates:
        try:
            templates[path] = Template(path)
        except IOError:
            return None

    return copy.deepcopy(templates[path])
844507
public function findTemplate($template_name)
    {
        /*
         * Find template location inside search directory path
         */
        if (!$this->app) {
            throw new Exception_InitError('You should use add() to add objects!');
        }
        $f = $this->app->locatePath(
            $this->template_type ?: $this->settings['template_type'],
            $template_name.$this->settings['extension']
        );

        return $this->origin_filename = $f;
    }
773990
def _get_template(self, template_name):
        
        if template_name not in self.chached_templates:
            self.chached_templates[template_name] = self.env.get_template(template_name)
        return self.chached_templates[template_name]
1131087
def get_template(name):
    
    path = 'templates/' + name
    b_stream = pkg_resources.resource_stream('vr.imager', path)
    return b_stream.read().decode('utf-8')
285822
def get_template_loader(app, subdir='templates'):
    '''
    
    '''
    dmp = apps.get_app_config('django_mako_plus')
    return dmp.engine.get_template_loader(app, subdir, create=True)
1069579
def find_first_available_template(self, template_name_list):
        
        if isinstance(template_name_list, six.string_types):
            return template_name_list
        else:
            # Take advantage of fluent_pages' internal implementation
            return _select_template_name(template_name_list)
940689
def get_template(file):
    ''' 
    '''

    pattern = str(file).lower()
    while len(pattern) and not Lean.is_registered(pattern):
      pattern = os.path.basename(pattern)
      pattern = re.sub(r'^[^.]*\.?','',pattern)

  	# Try to find a preferred engine.
    preferred_klass = Lean.preferred_mappings[pattern] if Lean.preferred_mappings.has_key(pattern) else None

    if preferred_klass:
  		return preferred_klass

  	# Fall back to the general list of mappings
    klasses = Lean.template_mappings[pattern]

  	# Try to find an engine which is already loaded
    template = None
    for klass in klasses:
  		if hasattr(klass,'is_engine_initialized') and callable(klass.is_engine_initialized):
  			if klass.is_engine_initialized():
  				template = klass
  				break

 		if template:
 			return template

 		# Try each of the classes until one succeeds. If all of them fails,
   	# we'll raise the error of the first class.
    first_failure = None

    for klass in klasses:
      try:
        return klass
      except Exception, e:
        if not first_failure:
          first_failure = e

   	if first_failure:
   		raise Exception(first_failure)
249553
def find_inheritable_template_folder(view_context, name, partial, formats, param = nil)  
      find_inheritable_template_folder_cached(view_context, name, partial, formats, param) do
        find_inheritable_artifact(param) do |folder|
          view_context.template_exists?(name, folder, partial)
        end
      end
    end