Exemple #1
0
 public function test_render_deeply_nested_arrays_of_children()
 {
     $expected = '<nonsense>catmousewolfsheepchickenrooster</nonsense>';
     $actual = capture(function ($stream) {
         render($stream, html('nonsense', ['cat', 'mouse', ['wolf', 'sheep', ['chicken', 'rooster']]]));
     });
     $this->assertSame($expected, $actual['stdout']);
 }
Exemple #2
0
 public function test_html_expects_raw_output_from_capture()
 {
     $expected = "<p>i <3 honey bees</p>";
     $actual = (string) html('p', capture(function () {
         print 'i <3 honey bees';
     }));
     $this->assertSame($expected, $actual);
 }
Exemple #3
0
 public function test_html_zen_element_with_id_and_classes_and_children()
 {
     $expected = '<div id="modal" class="alert alert-warning">giftofhoney</div>';
     $actual = (string) html('div#modal.alert.alert-warning', 'gift', 'of', 'honey');
     $this->assertSame($expected, $actual);
 }
Exemple #4
0
<?php

use function htmlgen\html as h;
// notice "&" will automatically be converted to "&amp;"
// this behavior protects you from malicious user input
return h('p', 'Thanks for your interest in cats & donuts and stuff !');
Exemple #5
0
<?php

use function htmlgen\html as h;
use function htmlgen\map;
use function htmlgen\raw;
$beeData = ['pop' => 'yup', 'candy' => 'sometimes', 'flowers' => 'so much', 'water' => 'not really', 'sand' => 'indifferent', 'donuts' => 'most definitely'];
return [h('h1', 'Hello from HtmlGgen'), h('comment', 'really cool and thought-provoking article'), h('article', h('h2', 'All about honey'), h('img', ['src' => '/busybeehive.png', 'alt' => 'bees like to keep busy!', 'width' => 300, 'height' => 100]), h('p', 'Did you know that bees are responsible for making honey ?'), h('p', 'It\'s a wonder more people don\'t like bees !'), h('p', 'Bees are > htmlentities'), h('p', raw('Raw honey is the <strong>best</strong>')), h('table', h('thead', h('tr', h('td', 'item'), h('td', 'do bees like it?'))), h('tbody', map($beeData, function ($value, $key) {
    return h('tr', h('td', $key), h('td', $value));
}))), h('aside', 'Did you know that queen bees come from larvae that are overfed with royal jelly ?')), h('comment', 'newsletter signup form'), h('form', ['action' => '#subscribe'], h('input', ['name' => 'email', 'autofocus']), h('input', ['type' => 'button', 'value' => 'Get Bee News !']))];
Exemple #6
0
<?php

require '../htmlgen.php';
require './htmlgen.extensions.php';
use function htmlgen\html as h;
use function htmlgen\render;
render(STDOUT, h('doctype'), h('html', ['lang' => 'en'], h('head', h('meta', ['charset' => 'utf-8']), h('meta', ['http-equiv' => 'X-UA-Compatible', 'content' => 'IE=edge']), h('meta', ['name' => 'viewport', 'content' => 'width=device-width, initial-scale=1']), h('link', ['rel' => 'stylesheet', 'type' => 'text/css', 'href' => '/main.css']), h('condition', 'lt IE 9', h('script', ['src' => 'ie.js']))), h('body', h('header', require './navigation.php'), h('main', require './body.php'), h('footer', require './footer.php'), h('script', ['src' => '/main.js']))));
Exemple #7
0
<?php

use function htmlgen\html as h;
use function htmlgen\map;
$links = ['home' => '/', 'cats' => '/cats', 'milk' => '/milk', 'honey' => '/honey', 'donuts' => '/donuts', 'bees' => '/bees'];
return h('nav', h('ul', map($links, function ($href, $text) {
    return h('li', h('a', ['href' => $href], $text));
})));