Esempio n. 1
0
 public static function findTemplate($name, $dirs = null)
 {
     /*
      * Calculate template_source_loaders the first time the function is executed
      * because putting this logic in the module-level namespace may cause
      * circular import errors. See Django ticket #1292.
      */
     if (DjaLoader::$template_source_loaders === null) {
         $loaders = array();
         foreach (Dja::getSetting('TEMPLATE_LOADERS') as $loader_name) {
             $loader = DjaLoader::findTemplateLoader($loader_name);
             if ($loader !== null) {
                 $loaders[] = $loader;
             }
         }
         DjaLoader::$template_source_loaders = $loaders;
     }
     /** @var $loader Closure */
     foreach (DjaLoader::$template_source_loaders as $loader) {
         try {
             list($source, $display_name) = $loader($name, $dirs);
             return array($source, self::makeOrigin($display_name, $loader, $name, $dirs));
         } catch (TemplateDoesNotExist $e) {
             continue;
         }
     }
     throw new TemplateDoesNotExist($name);
 }
Esempio n. 2
0
/**
 * Restores the original template loaders after
 * :meth:`setup_test_template_loader` has been run.
 */
function restore_template_loaders()
{
    DjaLoader::$template_source_loaders = $GLOBALS['RESTORE_LOADERS_ATTR'];
    unset($GLOBALS['RESTORE_LOADERS_ATTR']);
}
Esempio n. 3
0
 /**
  * Same as test_extends_include_missing_baseloader, only tests
  * behavior of the cached loader instead of BaseLoader.
  */
 public function testExtendsIncludeMissingCachedloader()
 {
     $old_td = Dja::getSetting('TEMPLATE_DEBUG');
     Dja::setSetting('TEMPLATE_DEBUG', True);
     $old_loaders = DjaLoader::$template_source_loaders;
     $cache_loader = new CachedLoader(array(''));
     $cache_loader->_cached_loaders = array(new AppDirectoriesLoader());
     DjaLoader::$template_source_loaders = array($cache_loader);
     $load_name = 'test_extends_error.html';
     $tmpl = DjaLoader::getTemplate($load_name);
     $r = null;
     try {
         $r = $tmpl->render(new Context(array()));
     } catch (TemplateDoesNotExist $e) {
         $this->assertEquals('missing.html', $e->getMessage());
     }
     $this->assertEquals(null, $r, 'Template rendering unexpectedly succeeded, produced: ->' . $r . '<-');
     /*
      * For the cached loader, repeat the test, to ensure the first attempt did not cache a
      * result that behaves incorrectly on subsequent attempts.
      */
     $tmpl = DjaLoader::getTemplate($load_name);
     try {
         $tmpl->render(new Context(array()));
     } catch (TemplateDoesNotExist $e) {
         $this->assertEquals('missing.html', $e->getMessage());
     }
     $this->assertEquals(null, $r, 'Template rendering unexpectedly succeeded, produced: ->' . $r . '<-');
     DjaLoader::$template_source_loaders = $old_loaders;
     Dja::setSetting('TEMPLATE_DEBUG', $old_td);
 }