<commit_before>Aura View
=========

The Aura View package is an implementation of the [TemplateView](http://martinfowler.com/eaaCatalog/templateView.html) pattern, with support for helpers and path stacks.  It adheres to the "use PHP for presentation logic" ideology, and is preceded by systems such as [Savant](http://phpsavant.com), [Zend_View](http://framework.zend.com/manual/en/zend.view.html), and [Solar_View](http://solarphp.com/class/Solar_View).


Basic Usage
===========

Instantiation
-------------

The easiest way to instantiate a new `Template` with all the associated helpers is to include the `instance.php` script.

    <?php
    $template = require '/path/to/Aura.View/scripts/instance.php';

Then use the `Template` object to `fetch()` the output of a template script.

    <?php
    echo $template->fetch('/path/to/tpl.php');

Alternatively, we can add the `Aura.View` package to an autoloader, and instantiate manually:

    <?php
    use Aura\View\Template;
    use Aura\View\TemplateFinder;
    use Aura\View\HelperLocator;
    $template = new Template(new TemplateFinder, new HelperLocator);

(Note that if we instantiate manually, we will need to configure the `HelperLocator` manually to add helper services. See the "Helpers" section near the end of this page for more information.)


Assigning Data
--------------

We can assign variables to the template script by setting properties on the `Template` object, like so:

    <?php
    // business logic
    $template->var = 'World';

We can then reference those properties from within the template script using `$this`:

    <?php
    // template script
    $e = $this->getHelper('escape');
    echo $e($this->var);

We can add multiple data properties at once, merging new values with existing ones, by using `addData()`.

    <?php
    // business logic
    $template->addData([
        'foo' => 'Value of foo',
        'bar' => 'Value of bar',
    ]);

(Note that the array keys will map to object properties, so make sure they are valid as property names.)

Finally, we can replace all the `Template` data values at once using `setData()`.

    <?php
    // business logic
    // this will remove $var, $foo, and $bar from the template
    $template->setData([
        'baz' => 'Value of baz',
        'dib' => 'Value of dib',
    ]);


Writing Template Scripts
------------------------

Aura View template scripts are written in plain PHP and do not require a new markup language.  The template scripts are executed inside the `Template` object scope, so use of `$this` refers to the `Template` object.  The following is an example script:

    <?php $e = $this->getHelper('escape'); ?>
    <html>
    <head>
        <title><?php echo $e($this->title) ?></title>
    </head>
    <body>
        <p><?php
            echo "Hello " . $e($this->var) . '!';
        ?></p>
    </body>
    </html>

We can use any PHP code we would normally use. (This may require discipline on the part of the template script author to restrict himself to presentation-related logic only.)  We may wish to use the alternative PHP syntax for conditionals and loops:

    <?php if ($this->message): ?>
        <p>The message is <?php echo $e($this->message); ?></p>
    <?php endif; ?>
    
    <ul>
    <?php foreach ($this->list as $item): ?>
        <li><?php echo $e($item); ?></li>
    <?php endforeach; ?>
    </ul>


Using Helpers
-------------

Aura View comes with various `Helper` classes to encapsulate common presentation logic.  These helpers are mapped to the `Template` object through a `HelperLocator`. We can call a helper in one of two ways:

- As a method on the `Template` object

- Via `getHelper()` to get the helper as an object of its own

The single-most important helper is `$this->escape()`. We should use it every time we need to echo or print assigned variables.  (All of the other helpers apply escaping automatically.)  You can call it like so:

    <?php
    // template script
    echo $this->escape($this->var);

Or like so:

    <?php
    // template script
    $e = $this->getHelper('escape');
    echo $e($this->var);

Other helpers that are part of Aura View include:

- `$this->anchor($href, $text)` returns an `<a href="$href">$text</a>` tag

- `$this->attribs($list)` returns a space-separated attribute list from a `$list` key-value pair

- `$this->base($href)` returns a `<base href="$href" />` tag

- `$this->datetime($datestr, $format)` returns a formatted datetime string.

- `$this->image($src)` returns an `<img src="$src" />` tag.

- `$this->metas()` provides an object with methods that add to, and then retrieve, a series of `<meta ... />` tags.

    - `$this->metas()->addHttp($http_equiv, $content)` adds an HTTP-equivalent meta tag to the helper.
    
    - `$this->metas()->addName($name, $content)` adds a meta-name tags to the helper.
    
    - `$this-metas()->get()` returns all the added tags from the helper.

- `$this->scripts()` provides an object with methods that add to, and then retrieve, a series of `<script ... ></script>` tags.

    - `$this->scripts()->add($src)` adds a script tag to the helper.<commit_msg>update readme with new api calls<commit_after>Aura View
=========

The Aura View package is an implementation of the [TemplateView](http://martinfowler.com/eaaCatalog/templateView.html) pattern, with support for helpers and path stacks.  It adheres to the "use PHP for presentation logic" ideology, and is preceded by systems such as [Savant](http://phpsavant.com), [Zend_View](http://framework.zend.com/manual/en/zend.view.html), and [Solar_View](http://solarphp.com/class/Solar_View).


Basic Usage
===========

Instantiation
-------------

The easiest way to instantiate a new `Template` with all the associated helpers is to include the `instance.php` script.

    <?php
    $template = require '/path/to/Aura.View/scripts/instance.php';

Then use the `Template` object to `fetch()` the output of a template script.

    <?php
    echo $template->fetch('/path/to/tpl.php');

Alternatively, we can add the `Aura.View` package to an autoloader, and instantiate manually:

    <?php
    use Aura\View\Template;
    use Aura\View\TemplateFinder;
    use Aura\View\HelperLocator;
    $template = new Template(new TemplateFinder, new HelperLocator);

(Note that if we instantiate manually, we will need to configure the `HelperLocator` manually to add helper services. See the "Helpers" section near the end of this page for more information.)


Assigning Data
--------------

We can assign variables to the template script by setting properties on the `Template` object, like so:

    <?php
    // business logic
    $template->var = 'World';

We can then reference those properties from within the template script using `$this`:

    <?php
    // template script
    $e = $this->getHelper('escape');
    echo $e($this->var);

We can add multiple data properties at once, merging new values with existing ones, by using `addData()`.

    <?php
    // business logic
    $template->addData([
        'foo' => 'Value of foo',
        'bar' => 'Value of bar',
    ]);

(Note that the array keys will map to object properties, so make sure they are valid as property names.)

Finally, we can replace all the `Template` data values at once using `setData()`.

    <?php
    // business logic
    // this will remove $var, $foo, and $bar from the template
    $template->setData([
        'baz' => 'Value of baz',
        'dib' => 'Value of dib',
    ]);


Writing Template Scripts
------------------------

Aura View template scripts are written in plain PHP and do not require a new markup language.  The template scripts are executed inside the `Template` object scope, so use of `$this` refers to the `Template` object.  The following is an example script:

    <?php $e = $this->getHelper('escape'); ?>
    <html>
    <head>
        <title><?php echo $e($this->title) ?></title>
    </head>
    <body>
        <p><?php
            echo "Hello " . $e($this->var) . '!';
        ?></p>
    </body>
    </html>

We can use any PHP code we would normally use. (This may require discipline on the part of the template script author to restrict himself to presentation-related logic only.)  We may wish to use the alternative PHP syntax for conditionals and loops:

    <?php if ($this->message): ?>
        <p>The message is <?php echo $e($this->message); ?></p>
    <?php endif; ?>
    
    <ul>
    <?php foreach ($this->list as $item): ?>
        <li><?php echo $e($item); ?></li>
    <?php endforeach; ?>
    </ul>


Using Helpers
-------------

Aura View comes with various `Helper` classes to encapsulate common presentation logic.  These helpers are mapped to the `Template` object through a `HelperLocator`. We can call a helper in one of two ways:

- As a method on the `Template` object

- Via `getHelper()` to get the helper as an object of its own

The single-most important helper is `$this->escape()`. We should use it every time we need to echo or print assigned variables.  (All of the other helpers apply escaping automatically.)  You can call it like so:

    <?php
    // template script
    echo $this->escape($this->var);

Or like so:

    <?php
    // template script
    $e = $this->getHelper('escape');
    echo $e($this->var);

Other helpers that are part of Aura View include:

- `$this->anchor($href, $text)` returns an `<a href="$href">$text</a>` tag

- `$this->attribs($list)` returns a space-separated attribute list from a `$list` key-value pair

- `$this->base($href)` returns a `<base href="$href" />` tag

- `$this->datetime($datestr, $format)` returns a formatted datetime string.

- `$this->image($src)` returns an `<img src="$src" />` tag.

- `$this->metas()` provides an object with methods that add to, and then retrieve, a series of `<meta ... />` tags.

    - `$this->metas()->addHttp($http_equiv, $content)` adds an HTTP-equivalent meta tag to the helper.
    
    - `$this->metas()->addName($name, $content)` adds a meta-name tags to the helper.
    
    - `$this-metas()->get()` returns all the added tags from the helper.

- `$this->scripts()` provides an object with methods that add to, and then retrieve, a series of `<script ... ></script>` tags.

    - `$this->scripts()->add($src)` adds a script tag to the helper.
    
    - `$this->scripts()->addCond($exp, $src)` adds a script tag inside a conditional expression to the helper.
{'fraction_non_alphanumeric': 0.1421300297704792, 'fraction_numerical': 0.0, 'mean_word_length': 3.1606072712744706, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2692073', 'n_tokens_mistral': 3077, 'n_tokens_neox': 2993, 'n_words': 1251}