App: manual Page: fragments/page_4
PHP
|
HTML
fragments/page_4.pad
|
Result
|
|
{data 'fruit'}["apple","pear"]{/data} <p>A clean pass sees the store: {code clean}{fruit}{$fruit} {/fruit}{/code}</p> {code}{sequence '7;8;9', push='nums'/}{/code} <p>A plain pass pushed nums, and it survived: {pull:nums}{$sequence} {/pull:nums}</p>
|
|
App: manual Page: fragments/response_fragments_1
PHP
|
HTML
fragments/response_fragments_1.pad
|
Result
|
|
<h4>Orders</h4>
{fragment 'order-list'} <ul> {sequence '101..103', name='number'}<li>Order {$number}</li>{/sequence} </ul> {/fragment}
<p>The page goes on here.</p>
|
|
App: manual Page: fragments/sequences_1
PHP
|
HTML
fragments/sequences_1.pad
|
Result
|
|
<p>{sequence '1..8'}{$sequence} {/sequence}</p> <p>{sequence fibonacci, rows=8}{$sequence} {/sequence}</p> <p>{sequence prime, from=10, rows=6}{$sequence} {/sequence}</p> <p>{sequence 'A..F'}{$sequence} {/sequence}</p>
|
|
App: manual Page: fragments/stacks_1
PHP
|
HTML
fragments/stacks_1.pad
|
Result
|
|
<p>Stylesheets this page needs:</p> <ul>{stack 'styles'}</ul>
{sequence '1..3', name='n'} {push 'styles', once='badge'}<li>badge.css</li>{/push} <span class="badge">badge {$n}</span> {/sequence}
{push 'styles'}<li>footer.css</li>{/push}
|
|
App: manual Page: lvl_occ/5
PHP
|
HTML
lvl_occ/5.pad
|
Result
|
|
<table border='1'> {sequence '10..30', increment=10, name='row'} <tr> {sequence '1..5', name='column'} <td>{$row | + $column}</td> {/sequence} </tr> {/sequence} </table>
|
|
App: manual Page: miscellaneous/level_and_occurrence_variables
App: manual Page: pages/level_and_occurrence_variables
PHP
|
HTML
pages/level_and_occurrence_variables.pad
|
Result
|
|
{block} $xxx variables are set once at the beginning of a level<br> %xxx variables are set on every occurence inside a level<br> {/block}
{page 'miscellaneous/level_and_occurrence_variables'}
|
|
App: manual Page: pages/levels_and_occurrences
PHP
|
HTML
pages/levels_and_occurrences.pad
|
Result
|
|
<p> {block} PAD is data driven, the PAD data concepts are named Level and Occurence <br><br> Below example: <br> - Is two levels deep <br> - The level 'row' has 3 occurences<br> - The level 'column' has 5 occurences<br><br> {/block} {example 'lvl_occ/1', skipNames, center} </p>
{block} If not specifield for a PAD tag then default it has 1 occurence. <br><br><hr><br> Just for fun, below the above example implemented in a few different ways. <br> Hopefully all this magic will be explained in this manual. {/block}
<p> {sequence '2..12', name='xxx'} {example 'lvl_occ/{$xxx}', skipNames{notFirst},skipOpen,skipHeader{/notFirst}{notLast},skipClose{/notLast}} {/sequence} </p>
|
|
App: manual Page: pages/page
PHP
|
HTML
pages/page.pad
|
Result
|
|
{meta title='Nested Passes - {code} and {page}'}
<p>A nested pass is the engine run inside itself: the content of a <code>{code}</code> pair, or the page a <code>{page}</code> tag names, is rendered as a complete PAD run of its own, and what it produced lands in the surrounding page. The pass sees the request it runs in - its variables, its stores - unless it asks for isolation.</p>
<h2>A pass and what it leaves behind</h2>
<p>A plain <code>{code}</code> shares everything. What the pass creates is still there when it returns:</p>
{example 'fragments/page_1'}
<h2>The four isolation forms</h2>
<p>Three options decide how much of the request a pass sees, and how much of the pass the request keeps. They differ on both sides of the boundary:</p>
<table border="1" cellpadding="8" cellspacing="0" style="border-collapse: collapse;"> <tr><th>form</th><th>sees the outer state</th><th>what it created afterwards</th></tr> <tr><td><code>{code}</code></td> <td>yes</td><td>still there</td></tr> <tr><td><code>{code reset}</code></td> <td>no - a blank slate going in</td><td>still there</td></tr> <tr><td><code>{code clean}</code></td> <td>yes</td><td>taken back out</td></tr> <tr><td><code>{code sandbox}</code></td> <td>no</td><td>taken back out</td></tr> </table>
<p> </p>
{example 'fragments/page_2'}
<h2>Another page as a pass</h2>
<p><code>{page 'name'}</code> runs that page - its .php and its .pad - as a pass, with the same isolation options. A <code>function</code> option runs the pass inside a PHP function body, but it still starts from the caller's variables and what it sets comes back out - a page whose .php half must not touch the caller's variables wants <code>clean</code> or <code>sandbox</code>:</p>
{example 'fragments/page_3'}
<h2>Stores cross the boundary by the same rules</h2>
<p>The data, content, bool and sequence stores follow the isolation form. A <code>clean</code> pass reads the request's stores; a <code>sandbox</code> or <code>reset</code> pass starts without them. On the way out, only a plain pass's pushes stay: each of the three isolated forms puts the request's stores back exactly as they were, its own pushes included:</p>
{example 'fragments/page_4'}
<h2>Engine state is always put back</h2>
<p>Whatever the isolation form, the engine itself returns to where it was: a loop the pass ran inside continues from the same row, and a request-lived counter such as <code>{switch}</code>'s rotation is rolled back with the rest - a pass takes its counting with it:</p>
{example 'fragments/page_5'}
<p>Both calls answer the first value: the rotation the pass advanced was restored when the pass returned.</p>
|
|
App: manual Page: pages/response_fragments
PHP
|
HTML
pages/response_fragments.pad
|
Result
|
|
{meta title='Response fragments'}
<p>A search result, a page of a list, a counter: a part of a page that the browser wants to refresh on its own. <code>{fragment 'name'}...{/fragment}</code> names such a part. A normal request renders the whole page, the fragment in its place:</p>
{example 'fragments/response_fragments_1'}
<p>A request that adds <code>&padFragment=order-list</code> to the URL gets that fragment and nothing else - the same template serves the full page and the update:</p>
{example 'fragments/response_fragments_2'}
<h2>How it works</h2>
<ul> <li>The page renders up to the end of the fragment, and the fragment's rendering - closing pipe included - is the whole response. What comes after it is not rendered at all.</li> <li>The response is bare, like a <code>padInclude</code> request: no wrapper, no tidy.</li> <li>The first fragment of that name to finish rendering is the one sent. Keep a fragment unconditional and put conditions inside it: a request for a fragment that never rendered is an error under the strict check, and an empty 404 otherwise.</li> <li>The page's PHP may decide too: <code>$padFragmentOnly = 'order-list';</code> - for instance when the request carries an <code>HX-Request</code> header.</li> </ul>
<h2>With ajax and HTMX</h2>
<ul> <li><code>{ajax 'orders', fragment='order-list'}</code> fetches only that fragment of the page into its div.</li> <li>HTMX: <code><div hx-get="?orders&padFragment=order-list" hx-trigger="every 5s"></code> swaps in the fresh list.</li> <li>An HTMX request needs no <code>padFragment</code> when it swaps an element named like the fragment: <code>hx-target="#order-list"</code> sends <code>HX-Target: order-list</code>, and a page with a fragment of that name answers it alone. A page without one renders whole, as it would otherwise. See {manual 'htmx'}.</li> </ul>
|
|
App: manual Page: pages/sequences
PHP
|
HTML
pages/sequences.pad
|
Result
|
|
{meta title='Sequences'}
<p>The <code>{sequence}</code> tag generates values instead of reading them: a range, a mathematical series, letters - 122 types, each iterated like any data tag:</p>
{example 'fragments/sequences_1'}
<p>That is the smallest corner of a whole subsystem: plays that keep, remove or flag terms, stores that pass a sequence from one tag to the next, actions that transform it, and random draws with their own rules. It has an application of its own, which is its manual:</p>
<p><b><a href="{$padHost}sequence/">The sequence application</a></b> - every type, play, action and option, demonstrated live.</p> <h2>Seeing and hearing them</h2>
<p>A sequence is data like any other, so {tag 'chart'} and {tag 'sparkline'} draw it straight away with <code>sequence=</code>:</p>
{example 'fragments/sequences_2'}
<p>The sequence application has three pages built on that: the <a href="{$padHost}sequence/?gallery">Gallery</a> draws every type beside the OEIS entry its terms come from, <a href="{$padHost}sequence/?listen">Listen</a> plays a sequence as notes - Recamán's is the famous one - in an audio file written into the page, and <a href="{$padHost}sequence/?guess">Guess</a> shows the start of a sequence and asks for the next term.</p>
|
|
App: manual Page: pages/stacks
PHP
|
HTML
pages/stacks.pad
|
Result
|
|
{meta title='Stacks: push and stack'}
<p>A component knows which script or stylesheet it needs; the layout knows where those belong. <code>{push 'name'}</code> adds rendered text to a named stack where the component is used, and <code>{stack 'name'}</code> prints the stack - in the <code><head></code>, say, far above the components that fill it.</p>
{example 'fragments/stacks_1'}
<h2>Filled in at the end</h2>
<p>A page renders from top to bottom, so a <code>{stack}</code> in the head comes out before anything below it has pushed. It prints a marker instead, and the marker is replaced by the stack once the whole page has rendered: it gets every push of the page, made above it or below it, in the order they were made.</p>
<h2>once</h2>
<ul> <li><code>once='chart'</code> - the first push of that key is kept and a later one is skipped before its content renders, so a component used fifty times renders its script tag once. Keys are per stack.</li> <li><code>once</code> without a key - a push whose rendered text the stack already holds is dropped.</li> </ul>
<h2>Where pushes come from</h2>
<ul> <li>The content of a push renders where the tag stands, with the variables of that spot - inside a loop, the row's.</li> <li>A plain <code>{page}</code> or <code>{code}</code> pass adds to the page's stacks; a sandbox, clean or reset pass keeps its own.</li> <li>A push inside a <code>{cache}</code> section is stored with the section and made again on every hit.</li> <li>From PHP: <code>padStackPush ( 'scripts', $html, $once )</code>.</li> </ul>
|
|
App: manual Page: pages/walking
PHP
|
HTML
pages/walking.pad
|
Result
|
|
{block} <p> Normally all the occurences for a level are retrieved and placed in an internal table before the processing takes place.<br> When this table is processed PAD knows for example when it is handling the last Occurence.<br> The below example with the {tag 'sequence'} tag does do that: </p> {/block}
{page 'walk/1'}
{block} <p> But some PAD tags use the PAD construct 'walking', then the occurences are processed one by one.<br> The tags {tag 'while'} & {tag 'until'} are an example of this.<br> This 'walking' construct breaks those special pad tags like {tag 'last'} & {tag 'border'} that give information about a {tag 'tag'}<br> Also the 'Data Handling' options are broken since those work on the all occurences at once. </p> {/block}
{page 'walk/2'}
{block} <p> To solve above breaking, place the result of a walking tag into the Data Store, and use it as a own tag. </p> {/block}
{page 'walk/3'}
{usesFragment 'walk/_lib/lib'}
|
|
App: manual Page: walk/1
App: reference Page: index
PHP
|
HTML
index.pad
|
Result
|
|
<blockquote>
{block}
{pad data='reference'}
{sequence '1..{$lvl}'} <blockquote> {/sequence}
<h3 id="{$type | slug}">{$type}</h3>
<blockquote>
{getReference '{$dir}', '{$xref}'}
{if $dir} <a href="?dir{?xref}{?type}{?item}">{$item}</a> {elseif $pages} <a href="?pages{?xref}{?type}{?item}">{$item}</a> @else@ {$item} {/if}
{/getReference} </blockquote>
{sequence '1..{$lvl}'} </blockquote> {/sequence}
{/pad}
{/block}
</blockquote>
|
|
|