Skip to content

Commit 47a5763

Browse files
committed
It is complete
There's probably a lot of bugs but the test article runs perfectly!
1 parent fe45b69 commit 47a5763

File tree

4 files changed

+204
-10
lines changed

4 files changed

+204
-10
lines changed

Engine/tEobject.php

Lines changed: 197 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,209 @@ function resolveValue($checkFor, $valueType) {
207207
}
208208

209209
public function construct() {
210+
$output = $this->constructFile($this->file, 0);
211+
return $output;
212+
}
213+
214+
function constructFile($file, $fileDepth) {
215+
// Some basic testing. Test if the file depth is too much to process, if the file even exists...
216+
if ($fileDepth >= tEnMaxFiles)
217+
return;
218+
$fileDepth++;
219+
$fileString = $this->getFile($file);
220+
if ($fileString == null)
221+
return;
222+
223+
// Some basic setup.
224+
$position = 0;
225+
$isOpen = false;
210226
$output = "";
211227

228+
while (true) {
229+
$substr = substr($fileString, $position, 1);
230+
231+
if ($substr == "")
232+
break;
233+
if ($substr == tEnTagQ)
234+
$position++;
235+
if ($substr == tEnTagS) { // If we have the start of a tag, move forward one and determine WHICH tag it is.
236+
$position++;
237+
$substr = substr($fileString, $position, 1);
238+
if ($substr == tEnConst || $substr == tEnVar || $substr == tEnFile || $substr == tEnTableB) {
239+
$isOpen = true;
240+
$finalValue = false;
241+
$size = 0;
242+
$start = $position;
243+
$tPosition = null;
244+
$primaryIn = $substr;
245+
} // If none of these match, it'll prevent the open tag parsing.
246+
}
247+
248+
while ($isOpen) {
249+
$size++;
250+
$substr = substr($fileString, $position+$size, 1);
251+
252+
// Going through tag logic.
253+
if (($substr == tEnConst || $substr == tEnVar || $substr == tEnFile) && !$finalValue) // We're looking for the variable input chains.
254+
$start++;
255+
else
256+
$finalValue = true;
257+
if ($substr == tEnTableK && $primaryIn == tEnTableB && $tPosition == null) { // When we find a table's K value, then we unlock finalValue and change the tPosition.
258+
$tPosition = $size;
259+
$tStart = $start;
260+
$finalValue = false;
261+
$start = $size;
262+
}
263+
if ($substr == tEnTagE) // When we find the end tag, we know it's ended.
264+
$isOpen = false;
265+
266+
if ($isOpen == false) {
267+
// First, we try to resolve!
268+
if ($primaryIn == tEnTableB) {
269+
$resolved = substr($fileString, $tStart+1, $tPosition-1);
270+
$resolvedT = substr($fileString, $position+$start+1, $size-$tPosition-2);
271+
272+
// Second half
273+
if ($start-1 != $tPosition) {
274+
$resolvedT = substr($fileString, $start+$position+1, $size-$start-1);
275+
while (true) {
276+
$toCheck = substr($fileString, $position+$start, 1);
277+
$resolutionTest = $this->resolveValue($resolvedT, $toCheck);
278+
if ($resolutionTest == null)
279+
break;
280+
$start--;
281+
$resolvedT = $resolutionTest;
282+
if ($start-1 == $position+$tPosition)
283+
break;
284+
}
285+
}
286+
287+
// First half
288+
if ($tStart != $position) {
289+
$resolved = substr($fileString, $tStart+1, $tPosition-($tStart-$position)-1);
290+
while (true) {
291+
$toCheck = substr($fileString, $tStart, 1);
292+
$resolutionTest = $this->resolveValue($resolved, $toCheck);
293+
if ($resolutionTest == null)
294+
break;
295+
$tStart--;
296+
$resolved = $resolutionTest;
297+
if ($tStart == $position)
298+
break;
299+
}
300+
}
301+
} elseif ($primaryIn == tEnConst || $primaryIn == tEnVar || $primaryIn == tEnFile) {
302+
$resolved = substr($fileString, $start+1, $size-1);
303+
if ($start != $position) {
304+
$resolved = substr($fileString, $start+1, $size-($start-$position)-1);
305+
while (true) {
306+
$toCheck = substr($fileString, $start, 1);
307+
$resolutionTest = $this->resolveValue($resolved, $toCheck);
308+
if ($resolutionTest == null)
309+
break;
310+
$start--;
311+
$resolved = $resolutionTest;
312+
if ($start == $position) // If we've reached the end of the tag, we break.
313+
break;
314+
}
315+
}
316+
}
317+
318+
// And then, we try to process with the resolved.
319+
$toOutput = substr($fileString, $position-1, $size+2);
320+
if ($primaryIn == tEnFile) {
321+
$fileRead = $this->getFile($resolved);
322+
if ($fileRead != null)
323+
$toOutput = $this->constructFile($resolved, $fileDepth);
324+
} elseif ($primaryIn == tEnTableB) {
325+
$toCheck = substr($fileString, $position+$start, 1);
326+
if ($toCheck == tEnConst || $toCheck == tEnVar) {
327+
$toOutput = "";
328+
$table = null;
329+
$tableFile = $this->getFile($resolved);
330+
if ($toCheck == tEnConst && defined($resolved))
331+
$table = constant($resolved);
332+
elseif ($toCheck == tEnVar && isset($this->toFill[2][$resolvedT]))
333+
$table = $this->toFill[2][$resolvedT];
334+
foreach ($table as $tableData) {
335+
$toOutput .= $this->constructTable($tableFile, $tableData);
336+
}
337+
}
338+
339+
} elseif ($primaryIn == tEnConst || $primaryIn == tEnVar) {
340+
if ($primaryIn == tEnConst && defined($resolved))
341+
$toOutput = constant($resolved);
342+
else
343+
if (isset($this->toFill[2][$resolved]))
344+
$toOutput = $this->toFill[2][$resolved];
345+
}
346+
347+
$output .= $toOutput;
348+
$position += $size+1;
349+
}
350+
}
351+
352+
$output .= substr($fileString, $position, 1);
353+
$position++;
354+
}
355+
212356
return $output;
213357
}
214358

215-
function constructFile($file, $fileDepth) {
359+
function constructTable($file, $array) {
360+
if ($file == null) // Don't bother, the file was empty.
361+
return;
362+
363+
$position = 0;
364+
$arrayPos = 0;
365+
$output = "";
366+
$isOpen = false;
367+
while (true) {
368+
$substr = substr($file, $position, 1);
369+
370+
if ($substr == "")
371+
break;
372+
if ($substr == tEnTagQ)
373+
$position++;
374+
if ($substr == tEnTagS) {
375+
$position++;
376+
$substr = substr($file, $position, 1);
377+
if ($substr == tEnTableV) {
378+
$isOpen = true;
379+
$size = 0;
380+
}
381+
}
382+
383+
while ($isOpen) {
384+
$substr = substr($file, $position+$size, 1);
385+
386+
if ($substr == "")
387+
$isOpen = false;
388+
if ($substr == tEnTagE)
389+
$isOpen = false;
390+
391+
if (!$isOpen) {
392+
$toProcess = substr($file, $position+1, $size-1);
393+
if ($size == 1) {
394+
if (isset($array[$arrayPos])) {
395+
$output .= $array[$arrayPos];
396+
$arrayPos++;
397+
} else
398+
$output .= "[Table blank!]";
399+
elseif (isset($array[$toProcess]))
400+
$output .= $array[$toProcess];
401+
}
402+
$position += $size;
403+
$substr = "";
404+
}
405+
$size++;
406+
}
407+
408+
$output .= $substr;
409+
$position++;
410+
}
216411

412+
return $output;
217413
}
218414

219415
// When you want to add a value, this is the function to call upon. Index is the variable name, and value is what you want to kill.

HTML/index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
echo $templateFile->construct();
1919

20+
21+
echo "<hr>";
2022
var_dump($templateFile->returnConsts());
2123
echo "<br>";
2224
var_dump($templateFile->returnVars());
2325
echo "<br>";
2426
var_dump($templateFile->returnSets());
25-
echo "<hr>";
2627
?>

HTML/test/likeThis.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<marquee>[@!thisLike]</marquee> <!-- Figures that blink doesn't work on most modern browsers, oh but MARQUEE DOES WTF. -->
1+
<b>[@!thisLike]</b><!-- Figures that blink doesn't work on most modern browsers, oh but MARQUEE DOES WTF. -->

HTML/test/test.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
<body>
1+
<body style="width : 800px">
22
<h1>Exemplar Template Engine : [!tEnMajor].[!tEnMinor].[!tEnPatch] - [!tEnCodename]</h1>
33
<p>This is a showcase of all of the template engine's feature.</p>
44
<hr>
55
<ul>
66
<li>Constants are \[!likeThis], [!likeThis]!</li>
77
<li>Variables are \[@likeThis], [@likeThis]!</li>
88
<li>Files are \[#likeThis.html], [#likeThis.html]!</li>
9-
<li>Tables are tags chained together are \[*fileName.html:!inputArray], and then repeatedly call upon \[^] or \[^tablePosition].</li>
9+
<li>Tables are technically two tags chained together are \[*fileName.html:!inputArray], and then repeatedly call upon \[^] or \[^tablePosition].</li>
1010
</ul>
11-
<p>Tables are a bit more involved, and work like this:</p>
11+
<p>Tables are a bit more involved. The idea is that a file is loaded in with *, and then a two dimensional array is after ;. The table is filled with ^ tags, which are replaced with data in the ; array's second dimension. This is repeated until the first dimension of the array is exhausted. Below is an example of it in action.</p>
1212
<table>
1313
[*table.html:@tableInput]
1414
</table>
15-
<table>
16-
[*!thisLike:!thisLike]
17-
</table>
1815
<p>As you can see, tables are a <i>very</i> powerful feature which open up many different possibilities.</p>
1916
<p>Another little interesting factoid is that file tags are first tested relative to the template, then relative to the script, and finally absolute. This means that you can place your templates folder anywhere you damn well please, and have it work just fine. Some examples include [#relativeFile.html], [#test2/relativeFile.html], and [#test3/relativeFile.html].</p>
2017
<hr>
2118
<p>Finally, this engine DOES support chaining together constant and variable tags with others, as well as file piping as input for variable names and such. That can look a bit like \[#@likeThis], \[^!likeThis], or even \[@!likeThis]. You can see this in action with [@!thisLike].</p>
22-
<p>Please note that piping files as variable names can lead to very strange results, and should be used sparingly, if not <b>NEVER</b>! It's simply there for specific edgecases. Also note that if safe insertion is enabled(is it enabled:[!tEnSafeInsert]? It is by default), you may have to call upon the method <b>refreshRequests()</b> multiple times in order to allow access to all chained/piped values.</p>
19+
<p>Please note that piping files as variable names can lead to very strange results, and should be used sparingly, if not <b>NEVER</b>! It's simply there for specific edgecases. Also note that if safe insertion is enabled(is it enabled:[!tEnSafeInsert]! It is by default,) you may have to call upon the method <b>refreshRequests()</b> multiple times in order to allow access to all chained/piped values.</p>
2320
</body>

0 commit comments

Comments
 (0)