Compose LightnCandy render codes for include()

@param array<string,array|string|integer> $context Current context
@param string $code generated PHP code

@return string Composed PHP code
434884
public static function composePHPRender($context, $code) {
        $flagJStrue = Expression::boolString($context['flags']['jstrue']);
        $flagJSObj = Expression::boolString($context['flags']['jsobj']);
        $flagJSLen = Expression::boolString($context['flags']['jslen']);
        $flagSPVar = Expression::boolString($context['flags']['spvar']);
        $flagProp = Expression::boolString($context['flags']['prop']);
        $flagMethod = Expression::boolString($context['flags']['method']);
        $flagLambda = Expression::boolString($context['flags']['lambda']);
        $flagMustlok = Expression::boolString($context['flags']['mustlok']);
        $flagMustlam = Expression::boolString($context['flags']['mustlam']);
        $flagMustsec = Expression::boolString($context['flags']['mustsec']);
        $flagEcho = Expression::boolString($context['flags']['echo']);
        $flagPartNC = Expression::boolString($context['flags']['partnc']);
        $flagKnownHlp = Expression::boolString($context['flags']['knohlp']);

        $constants = Exporter::constants($context);
        $helpers = Exporter::helpers($context);
        $partials = implode(",\n", $context['partialCode']);
        $debug = Runtime::DEBUG_ERROR_LOG;
        $use = $context['flags']['standalone'] ? Exporter::runtime($context) : "use {$context['runtime']} as {$context['runtimealias']};";
        $stringObject = $context['flags']['method'] || $context['flags']['prop'] ? Exporter::stringobject($context) : '';
        $safeString = (($context['usedFeature']['enc'] > 0) && ($context['flags']['standalone'] === 0)) ? "use {$context['safestring']} as SafeString;" : '';
        $exportSafeString = (($context['usedFeature']['enc'] > 0) && ($context['flags']['standalone'] >0)) ? Exporter::safestring($context) : '';
        // Return generated PHP code string.
        return <<<VAREND
$stringObject{$safeString}{$use}{$exportSafeString}return function (\$in = null, \$options = null) {
    \$helpers = $helpers;
    \$partials = array($partials);
    \$cx = array(
        'flags' => array(
            'jstrue' => $flagJStrue,
            'jsobj' => $flagJSObj,
            'jslen' => $flagJSLen,
            'spvar' => $flagSPVar,
            'prop' => $flagProp,
            'method' => $flagMethod,
            'lambda' => $flagLambda,
            'mustlok' => $flagMustlok,
            'mustlam' => $flagMustlam,
            'mustsec' => $flagMustsec,
            'echo' => $flagEcho,
            'partnc' => $flagPartNC,
            'knohlp' => $flagKnownHlp,
            'debug' => isset(\$options['debug']) ? \$options['debug'] : $debug,
        ),
        'constants' => $constants,
        'helpers' => isset(\$options['helpers']) ? array_merge(\$helpers, \$options['helpers']) : \$helpers,
        'partials' => isset(\$options['partials']) ? array_merge(\$partials, \$options['partials']) : \$partials,
        'scopes' => array(),
        'sp_vars' => isset(\$options['data']) ? array_merge(array('root' => \$in), \$options['data']) : array('root' => \$in),
        'blparam' => array(),
        'partialid' => 0,
        'runtime' => '{$context['runtime']}',
    );
    {$context['renderex']}
    {$context['ops']['array_check']}
    {$context['ops']['op_start']}'$code'{$context['ops']['op_end']}
};
VAREND
        ;
    }
760921
public RequestContext renderCode(final int code) {
        if (renderer instanceof JsonRenderer) {
            final JsonRenderer r = (JsonRenderer) renderer;

            final JSONObject ret = r.getJSONObject();
            ret.put(Keys.CODE, code);
        }

        return this;
    }
876669
protected function decodeHash( $code )
	{
		$php	= gzinflate( base64_decode( $code ) );
		$php	= substr( $php, strlen( $this->incodePrefix) , -strlen( $this->incodeSuffix ) );
		return 	$php;
	}
440816
def render(self, context):
    ''''''
    modules = {
      'pyjade': __import__('pyjade')
    }
    context['false'] = False
    context['true'] = True
    try:
        return six.text_type(eval('pyjade.runtime.attrs(%s)'%self.code,modules,context))
    except NameError:
        return ''
749116
protected function _render($context = null)
    {
        if (is_null($context)) {
            $context = [];
        }

        return $this->_replaceTokens($this->_getPlaceholderTemplate(), $context, $this->_getTokenStart(), $this->_getTokenEnd(), $this->_getDefaultPlaceholderValue());
    }
316479
public function tokenize($code)
    {
        $this->tokens = array();
        $lines        = preg_split('/\r?\n/', $code);
        $number       = 0;

        foreach ($lines as $number => $fragment) {
            $this->processLine($number + 1, $fragment);
            $this->tokens[] = new Token(self::TOKEN_EOL, null, $number + 1);
        }
        $this->tokens[] = new Token(self::TOKEN_EOF, null, $number + 1);

        return new TokenStream($this->tokens);
    }
1032717
private function renderNoMacro(Context $context) {


		//================================================================
		//fig:cond
		//If the tag holds a fig:walk directive as well as the fig:cond,
		//do not take into account this fig:cond unless the rendering is inside the looping phase,
		//because the condition pertains to every single iteration, rather than to the global loop.
        // See WalkTest::testCondOnWalkAppliesToEachIter() for proof.
		if(null !== $this->figCond) {
			if((null === $this->figWalk) || $context->isBypassWalk()) {
				if(! $this->evalCondition($context)) {
					return '';
				}
			}
		}

		//================================================================
		//fig:case
		if($this->figCase) {
		    // Keep in mind that the case directive is written directly on the tag,
            // and there is no "switch" statement on its container.
            // So we must keep track at the parent level, of the current state of the case children.
			if($context->hasParent()) {
				if($context->isCaseSwitched()) {
					return '';
				} else {
					$condExpr = $this->figCase;
					$condVal = $this->evaluate($context, $condExpr);
					if(! $condVal) {
						return '';
					} else {
						$context->setCaseSwitched();
					}
				}
			}
		}


		//================================================================
        // Here, we can let a special Fig Tag perform its specific treatment.
        // Example: trans.
        // Doing this here, lets the tag benefit from previous logic (fig directive attributes)
        // such as cond, case etc.
        if ($context->view->isFigPrefix($this->name)) {
		    $specificResult = $this->doSpecific($context);
		    if (null !== $specificResult) {
		        return $specificResult;
            }
        }




		//================================================================
		//fig:walk
		//Loop over evaluated dataset.
		if(! $context->isBypassWalk()) {
			if(null !== $this->figWalk) {
				return $this->fig_walk($context);
			}
		}

		//================================================================
		//fig:call
		//A tag with the fig:call directive is necessarily mute.
		//It is used as a placeholder only for the directive.
		if(null !== $this->figCall) {
			return $this->fig_call($context);
		}




		//================================================================
		//fig:slot
		//Define the named slot at View level, pointing on the
		//current position of the rendering output.
		//Then, render the slot element, as a default content in case
		//nothing is plugged into it.
		//In case of plug for this slot, the complete slot tag (outer) is replaced.
		if($slotName = $this->getFigAttribute($context->figNamespace, 'slot')) {

            //Store a reference to current node, into the View's map of slots

			$anchorString = '/==SLOT==' . $slotName . '==/';
			$slot = new Slot($anchorString);
			$context->assignSlot($slotName, $slot);

			unset($this->attributes[$context->figNamespace . 'slot']);
			$result = $this->render($context);

			$slot->setLength(strlen($result));
			$this->attributes[$context->figNamespace . 'slot'] = $slotName;
			return $anchorString . $result;
		}

		//================================================================
		//fig:plug
		//An element bearing the fig:plug attribute
		//is to be rendered in place of the other element bearing
		//the corresponding fig:slot attribute.
		//The complete plug tag (outer) is rendered in place of the slot.
		//At slots-filling time, if a plug has a fig:append attribute evaluating to true,
		//its content is appended to whatever was already filled into the slot.
		//The entire plug+append tag (outer) is appended to the slot placeholder
		//(the slot's outer tag being removed).
		if(($slotName = $this->getFigAttribute($context->figNamespace, 'plug')) && ! $this->isTransient(self::TRANSIENT_PLUG_RENDERING)) {

			//Keep track of the callback node (the fig:plug node).
			//The callbacks are maintained as a chain. Several callbacks
			//can enchain one after the other,
			//in the order they were parsed.
			if ($context->view->hasOption(View::GLOBAL_PLUGS)) {
				//The plugs are rendered at the end of the rendering of the View.
				$context->addPlug($slotName);
			} else {
				// The plugs are rendered in their local context
				// (but still, remain stuffed at the end of the template rendering)
				$this->transient(self::TRANSIENT_PLUG_RENDERING);
				$context->addPlug($slotName, $this->render($context), $this->evalFigAttribute($context, 'append'));
			}

			//A fig:plug tag does not produce any in-place output.
			return '';
		}



		//================================================================
		//fig:auto
		//
		//This attribute means that the tag should render auto-closed, even though it
		//may be exploded for the purpose of assigning fig:attr children.
		if(null !== $this->figAuto) {
			$expression = $this->figAuto;
			if($this->evaluate($context, $expression)) {
			    // The empty string here is important, rather than null,
                // because it is needed by the part that renders the children of a fig:auto tag.
				$this->figText = '';
				$this->autoclose = true;
			}
		}

		//================================================================
		//fig:void
		//
		//This attribute means that the tag should render as HTML-void (such as: <br>)
		//and its contents discarded.
		if(null !== $this->figVoid) {
			$expression = $this->figVoid;
			if($this->evaluate($context, $expression)) {
				$this->figText = null;
				$this->voidtag = true;
			}
		}

        //================================================================
        //fig:text
        //
        //Instead of rendering current tag, replace its contents
        //with expression.
        //If expression is a symbol that represents an argument to
        //a macro call, of class ViewElementTag, then do not lex-eval
        //the expression but rather render this tag. This allows passing to a macro call
        //a complex fig:param (a piece of xml).
        //
        //Only the immediate Tag children of name fig:attr are parsed,
        //so that it is still possible to have dynamic attributes to a tag bearing fig:text.
        if(null !== $this->figText) {
            $content = $this->figText;

            $output = $this->evaluate($context, $content);
            if($output === null) {
                $this->outputBuffer = '';
            } else {

                // Unfortunately there is no auto __toString
                // for DOMNode objects (not even DOMText...)
                if (is_object($output)
                    && ($output instanceof \DOMNode)) {
                    $output = $output->nodeValue;
                }

                if (is_object($output)) {
                    // Try to convert object to string, using PHP's cast mechanism (possibly involving __toString() method).
                    try {
                        $output = (string) $output;
                    } catch(\ErrorException $ex) {
                        throw new RenderingException($this->getTagName(),
                            $context->getFilename(),
                            $this->getLineNumber(),
                            $ex->getMessage()
                        );
                    }
                }

                // Since we're in a fig:text directive, make sure we'll output a string (even if we got a bool)
                $output = (string) $output;
                $this->outputBuffer = $output;
				
				
				
                if (trim($output) != '') {
                    //We clear the autoclose flag only if there is any meaningful
                    //inner content.
                    $this->autoclose = false;
                }
            }

            if(! $this->isMute($context)) {
                //Take care of inner fig:attr
                $nChildren = count($this->children);
                for($iChild = 0; $iChild < $nChildren; ++$iChild) {
                    $child = & $this->children[$iChild];
                    if($child instanceof TagFigAttr) {
                        $child->render($context);
                    }
                }
            }
        }


		//Now proceed with the children...
		$result = $this->renderChildren($context);



		//Let's apply the potential filter on the inner parts.
		$result = $this->applyOutputFilter($context, $result);

		//And then, render the outer XML part of the tag, if not mute.

		//fig:mute
		//If this attribute is set and true,
		//then the current element is rendered withouts its
		//outer tag.
		//Every fig: tag is mute by nature.
		if(! $this->isMute($context)) {
			$xmlAttributesString = $this->buildXMLAttributesString($context);

			if ($this->voidtag) {
				$result = '<' . $this->name . $xmlAttributesString . '>';
			} else {
				if($result instanceof ViewElementTag) {
					$innerResults = $result->render($context);
				} else {
					$innerResults = $result;
				}
				
				// If the inner content is the result of some XML XPath
				// leading to a DOMText value, we can safely use the underlying
				// text for the object. Unfortunately there is no 
				// native __toString() there :(
				if (is_object($innerResults) 
				    && ($innerResults instanceof \DOMNode)) {
				  $innerResults = $innerResults->nodeValue;
				}
				
				$result =
					'<' . $this->name . $xmlAttributesString .
					($this->autoclose ? ' /' : '') .
				 '>' . $innerResults;
				if(! $this->autoclose) {
					$result .= '</' . $this->name . '>';
				}
			}


			//Clear runtime attributes (fig:attr) now that we have used them,
			//for potential next iteration of same tag,
			//because runtime attributes could be conditioned and the condition could eval differently
			//in next iteration.
            $context->clearRuntimeAttributes();
		}


		return $result;
	}
981051
protected function renderChildren(Context $context) {

        $doNotRenderFigParam = $context->isDoNotRenderFigParams();

		$result = '';
		//If a fig treatment happened already, then outputBuffer contains
		//the result to use. Otherwise, it needs to be calculated recursively
		//with the children.
		if($this->outputBuffer === null) {
			//A mute tag that does not have any content rendered yet, should not output the consecutive blank cdata.
			if( $this->isMute($context) ) {
				if(isset($this->children[0]) && ($this->children[0] instanceof ViewElementCData) ) {
					//TODO: comprendre pourquoi il me reste des blancs avant ?xml
					$this->children[0]->outputBuffer = preg_replace('#^[ \\t]*\\n#', '', $this->children[0]->outputBuffer);
				}
			}

			$nChildren = count($this->children);
			for($iChild = 0; $iChild < $nChildren; ++$iChild) {
				$child = & $this->children[$iChild];
				if($doNotRenderFigParam && ($child instanceof ViewElementTag) && ($child->getTagName() == $context->figNamespace . 'param') ) {
					//This situation is encountered when a sourced fig:trans tag has a fig:param immediate child:
					//the fig:param is used to resolve the translation, but it must not be rendered in the value of the
					//fig:trans tag (because it is sourced, it means that the translation is not to be taken from an external dictionary,
					//but rather directly the rendered content of the fig:trans tag).
					continue;
				}

				$subRender = $child->render($context);
				//Caution: it used to work fine, and then I got a: Could not
				//convert ViewElementTag to string,
				//as I called a macro with a fig:param being some XML piece, instead of a plain value.
				//So I added this additional step: the rendering of the said ViewElementTag.
				if($subRender instanceof ViewElement) {
					$subRender = $subRender->render($context);
				}
				$result .= $subRender;

			}
		} else {
			$result = $this->outputBuffer;
		}

		return $result;
	}
1328638
public function render($template, $data = [], $code = 200, array $headers = [])
    {
        $this->code = $code;

        $this->withHeaders($headers);

        $view = View::parse($template, $data);

        $this->content = $view->sendContent();

        return $this->buildHttpResponse();
    }
1015708
public function render($context)
    {
        if ($this->place || $this->place == self::RESET_CONTEXT) {
            return sprintf('<img src="%s" alt="%s" />', $this->path, $this->alt);
        } elseif ($this->place == self::PRE_CONTEXT) {
            return sprintf('<img src="%s" alt="%s" />', $this->path, $this->alt) . $context;
        } else {
            return $context . sprintf('<img src="%s" alt="%s" />', $this->path, $this->alt);
        }
    }
1154854
public function inline(string $code, bool $after = true): AssetInterface
    {
        $this->inline[] = [
            'code' => $code,
            'position' => $after ? 'after' : 'before'
        ];

        return $this;
    }
1002734
public function replace($code, array $placeholders = [])
    {
        $code = Helper::toType($code);
        if (empty($code) || !is_string($code)) {
            return $code;
        }
        if (!empty($placeholders)) {
            $this->addMultiPlaceholders($placeholders);
        }
        /*
         * Remove tpl-comment
         * ```
         * {* Comment about *}
         * ```
         */
        $code = preg_replace('/\{\*.*?\*\}/is', "", $code);
        $code = preg_replace_callback(
            '/
                (?P<beforeSkip>\{\!\\s*)?\[\[
                (?P<sanitizeDisable>\!)?
                (?P<type>[\#\%\~\$]?|\+{1,2}|@{1,2})					# search type of variable template
                (?P<name>@?[\\w\-\/\\\.\$]+)							# name of variable template [\w, -, \, .]
                (?:[^\[\]]++ | \[(?!\[) | \](?!\]) | (?R))*		# possible recursion
                \]\](?P<afterSkip>\\s*\!\})?
            /iux',
            [$this, 'replaceCallback'],
            $code
        );
        return Helper::toType($code);
    }
558135
public function render($context)
    {
        $values = array();

        foreach ($this->vars as $var) {
            $actualRow = $this->getRow()->getActualRow();
            $values[] = $actualRow[$var];
        }
        $value = vsprintf($this->value, $values);

        $this->getRow()->addVarAttr($this->name, $value);
        return $context;
    }
760537
public function render(array $data, ContextInterface $context)
    {
        $data += ['class' => ''];
        $data['class'] .= ' filled-in ';
        $data['class'] = trim($data['class']);

        return parent::render($data, $context);
    }
670361
protected void code(String template, String packageName, String className, Supplier<Map<String, Object>> context) {
        StringBuffer code = generate(template, context);
        writeCode(packageName, className, code);
    }
277654
public function transpile($code)
    {
        try {
            return AfxService::convertAfxToFusion($code);
        } catch (AfxException $afxException) {
            throw new Fusion\Exception(sprintf('Error during AFX-parsing: %s', $afxException->getMessage()));
        }
    }
653408
public function render(array $context = [])
    {
        $this->context()->addContext($context);
        $context = $this->context()->get();

        return $this->twig->render($context);
    }