@vituum/vite-plugin-latte 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/handler.js +9 -0
- package/index.js +138 -0
- package/index.php +173 -0
- package/latte/AssetFilter.php +11 -0
- package/latte/FetchFunction.php +28 -0
- package/latte/IconFilter.php +14 -0
- package/latte/JsonTag.php +64 -0
- package/latte/PlaceholderFunction.php +11 -0
- package/latte/RandomColorFunction.php +14 -0
- package/latte/TelFilter.php +22 -0
- package/package.json +35 -0
- package/vendor/autoload.php +7 -0
- package/vendor/bin/latte-lint +107 -0
- package/vendor/composer/ClassLoader.php +572 -0
- package/vendor/composer/InstalledVersions.php +350 -0
- package/vendor/composer/LICENSE +21 -0
- package/vendor/composer/autoload_classmap.php +183 -0
- package/vendor/composer/autoload_namespaces.php +9 -0
- package/vendor/composer/autoload_psr4.php +9 -0
- package/vendor/composer/autoload_real.php +57 -0
- package/vendor/composer/autoload_static.php +193 -0
- package/vendor/composer/installed.json +93 -0
- package/vendor/composer/installed.php +32 -0
- package/vendor/composer/platform_check.php +26 -0
- package/vendor/latte/latte/bin/latte-lint +29 -0
- package/vendor/latte/latte/composer.json +53 -0
- package/vendor/latte/latte/license.md +60 -0
- package/vendor/latte/latte/ncs.php +14 -0
- package/vendor/latte/latte/ncs.xml +9 -0
- package/vendor/latte/latte/readme.md +21 -0
- package/vendor/latte/latte/src/Bridges/Tracy/BlueScreenPanel.php +114 -0
- package/vendor/latte/latte/src/Bridges/Tracy/LattePanel.php +99 -0
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.panel.phtml +98 -0
- package/vendor/latte/latte/src/Bridges/Tracy/templates/LattePanel.tab.phtml +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Block.php +44 -0
- package/vendor/latte/latte/src/Latte/Compiler/Escaper.php +244 -0
- package/vendor/latte/latte/src/Latte/Compiler/ExpressionBuilder.php +128 -0
- package/vendor/latte/latte/src/Latte/Compiler/Node.php +28 -0
- package/vendor/latte/latte/src/Latte/Compiler/NodeHelpers.php +132 -0
- package/vendor/latte/latte/src/Latte/Compiler/NodeTraverser.php +77 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AreaNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/AuxiliaryNode.php +27 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/FragmentNode.php +59 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/AttributeNode.php +48 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/BogusTagNode.php +46 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/CommentNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/ElementNode.php +129 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Html/QuotedValue.php +53 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/NopNode.php +21 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ArgumentNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ComplexTypeNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayAccessNode.php +41 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayItemNode.php +52 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ArrayNode.php +94 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/AssignOpNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/BinaryOpNode.php +65 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CastNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClassConstantFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/CloneNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureNode.php +73 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ClosureUseNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ConstantFetchNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/EmptyNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/ErrorSuppressNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FilterCallNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/FunctionCallableNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InRangeNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/InstanceofNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/IssetNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MatchNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallNode.php +50 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/MethodCallableNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NewNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/NotNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PostOpNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PreOpNode.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/PropertyFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallNode.php +55 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticCallableNode.php +47 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/StaticPropertyFetchNode.php +42 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/TernaryNode.php +50 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/UnaryOpNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Expression/VariableNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ExpressionNode.php +17 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/FilterNode.php +67 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IdentifierNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/IntersectionTypeNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/MatchArmNode.php +45 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ModifierNode.php +107 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NameNode.php +89 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/NullableTypeNode.php +35 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ParameterNode.php +54 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/BooleanNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringNode.php +80 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/EncapsedStringPartNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/FloatNode.php +63 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/IntegerNode.php +70 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/NullNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/Scalar/StringNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/ScalarNode.php +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/UnionTypeNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/Php/VarLikeIdentifierNode.php +21 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/StatementNode.php +15 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TemplateNode.php +34 -0
- package/vendor/latte/latte/src/Latte/Compiler/Nodes/TextNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Compiler/PhpHelpers.php +227 -0
- package/vendor/latte/latte/src/Latte/Compiler/Position.php +43 -0
- package/vendor/latte/latte/src/Latte/Compiler/PrintContext.php +334 -0
- package/vendor/latte/latte/src/Latte/Compiler/Tag.php +117 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagLexer.php +399 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagParser.php +388 -0
- package/vendor/latte/latte/src/Latte/Compiler/TagParserData.php +580 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateGenerator.php +206 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateLexer.php +391 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParser.php +448 -0
- package/vendor/latte/latte/src/Latte/Compiler/TemplateParserHtml.php +506 -0
- package/vendor/latte/latte/src/Latte/Compiler/Token.php +259 -0
- package/vendor/latte/latte/src/Latte/Compiler/TokenStream.php +151 -0
- package/vendor/latte/latte/src/Latte/ContentType.php +22 -0
- package/vendor/latte/latte/src/Latte/Engine.php +591 -0
- package/vendor/latte/latte/src/Latte/Essential/Blueprint.php +160 -0
- package/vendor/latte/latte/src/Latte/Essential/CachingIterator.php +232 -0
- package/vendor/latte/latte/src/Latte/Essential/CoreExtension.php +232 -0
- package/vendor/latte/latte/src/Latte/Essential/Filters.php +591 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/BlockNode.php +161 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/CaptureNode.php +98 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ContentTypeNode.php +74 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DebugbreakNode.php +53 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DefineNode.php +134 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DoNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/DumpNode.php +58 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/EmbedNode.php +125 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ExtendsNode.php +60 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/FirstLastSepNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForNode.php +91 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ForeachNode.php +155 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfChangedNode.php +141 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfContentNode.php +82 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IfNode.php +180 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ImportNode.php +49 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeBlockNode.php +140 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IncludeFileNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/IterateWhileNode.php +94 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NAttrNode.php +105 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NClassNode.php +54 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/NTagNode.php +79 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/ParametersNode.php +84 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/PrintNode.php +70 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RawPhpNode.php +46 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/RollbackNode.php +37 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SkipNode.php +71 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SpacelessNode.php +62 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/SwitchNode.php +118 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplatePrintNode.php +39 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TemplateTypeNode.php +38 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TraceNode.php +35 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TranslateNode.php +104 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/TryNode.php +75 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarNode.php +106 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarPrintNode.php +40 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/VarTypeNode.php +36 -0
- package/vendor/latte/latte/src/Latte/Essential/Nodes/WhileNode.php +81 -0
- package/vendor/latte/latte/src/Latte/Essential/Passes.php +115 -0
- package/vendor/latte/latte/src/Latte/Essential/RawPhpExtension.php +28 -0
- package/vendor/latte/latte/src/Latte/Essential/RollbackException.php +16 -0
- package/vendor/latte/latte/src/Latte/Essential/Tracer.php +117 -0
- package/vendor/latte/latte/src/Latte/Essential/TranslatorExtension.php +101 -0
- package/vendor/latte/latte/src/Latte/Extension.php +97 -0
- package/vendor/latte/latte/src/Latte/Helpers.php +96 -0
- package/vendor/latte/latte/src/Latte/Loader.php +37 -0
- package/vendor/latte/latte/src/Latte/Loaders/FileLoader.php +95 -0
- package/vendor/latte/latte/src/Latte/Loaders/StringLoader.php +76 -0
- package/vendor/latte/latte/src/Latte/Policy.php +24 -0
- package/vendor/latte/latte/src/Latte/PositionAwareException.php +50 -0
- package/vendor/latte/latte/src/Latte/Runtime/Block.php +24 -0
- package/vendor/latte/latte/src/Latte/Runtime/FilterExecutor.php +151 -0
- package/vendor/latte/latte/src/Latte/Runtime/FilterInfo.php +39 -0
- package/vendor/latte/latte/src/Latte/Runtime/Filters.php +234 -0
- package/vendor/latte/latte/src/Latte/Runtime/Html.php +35 -0
- package/vendor/latte/latte/src/Latte/Runtime/HtmlStringable.php +17 -0
- package/vendor/latte/latte/src/Latte/Runtime/Template.php +381 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/FunctionCallableNode.php +29 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/MethodCallableNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/PropertyFetchNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/SandboxNode.php +73 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallNode.php +31 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticCallableNode.php +30 -0
- package/vendor/latte/latte/src/Latte/Sandbox/Nodes/StaticPropertyFetchNode.php +32 -0
- package/vendor/latte/latte/src/Latte/Sandbox/RuntimeChecker.php +116 -0
- package/vendor/latte/latte/src/Latte/Sandbox/SandboxExtension.php +132 -0
- package/vendor/latte/latte/src/Latte/Sandbox/SecurityPolicy.php +185 -0
- package/vendor/latte/latte/src/Latte/Strict.php +101 -0
- package/vendor/latte/latte/src/Latte/attributes.php +24 -0
- package/vendor/latte/latte/src/Latte/exceptions.php +69 -0
- package/vendor/latte/latte/src/Tools/Linter.php +175 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential\Nodes;
|
|
11
|
+
|
|
12
|
+
use Latte;
|
|
13
|
+
use Latte\Compiler\Nodes\Php\Expression\ArrayNode;
|
|
14
|
+
use Latte\Compiler\Nodes\StatementNode;
|
|
15
|
+
use Latte\Compiler\PrintContext;
|
|
16
|
+
use Latte\Compiler\Tag;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* n:attr="..."
|
|
21
|
+
*/
|
|
22
|
+
final class NAttrNode extends StatementNode
|
|
23
|
+
{
|
|
24
|
+
public ArrayNode $args;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
public static function create(Tag $tag): static
|
|
28
|
+
{
|
|
29
|
+
$tag->expectArguments();
|
|
30
|
+
$node = new static;
|
|
31
|
+
$node->args = $tag->parser->parseArguments();
|
|
32
|
+
return $node;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
public function print(PrintContext $context): string
|
|
37
|
+
{
|
|
38
|
+
return $context->format(
|
|
39
|
+
'$ʟ_tmp = %node;
|
|
40
|
+
echo %raw::attrs(isset($ʟ_tmp[0]) && is_array($ʟ_tmp[0]) ? $ʟ_tmp[0] : $ʟ_tmp, %dump) %line;',
|
|
41
|
+
$this->args,
|
|
42
|
+
self::class,
|
|
43
|
+
$context->getEscaper()->getContentType() === Latte\ContentType::Xml,
|
|
44
|
+
$this->position,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/** @internal */
|
|
50
|
+
public static function attrs($attrs, bool $xml): string
|
|
51
|
+
{
|
|
52
|
+
if (!is_array($attrs)) {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
$s = '';
|
|
57
|
+
foreach ($attrs as $key => $value) {
|
|
58
|
+
if ($value === null || $value === false) {
|
|
59
|
+
continue;
|
|
60
|
+
|
|
61
|
+
} elseif ($value === true) {
|
|
62
|
+
$s .= ' ' . $key . ($xml ? '="' . $key . '"' : '');
|
|
63
|
+
continue;
|
|
64
|
+
|
|
65
|
+
} elseif (is_array($value)) {
|
|
66
|
+
$tmp = null;
|
|
67
|
+
foreach ($value as $k => $v) {
|
|
68
|
+
if ($v != null) { // intentionally ==, skip nulls & empty string
|
|
69
|
+
// composite 'style' vs. 'others'
|
|
70
|
+
$tmp[] = $v === true
|
|
71
|
+
? $k
|
|
72
|
+
: (is_string($k) ? $k . ':' . $v : $v);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if ($tmp === null) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
$value = implode($key === 'style' || !strncmp($key, 'on', 2) ? ';' : ' ', $tmp);
|
|
81
|
+
|
|
82
|
+
} else {
|
|
83
|
+
$value = (string) $value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
$q = !str_contains($value, '"') ? '"' : "'";
|
|
87
|
+
$s .= ' ' . $key . '=' . $q
|
|
88
|
+
. str_replace(
|
|
89
|
+
['&', $q, '<'],
|
|
90
|
+
['&', $q === '"' ? '"' : ''', $xml ? '<' : '<'],
|
|
91
|
+
$value,
|
|
92
|
+
)
|
|
93
|
+
. (str_contains($value, '`') && strpbrk($value, ' <>"\'') === false ? ' ' : '')
|
|
94
|
+
. $q;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return $s;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
public function &getIterator(): \Generator
|
|
102
|
+
{
|
|
103
|
+
yield $this->args;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential\Nodes;
|
|
11
|
+
|
|
12
|
+
use Latte\CompileException;
|
|
13
|
+
use Latte\Compiler\Nodes\Php\Expression\ArrayNode;
|
|
14
|
+
use Latte\Compiler\Nodes\StatementNode;
|
|
15
|
+
use Latte\Compiler\PrintContext;
|
|
16
|
+
use Latte\Compiler\Tag;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* n:class="..."
|
|
21
|
+
*/
|
|
22
|
+
final class NClassNode extends StatementNode
|
|
23
|
+
{
|
|
24
|
+
public ArrayNode $args;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
public static function create(Tag $tag): static
|
|
28
|
+
{
|
|
29
|
+
if ($tag->htmlElement->getAttribute('class')) {
|
|
30
|
+
throw new CompileException('It is not possible to combine class with n:class.', $tag->position);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
$tag->expectArguments();
|
|
34
|
+
$node = new static;
|
|
35
|
+
$node->args = $tag->parser->parseArguments();
|
|
36
|
+
return $node;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
public function print(PrintContext $context): string
|
|
41
|
+
{
|
|
42
|
+
return $context->format(
|
|
43
|
+
'echo ($ʟ_tmp = array_filter(%node)) ? \' class="\' . LR\Filters::escapeHtmlAttr(implode(" ", array_unique($ʟ_tmp))) . \'"\' : "" %line;',
|
|
44
|
+
$this->args,
|
|
45
|
+
$this->position,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
public function &getIterator(): \Generator
|
|
51
|
+
{
|
|
52
|
+
yield $this->args;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential\Nodes;
|
|
11
|
+
|
|
12
|
+
use Latte;
|
|
13
|
+
use Latte\CompileException;
|
|
14
|
+
use Latte\Compiler\Nodes\Php\ExpressionNode;
|
|
15
|
+
use Latte\Compiler\Nodes\StatementNode;
|
|
16
|
+
use Latte\Compiler\PrintContext;
|
|
17
|
+
use Latte\Compiler\Tag;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* n:tag="..."
|
|
22
|
+
*/
|
|
23
|
+
final class NTagNode extends StatementNode
|
|
24
|
+
{
|
|
25
|
+
public ExpressionNode $name;
|
|
26
|
+
public string $origName;
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
public static function create(Tag $tag): void
|
|
30
|
+
{
|
|
31
|
+
if (preg_match('(style$|script$)iA', $tag->htmlElement->name)) {
|
|
32
|
+
throw new CompileException('Attribute n:tag is not allowed in <script> or <style>', $tag->position);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
$tag->expectArguments();
|
|
36
|
+
$node = new static;
|
|
37
|
+
$node->name = $tag->parser->parseExpression();
|
|
38
|
+
$node->origName = $tag->htmlElement->name;
|
|
39
|
+
$tag->htmlElement->customName = $node;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
public function print(PrintContext $context): string
|
|
44
|
+
{
|
|
45
|
+
return self::class . '::check('
|
|
46
|
+
. var_export($this->origName, true)
|
|
47
|
+
. ', '
|
|
48
|
+
. $this->name->print($context)
|
|
49
|
+
. ')';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
public static function check(string $orig, $new): string
|
|
54
|
+
{
|
|
55
|
+
if ($new === null) {
|
|
56
|
+
return $orig;
|
|
57
|
+
|
|
58
|
+
} elseif (
|
|
59
|
+
!is_string($new)
|
|
60
|
+
|| !preg_match('~' . Latte\Compiler\TemplateLexer::ReTagName . '$~DA', $new)
|
|
61
|
+
) {
|
|
62
|
+
throw new Latte\RuntimeException('Invalid tag name ' . var_export($new, true));
|
|
63
|
+
|
|
64
|
+
} elseif (
|
|
65
|
+
in_array($lower = strtolower($new), ['style', 'script'], true)
|
|
66
|
+
|| isset(Latte\Helpers::$emptyElements[strtolower($orig)]) !== isset(Latte\Helpers::$emptyElements[$lower])
|
|
67
|
+
) {
|
|
68
|
+
throw new Latte\RuntimeException("Forbidden tag <$orig> change to <$new>.");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return $new;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
public function &getIterator(): \Generator
|
|
76
|
+
{
|
|
77
|
+
yield $this->name;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential\Nodes;
|
|
11
|
+
|
|
12
|
+
use Latte\CompileException;
|
|
13
|
+
use Latte\Compiler\Nodes\Php\Expression\AssignNode;
|
|
14
|
+
use Latte\Compiler\Nodes\Php\Expression\VariableNode;
|
|
15
|
+
use Latte\Compiler\Nodes\Php\ParameterNode;
|
|
16
|
+
use Latte\Compiler\Nodes\Php\Scalar\NullNode;
|
|
17
|
+
use Latte\Compiler\Nodes\StatementNode;
|
|
18
|
+
use Latte\Compiler\PrintContext;
|
|
19
|
+
use Latte\Compiler\Tag;
|
|
20
|
+
use Latte\Compiler\Token;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* {parameters [type] $var, ...}
|
|
25
|
+
*/
|
|
26
|
+
class ParametersNode extends StatementNode
|
|
27
|
+
{
|
|
28
|
+
/** @var ParameterNode[] */
|
|
29
|
+
public array $parameters = [];
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
public static function create(Tag $tag): static
|
|
33
|
+
{
|
|
34
|
+
if (!$tag->isInHead()) {
|
|
35
|
+
throw new CompileException('{parameters} is allowed only in template header.', $tag->position);
|
|
36
|
+
}
|
|
37
|
+
$tag->expectArguments();
|
|
38
|
+
$node = new static;
|
|
39
|
+
$node->parameters = self::parseParameters($tag);
|
|
40
|
+
return $node;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
private static function parseParameters(Tag $tag): array
|
|
45
|
+
{
|
|
46
|
+
$stream = $tag->parser->stream;
|
|
47
|
+
$params = [];
|
|
48
|
+
do {
|
|
49
|
+
$type = $tag->parser->parseType();
|
|
50
|
+
|
|
51
|
+
$save = $stream->getIndex();
|
|
52
|
+
$expr = $stream->is(Token::Php_Variable) ? $tag->parser->parseExpression() : null;
|
|
53
|
+
if ($expr instanceof VariableNode && is_string($expr->name)) {
|
|
54
|
+
$params[] = new ParameterNode($expr, new NullNode, $type);
|
|
55
|
+
} elseif (
|
|
56
|
+
$expr instanceof AssignNode
|
|
57
|
+
&& $expr->var instanceof VariableNode
|
|
58
|
+
&& is_string($expr->var->name)
|
|
59
|
+
) {
|
|
60
|
+
$params[] = new ParameterNode($expr->var, $expr->expr, $type);
|
|
61
|
+
} else {
|
|
62
|
+
$stream->seek($save);
|
|
63
|
+
$stream->throwUnexpectedException(addendum: ' in ' . $tag->getNotation());
|
|
64
|
+
}
|
|
65
|
+
} while ($stream->tryConsume(','));
|
|
66
|
+
|
|
67
|
+
return $params;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
public function print(PrintContext $context): string
|
|
72
|
+
{
|
|
73
|
+
$context->paramsExtraction = $this->parameters;
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
public function &getIterator(): \Generator
|
|
79
|
+
{
|
|
80
|
+
foreach ($this->parameters as &$param) {
|
|
81
|
+
yield $param;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential\Nodes;
|
|
11
|
+
|
|
12
|
+
use Latte\CompileException;
|
|
13
|
+
use Latte\Compiler\Nodes\Php\ExpressionNode;
|
|
14
|
+
use Latte\Compiler\Nodes\Php\ModifierNode;
|
|
15
|
+
use Latte\Compiler\Nodes\StatementNode;
|
|
16
|
+
use Latte\Compiler\PrintContext;
|
|
17
|
+
use Latte\Compiler\Tag;
|
|
18
|
+
use Latte\Compiler\TemplateParser;
|
|
19
|
+
use Latte\ContentType;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* {= ...}
|
|
24
|
+
*/
|
|
25
|
+
class PrintNode extends StatementNode
|
|
26
|
+
{
|
|
27
|
+
public ExpressionNode $expression;
|
|
28
|
+
public ModifierNode $modifier;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
public static function create(Tag $tag, TemplateParser $parser): static
|
|
32
|
+
{
|
|
33
|
+
$tag->outputMode = $tag::OutputKeepIndentation;
|
|
34
|
+
|
|
35
|
+
$stream = $parser->getStream();
|
|
36
|
+
if (
|
|
37
|
+
$tag->isInText()
|
|
38
|
+
&& $parser->getContentType() === ContentType::Html
|
|
39
|
+
&& $tag->htmlElement?->name === 'script'
|
|
40
|
+
&& preg_match('#["\']#A', $stream->peek()->text)
|
|
41
|
+
) {
|
|
42
|
+
throw new CompileException("Do not place {$tag->getNotation(true)} inside quotes in JavaScript.", $tag->position);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
$tag->expectArguments();
|
|
46
|
+
$node = new static;
|
|
47
|
+
$node->expression = $tag->parser->parseExpression();
|
|
48
|
+
$node->modifier = $tag->parser->parseModifier();
|
|
49
|
+
$node->modifier->escape = true;
|
|
50
|
+
return $node;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
public function print(PrintContext $context): string
|
|
55
|
+
{
|
|
56
|
+
return $context->format(
|
|
57
|
+
"echo %modify(%node) %line;\n",
|
|
58
|
+
$this->modifier,
|
|
59
|
+
$this->expression,
|
|
60
|
+
$this->position,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
public function &getIterator(): \Generator
|
|
66
|
+
{
|
|
67
|
+
yield $this->expression;
|
|
68
|
+
yield $this->modifier;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential\Nodes;
|
|
11
|
+
|
|
12
|
+
use Latte\Compiler\Nodes\StatementNode;
|
|
13
|
+
use Latte\Compiler\PrintContext;
|
|
14
|
+
use Latte\Compiler\Tag;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* {php statement; statement; ...}
|
|
19
|
+
*/
|
|
20
|
+
class RawPhpNode extends StatementNode
|
|
21
|
+
{
|
|
22
|
+
public string $code;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
public static function create(Tag $tag): static
|
|
26
|
+
{
|
|
27
|
+
$tag->expectArguments();
|
|
28
|
+
while (!$tag->parser->stream->consume()->isEnd());
|
|
29
|
+
$node = new static;
|
|
30
|
+
$node->code = trim($tag->parser->text);
|
|
31
|
+
if (!preg_match('~[;}]$~', $node->code)) {
|
|
32
|
+
$node->code .= ';';
|
|
33
|
+
}
|
|
34
|
+
return $node;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
public function print(PrintContext $context): string
|
|
39
|
+
{
|
|
40
|
+
return $context->format(
|
|
41
|
+
'%line; %raw ',
|
|
42
|
+
$this->position,
|
|
43
|
+
$this->code,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential\Nodes;
|
|
11
|
+
|
|
12
|
+
use Latte\CompileException;
|
|
13
|
+
use Latte\Compiler\Nodes\StatementNode;
|
|
14
|
+
use Latte\Compiler\PrintContext;
|
|
15
|
+
use Latte\Compiler\Tag;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* {rollback}
|
|
20
|
+
*/
|
|
21
|
+
class RollbackNode extends StatementNode
|
|
22
|
+
{
|
|
23
|
+
public static function create(Tag $tag): static
|
|
24
|
+
{
|
|
25
|
+
if (!$tag->closestTag(['try'])) {
|
|
26
|
+
throw new CompileException('Tag {rollback} must be inside {try} ... {/try}.', $tag->position);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return new static;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
public function print(PrintContext $context): string
|
|
34
|
+
{
|
|
35
|
+
return 'throw new Latte\Essential\RollbackException;';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential\Nodes;
|
|
11
|
+
|
|
12
|
+
use Latte\CompileException;
|
|
13
|
+
use Latte\Compiler\Nodes\Php\ExpressionNode;
|
|
14
|
+
use Latte\Compiler\Nodes\StatementNode;
|
|
15
|
+
use Latte\Compiler\PrintContext;
|
|
16
|
+
use Latte\Compiler\Tag;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* {breakIf ...}
|
|
21
|
+
* {continueIf ...}
|
|
22
|
+
* {skipIf ...}
|
|
23
|
+
*/
|
|
24
|
+
class SkipNode extends StatementNode
|
|
25
|
+
{
|
|
26
|
+
public string $type;
|
|
27
|
+
public ExpressionNode $condition;
|
|
28
|
+
public ?string $endTag = null;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
public static function create(Tag $tag): static
|
|
32
|
+
{
|
|
33
|
+
$tag->expectArguments();
|
|
34
|
+
if (!$tag->closestTag($tag->name === 'skipIf' ? ['foreach'] : ['for', 'foreach', 'while'])) {
|
|
35
|
+
throw new CompileException("Tag {{$tag->name}} is unexpected here.", $tag->position);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
$node = new static;
|
|
39
|
+
$node->type = $tag->name;
|
|
40
|
+
$node->condition = $tag->parser->parseExpression();
|
|
41
|
+
if (isset($tag->htmlElement->nAttributes['foreach'])) {
|
|
42
|
+
$node->endTag = $tag->htmlElement->name;
|
|
43
|
+
}
|
|
44
|
+
return $node;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
public function print(PrintContext $context): string
|
|
49
|
+
{
|
|
50
|
+
$cmd = $this->type === 'skipIf'
|
|
51
|
+
? '{ $iterator->skipRound(); continue; }'
|
|
52
|
+
: str_replace('If', '', $this->type) . ';';
|
|
53
|
+
|
|
54
|
+
if ($this->endTag) {
|
|
55
|
+
$cmd = "{ echo \"</$this->endTag>\\n\"; $cmd; } ";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return $context->format(
|
|
59
|
+
"if (%node) %line %raw\n",
|
|
60
|
+
$this->condition,
|
|
61
|
+
$this->position,
|
|
62
|
+
$cmd,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
public function &getIterator(): \Generator
|
|
68
|
+
{
|
|
69
|
+
yield $this->condition;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is part of the Latte (https://latte.nette.org)
|
|
5
|
+
* Copyright (c) 2008 David Grudl (https://davidgrudl.com)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare(strict_types=1);
|
|
9
|
+
|
|
10
|
+
namespace Latte\Essential\Nodes;
|
|
11
|
+
|
|
12
|
+
use Latte\Compiler\Nodes\AreaNode;
|
|
13
|
+
use Latte\Compiler\Nodes\StatementNode;
|
|
14
|
+
use Latte\Compiler\PrintContext;
|
|
15
|
+
use Latte\Compiler\Tag;
|
|
16
|
+
use Latte\ContentType;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* {spaceless}
|
|
21
|
+
*/
|
|
22
|
+
class SpacelessNode extends StatementNode
|
|
23
|
+
{
|
|
24
|
+
public AreaNode $content;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/** @return \Generator<int, ?array, array{AreaNode, ?Tag}, static> */
|
|
28
|
+
public static function create(Tag $tag): \Generator
|
|
29
|
+
{
|
|
30
|
+
$node = new static;
|
|
31
|
+
[$node->content] = yield;
|
|
32
|
+
return $node;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
public function print(PrintContext $context): string
|
|
37
|
+
{
|
|
38
|
+
return $context->format(
|
|
39
|
+
<<<'XX'
|
|
40
|
+
ob_start('Latte\Essential\Filters::%raw', 4096) %line;
|
|
41
|
+
try {
|
|
42
|
+
%node
|
|
43
|
+
} finally {
|
|
44
|
+
ob_end_flush();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
XX,
|
|
49
|
+
$context->getEscaper()->getContentType() === ContentType::Html
|
|
50
|
+
? 'spacelessHtmlHandler'
|
|
51
|
+
: 'spacelessText',
|
|
52
|
+
$this->position,
|
|
53
|
+
$this->content,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public function &getIterator(): \Generator
|
|
59
|
+
{
|
|
60
|
+
yield $this->content;
|
|
61
|
+
}
|
|
62
|
+
}
|