compile the template

@param string $resource_name
@param string $compile_path
@return boolean
335834
function _compile_resource($resource_name, $compile_path)
	{

		$_params = array('resource_name' => $resource_name);
		if (!$this->_fetch_resource_info($_params)) {
			return false;
		}

		$_source_content = $_params['source_content'];
		$_cache_include    = substr($compile_path, 0, -4).'.inc';

		if ($this->_compile_source($resource_name, $_source_content, $_compiled_content, $_cache_include)) {
			// if a _cache_serial was set, we also have to write an include-file:
			if ($this->_cache_include_info) {
				require_once(SMARTY_CORE_DIR . 'core.write_compiled_include.php');
				smarty_core_write_compiled_include(array_merge($this->_cache_include_info, array('compiled_content'=>$_compiled_content, 'resource_name'=>$resource_name)),  $this);
			}

			$_params = array('compile_path'=>$compile_path, 'compiled_content' => $_compiled_content);
			require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');
			smarty_core_write_compiled_resource($_params, $this);

			return true;
		} else {
			return false;
		}

	}
760998
def build_template(template_path)
      # FIXME: this is called every time build_template is called.
      # although this is idepodent, it's got room for optimization
      self.build_components!

      ERB.new( File.open( template_path ).read, nil, '<>' ).result(self.binding)
    end
512304
public function saveTemplate($template_name, array $template_fields = [ ]) {
        $data = $template_fields;
        $data['template'] = $template_name;
        return $this->apiPost('template', $data);
    }
531085
public function compile(): bool
    {
        // Delete old twig cache files
        if (file_exists($this->cachePath)) {
            $this->removeDirectory($this->cachePath);
        }

        if (!file_exists($this->cachePath)) {
            mkdir($this->cachePath);
        }

        // Iterate over all your templates and force compilation
        $this->twig->disableDebug();
        $this->twig->enableAutoReload();

        if (!$this->twig->getCache()) {
            throw new RuntimeException('The Twig cache must be enabled!');
        }

        $loader = $this->twig->getLoader();

        if ($loader instanceof FilesystemLoader) {
            $paths = $loader->getPaths();

            foreach ($paths as $path) {
                $this->compileFiles($path);
            }
        }

        return true;
    }
1125693
protected function convertTwigToPhp($path, $name)
    {
        $results = array();

        $dir = dirname($path);

        if (!file_exists($dir)) {
            mkdir($dir, 0755, true);
        }

        $templates = array();
        if ( $name === 'app' ) {
            $templates = $this->findFilesInFolder($dir . '/../../', 'twig');
        } else {
            $templates = $this->findFilesInFolder($dir . '/../views', 'twig');
        }

        $php  = "<?php\n";
        $twig = $this->getContainer()->get('twig');
        $twig->setLoader(new \Twig_Loader_String());
        foreach ($templates as $templateFileName) {
            $stream = $twig->tokenize(file_get_contents($templateFileName));
            $nodes = $twig->parse($stream);
            $template = $twig->compile($nodes);
            // remove first line
            $template = substr($template, strpos($template, "\n")+strlen("\n"));
            $php .= "/*\n * Resource: $name\n * File: $templateFileName\n */\n";
            $php .= $template;
            $results[$templateFileName]='Scanned';
        }

        if (!file_put_contents($path, $php)) {
            throw new \Exception('Cannot write intermediate PHP code for twig templates to twig.cache.php in: '.$path);
        }

        return $results;
    }
122882
public function compile(): void
	{
		// Get teplate contents

		$contents = $this->fileSystem->get($this->template);

		// Compile template

		foreach($this->compileOrder as $method)
		{
			$contents = $this->$method($contents);
		}

		// Store compiled template

		$this->fileSystem->put($this->cachePath . '/' . md5($this->template) . '.php', trim($contents));
	}
99121
public static function compileChildBlock($compiler, $_name = null)
    {
        $_output = '';
        // if called by {$smarty.block.child} we must search the name of enclosing {block}
        if ($_name == null) {
            $stack_count = count($compiler->_tag_stack);
            while (--$stack_count >= 0) {
                if ($compiler->_tag_stack[$stack_count][0] == 'block') {
                    $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'] ,"'\"");
                    break;
                }
            }
            // flag that child is already compile by {$smarty.block.child} inclusion
            $compiler->template->block_data[$_name]['compiled'] = true;
        }
        if ($_name == null) {
            $compiler->trigger_template_error('{$smarty.block.child} used out of context', $compiler->lex->taglineno);
        }
        // undefined child?
        if (!isset($compiler->template->block_data[$_name]['source'])) {
            return '';
        }
        $_tpl = new Smarty_Internal_template ('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
        $compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime);
        $_tpl->variable_filters = $compiler->template->variable_filters;
        $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
        $_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
        $_tpl->allow_relative_path = true;
        if ($compiler->nocache) {
            $_tpl->compiler->forceNocache = 2;
        } else {
            $_tpl->compiler->forceNocache = 1;
        }
        $_tpl->compiler->suppressHeader = true;
        $_tpl->compiler->suppressTemplatePropertyHeader = true;
        $_tpl->compiler->suppressMergedTemplates = true;
        if (strpos($compiler->template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
            $_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->parser->current_buffer->to_smarty_php(), $_tpl->compiler->compileTemplate($_tpl));
        } elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
            $_output = $_tpl->compiler->compileTemplate($_tpl) . $compiler->parser->current_buffer->to_smarty_php();
        } elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
            $_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->compiler->compileTemplate($_tpl);
        } elseif (!empty($compiler->template->block_data[$_name])) {
            $_output = $_tpl->compiler->compileTemplate($_tpl);
        }
        $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
        $compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']);
        $compiler->merged_templates = array_merge($compiler->merged_templates, $_tpl->compiler->merged_templates);
        $compiler->template->variable_filters = $_tpl->variable_filters;
        if ($_tpl->has_nocache_code) {
            $compiler->template->has_nocache_code = true;
        }
        foreach($_tpl->required_plugins as $code => $tmp1) {
            foreach($tmp1 as $name => $tmp) {
                foreach($tmp as $type => $data) {
                    $compiler->template->required_plugins[$code][$name][$type] = $data;
                }
            }
        }
        unset($_tpl);
        return $_output;
    }
674514
public function compile($tplName, $tplFile, $outputtype, $trusted,
                             $userModifiers = array(), $userFunctions = array())
    {
        $this->_sourceFile = $tplFile;
        $this->outputType = $outputtype;
        $cachefile = $this->config->cachePath.dirname($tplName).'/'.$this->outputType.($trusted ? '_t' : '').'_'.basename($tplName);
        $this->trusted = $trusted;
        $md5 = md5($tplFile.'_'.$this->outputType.($this->trusted ? '_t' : ''));

        if (!file_exists($this->_sourceFile)) {
            $this->doError0('errors.tpl.not.found');
        }

        $this->compileString(file_get_contents($this->_sourceFile), $cachefile,
            $userModifiers, $userFunctions, $md5);

        return true;
    }
855500
public function compile($path = null)
    {
        if ($path) {
            $this->setPath($path);
        }

        if (! is_null($this->cachePath)) {
            $contents = $this->compileString(
                $this->files->get($this->getPath())
            );

            if (! empty($this->getPath())) {
                $tokens = $this->getOpenAndClosingPhpTokens($contents);

                // If the tokens we retrieved from the compiled contents have at least
                // one opening tag and if that last token isn't the closing tag, we
                // need to close the statement before adding the path at the end.
                if ($tokens->isNotEmpty() && $tokens->last() !== T_CLOSE_TAG) {
                    $contents .= ' ?>';
                }

                $contents .= "<?php /**PATH {$this->getPath()} ENDPATH**/ ?>";
            }

            $this->files->put(
                $this->getCompiledPath($this->getPath()), $contents
            );
        }
    }
379810
public function compile_file($file_name = '', $atomic = false)
    {
        if (empty ($file_name))
            return false;

        return apc_compile_file($file_name, $atomic);
    }
19448
function(name, eagerCompile, cb) {
                if (name && name.raw) {
                    // this fixes autoescape for templates referenced in symbols
                    name = name.raw;
                }

                if (lib.isFunction(eagerCompile)) {
                    cb = eagerCompile;
                    eagerCompile = false;
                }

                if (typeof name !== 'string') {
                    throw new Error('template names must be a string: ' + name);
                }

                var tmpl = this.cache[name];

                if (tmpl) {
                    if (eagerCompile) {
                        tmpl.compile();
                    }

                    if (cb) {
                        cb(null, tmpl);
                    } else {
                        return tmpl;
                    }
                } else {
                    var syncResult;

                    lib.asyncIter(this.loaders, function(loader, i, next, done) {
                        function handle(src) {
                            if (src) {
                                done(src);
                            } else {
                                next();
                            }
                        }

                        if (loader.async) {
                            loader.getSource(name, function(err, src) {
                                if (err) {
                                    throw err;
                                }
                                handle(src);
                            });
                        } else {
                            handle(loader.getSource(name));
                        }
                    }, function(info) {
                        if (!info) {
                            var err = new Error('template not found: ' + name);
                            if (cb) {
                                cb(err);
                            } else {
                                throw err;
                            }
                        } else {
                            var tmpl = new Template(info.src, this,
                                info.path, eagerCompile);

                            if (!info.noCache) {
                                this.cache[name] = tmpl;
                            }

                            if (cb) {
                                cb(null, tmpl);
                            } else {
                                syncResult = tmpl;
                            }
                        }
                    }.bind(this));

                    return syncResult;
                }
            }
894155
def compile(template)
      v8_context do |context|
        template = template.read if template.respond_to?(:read)
        compiled_handlebars = context.eval("Handlebars.precompile(#{template.to_json})")
        "Handlebars.template(#{compiled_handlebars});"
      end
    end
599784
protected function doCompile($_content, $isTemplateSource = false)
    {
        /* here is where the compiling takes place. Smarty
          tags in the templates are replaces with PHP code,
          then written to compiled files. */
        // init the lexer/parser to compile the template
        $this->parser =
            new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this),
                                    $this);
        if ($isTemplateSource && $this->template->caching) {
            $this->parser->insertPhpCode("<?php\n\$_smarty_tpl->compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n");
        }
        if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
            $mbEncoding = mb_internal_encoding();
            mb_internal_encoding('ASCII');
        } else {
            $mbEncoding = null;
        }

        if ($this->smarty->_parserdebug) {
            $this->parser->PrintTrace();
            $this->parser->lex->PrintTrace();
        }
        // get tokens from lexer and parse them
        while ($this->parser->lex->yylex()) {
            if ($this->smarty->_parserdebug) {
                echo "<pre>Line {$this->parser->lex->line} Parsing  {$this->parser->yyTokenName[$this->parser->lex->token]} Token " .
                    htmlentities($this->parser->lex->value) . "</pre>";
            }
            $this->parser->doParse($this->parser->lex->token, $this->parser->lex->value);
        }

        // finish parsing process
        $this->parser->doParse(0, 0);
        if ($mbEncoding) {
            mb_internal_encoding($mbEncoding);
        }
        // check for unclosed tags
        if (count($this->_tag_stack) > 0) {
            // get stacked info
            list($openTag, $_data) = array_pop($this->_tag_stack);
            $this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag .
                                          "{$this->smarty->right_delimiter} tag");
        }
        // call post compile callbacks
        foreach ($this->postCompileCallbacks as $cb) {
            $parameter = $cb;
            $parameter[0] = $this;
            call_user_func_array($cb[0], $parameter);
        }
        // return compiled code
        return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode;
    }
181262
public static function compile($name, $with_draft = false)
	{
		$factory = new BuildFactory(self::config($name), 'site', $with_draft);
		$buildSite = $factory->build();
		$buildSite->build();
		$site = $buildSite->getNodes();

		$parser = new Parser();
		$config = $parser->parse(file_get_contents( self::config($name) ));

		$loader = new \Twig_Loader_Filesystem( $config['dir']['layout'] );
		$twig = new \Twig_Environment($loader);

		$compiler = new CompileSite($site, $config, $twig);
		$compiler->compile();
	}
446085
public function useTemplate($template_name = false)
    {
        $templates = $this->getTemplates();

        // set the default template
        if ($template_name == false) {
            $template_name = $templates[0]->name;
        }

        // actually use the template
        if ($template_name) {
            $this->{$template_name}();
        }
    }
1007779
public function compile(LocalFile $_bap_path, array $_bap_data = []): string {
    if(!$_bap_path->exists) {
      throw new TemplateNotFoundException($_bap_path);
    }

    $_bap_level = ob_get_level();
    ob_start();

    if(extract($_bap_data, EXTR_SKIP) !== count($_bap_data)) {
      throw new ParseError('Invalid variable name used');
    }

    try {
      include $_bap_path->full_path;
    } catch(Throwable $e) {
      while(ob_get_level() > $_bap_level) {
        ob_end_clean();
      }

      throw new TemplateCompilationError($_bap_path, $e);
    }

    return ltrim(ob_get_clean());
  }
59738
function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null)
	{
		if (file_exists(SMARTY_DIR . $this->compiler_file)) {
			require_once(SMARTY_DIR . $this->compiler_file);
		} else {
			// use include_path
			require_once($this->compiler_file);
		}


		$smarty_compiler = new $this->compiler_class;

		$smarty_compiler->template_dir      = $this->template_dir;
		$smarty_compiler->compile_dir       = $this->compile_dir;
		$smarty_compiler->plugins_dir       = $this->plugins_dir;
		$smarty_compiler->config_dir        = $this->config_dir;
		$smarty_compiler->force_compile     = $this->force_compile;
		$smarty_compiler->caching           = $this->caching;
		$smarty_compiler->php_handling      = $this->php_handling;
		$smarty_compiler->left_delimiter    = $this->left_delimiter;
		$smarty_compiler->right_delimiter   = $this->right_delimiter;
		$smarty_compiler->_version          = $this->_version;
		$smarty_compiler->security          = $this->security;
		$smarty_compiler->secure_dir        = $this->secure_dir;
		$smarty_compiler->security_settings = $this->security_settings;
		$smarty_compiler->trusted_dir       = $this->trusted_dir;
		$smarty_compiler->use_sub_dirs      = $this->use_sub_dirs;
		$smarty_compiler->_reg_objects      = &$this->_reg_objects;
		$smarty_compiler->_plugins          = &$this->_plugins;
		$smarty_compiler->_tpl_vars         = &$this->_tpl_vars;
		$smarty_compiler->default_modifiers = $this->default_modifiers;
		$smarty_compiler->compile_id        = $this->_compile_id;
		$smarty_compiler->_config            = $this->_config;
		$smarty_compiler->request_use_auto_globals  = $this->request_use_auto_globals;

		if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) {
			$smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path];
		}
		$smarty_compiler->_cache_include = $cache_include_path;


		$_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);

		if ($smarty_compiler->_cache_serial) {
			$this->_cache_include_info = array(
                'cache_serial'=>$smarty_compiler->_cache_serial
			,'plugins_code'=>$smarty_compiler->_plugins_code
			,'include_file_path' => $cache_include_path);

		} else {
			$this->_cache_include_info = null;

		}

		return $_results;
	}