2017 © Pedro Peláez
 

library html

helpers for html stuff

image

jnjxp/html

helpers for html stuff

  • Thursday, May 7, 2015
  • by jnj
  • Repository
  • 1 Watchers
  • 0 Stars
  • 34 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 20 Versions
  • 0 % Grown

The README.md

jnjxp/html : HTML Helpers

![Software License][ico-license] Latest version Build Status ![Coverage Status][ico-scrutinizer] Quality Score, (*1)

jnjxp\html is an extension of Aura.Html., (*2)

Installation

$ composer require jnjxp/html

Usage

Instantiate helper locator., (*3)

use Jnjxp\Html\Factory as HtmlFactory;

$helper = (new HtmlFactory())->newInstance();

// example calling the icon helper
$helper->icon('foo');
$helper->icon->__invoke('foo');
$helper('icon','foo');

Helpers

See the Aura.Html documentation (tag and input) for base functionality. - Breadcrumb - CacheBust - Icon - Links - Metas - Modal - Scripts - Styles - Title, (*4)

Helpers Usage

Create an HTML navigational breadcrumb, (*5)

$helper->breadcrumb(['id' => 'test']);  // (array) optional attributes

// add a single item to be escaped
$helper->breadcrumb()
    ->item('Home', '/', ['class' => 'foo']); // (title, uri, attributes)

// add several items to be escaped
$helper->breadcrumb()->items(
    [ // key as uri value as title or array of attributes with title as first key
        '/' => 'Home',
        '/foo' => [ 'Foo', 'class' => 'foo']
        'Bar' // numeric index, URI defaults to "#"
    ]
);

// add a single raw item not to be escaped
$helper->breadcrumb()->rawItem('<span>Home</span>', '/', ['class' => 'foo']);

// add several raw items not to be escaped
$helper->breadcrumb()->items(
    [
        '/' => '<span>Home</span>',
        '/foo' => ['Foo', 'class' => 'foo']
        'Bar'
    ]
);

Output Example:, (*6)


<nav aria-label="breadcrumb" role="navigation"> <ol id="test" itemscope class="breadcrumb" itemtype="http://schema.org/BreadcrumbList"> <li itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem"> <a href="/" itemprop="item"><span itemprop="name">Home</span></a> <meta itemprop="position" content="1" /> </li> <li class="foo" itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem"> <a href="/foo" itemprop="item"><span itemprop="name">Foo</span></a> <meta itemprop="position" content="2" /> </li> <li class="active" itemscope itemprop="itemListElement" itemtype="http://schema.org/ListItem"> <a href="#" itemprop="item"><span itemprop="name">Bar</span></a> <meta itemprop="position" content="3" /> </li> </ol> </nav>

CacheBust

Get a version suffixed file based on json manifest., (*7)

Example manifest (eg located at: /var/www/build/rev-manifest.json):, (*8)

{
  "assets/js/app.js": "assets/js/app-a9341845.js",
  "assets/css/style.css": "assets/css/style-ca20fa46.css"
}
// set path to public root
$helper->cacheBust->setPublic('/var/www');

// returns /build/assets/js/app-a9341845.js
$helper->cacheBust('assets/js/app.js', 'build/rev-manifest.json');

// can set a default manifest as well
$helper->cacheBust->setDefaultManifest('build/rev-manifest.json');
$helper->cacheBust('assets/js/app.js');

Icon

Create some markup suitable for styling as an icon (eg. glyphicons or fontawesome), (*9)

echo $helper->icon('edit');
echo $helper->icon('edit', 'Edit Entry');
echo $helper->icon('edit', true);

Outputs:, (*10)

<span class="icon icon-edit" aria-hidden="true"></span>

<span class="icon icon-edit" aria-hidden="true"></span> <span class="sr-only">Edit Entry</span>

<span class="icon icon-edit" aria-hidden="true"></span> <span class="sr-only">edit</span>

Links helper. (see Aura\Html\Helper\Links Documentation for core function), (*11)

$helper->links->icons();
echo $helper->links;

// can pass array to override defaults:
$icons = [
    'apple-touch-icon' => [
        'pattern' => '/assets/ico/apple-touch-icon-%sx%1$s.png',
        'sizes' => [144, 114, 72, 57]
    ],
    'icon' => [
        'pattern' => '/assets/ico/favicon-%sx%1$s.png',
        'sizes' => [192, 96, 32, 16],
        'attr' => ['type' => 'image/png']
    ]
];

$helper->links->icons($icons);

Outputs:, (*12)

<link rel="apple-touch-icon" sizes="144x144" href="/assets/ico/apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/assets/ico/apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/assets/ico/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="57x57" href="/assets/ico/apple-touch-icon-57x57.png" />
<link rel="icon" sizes="192x192" href="/assets/ico/favicon-192x192.png" type="image/png" />
<link rel="icon" sizes="96x96" href="/assets/ico/favicon-96x96.png" type="image/png" />
<link rel="icon" sizes="32x32" href="/assets/ico/favicon-32x32.png" type="image/png" />
<link rel="icon" sizes="16x16" href="/assets/ico/favicon-16x16.png" type="image/png" />

Metas

Add meta tags (see Aura\Html\Helper\Metas Documentation for core function), (*13)

$helper->metas()
    ->addProperty('foo', 'bar')
    ->addOpenGraphProperty('foo', 'bar')
    ->charset() // pass arg to override default
    ->compat() // pass arg to override default
    ->description('description here')
    ->loc() // pass arg to override default
    ->robots('noindex, follow') // no arg? defaults to 'index, follow'
    ->url('http://example.com')
    ->viewport() // pass arg to override default
    ->image('/image.png');

echo $helper->metas();

Outputs:, (*14)

<meta charset="UTF-8" />
<meta property="foo" content="bar" />
<meta property="og:foo" content="bar" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" property="og:description" content="description here" />
<meta property="og:locale" content="en_US" />
<meta name="robots" content="noindex, follow" />
<meta property="og:url" content="http://example.com" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="image" property="og:image" content="/image.png" />
<link rel="image_src" href="/image.png" />

Bootstrap Modal, (*15)

echo $helper->modal(['attr' => ['id' => 'test']])
    ->setTitle('Test Modal')
    ->setBody('Body Here')
    ->setFooter('Modal Footer')
    ->setButton('Launch', ['class' => 'btn-success']);

// Or...

echo $helper->modal(
    [
        'attr'   => ['id' => 'test'],
        'title'  => 'Test Modal',
        'body'   => 'Body Here',
        'footer' => 'Modal Footer',
        'button' => ['Launch', ['class' => 'btn-sucess']]
    ]
);

Outputs:, (*16)


<button class="btn-success" type="button" data-toggle="modal" data-target="#test"> Launch </button>

Scripts

Scripts helper, (*17)

$helper->scripts->bust()
    ->setPublic('/var/www/')
    ->setDefaultManifest('build/rev-manifest.json');

$helper->scripts->bust()->add('assets/js/app.js');

$helper->scripts->addInline('alert("foo")');
$helper->scripts->addEventListener('function(){alert("foo")}');

$helper->scripts->addEventListener(
    'alert(event.type)', // snippet
    'click', // event type
    'document.document.getElementById("test")', // target
    true // wrap snippet in function?
);

$helper->scripts->inlineCaptureStart();
echo 'alert("foo")';
$helper->scripts->captureEnd();


$helper->scripts->eventCaptureStart();
// can take same args as addEventListener
echo 'alert("foo")';
$helper->scripts->captureEnd();

echo $helper->scripts;

Outputs:, (*18)







Styles

Styles helper (see Aura\Html\Helper\Styles Documentation for core function), (*19)

$helper->styles->bust()
    ->setPublic('/var/www/')
    ->setDefaultManifest('build/rev-manifest.json');

$helper->styles->bust()->add('assets/css/style.css');

$helper->styles->addInline('.test{color:red;}');

$helper->styles->inlineCaptureStart();
echo ".test{color:red;}";
$helper->styles->captureEnd();

echo $helper->styles;

Outputs:, (*20)

    <link rel="stylesheet" href="/build/assets/css/style-ca20fa46.css" type="text/css" media="screen" />
    <style type="text/css" media="screen">.test{color:red;}</style>
    <style type="text/css" media="screen">.test{color:red;}</style>

Title

Title helper (see Aura\Html\Helper\Title Documentation for core function), (*21)

$helper->title
    ->set('Page Title')
    ->setSite('Site Title');

echo $helper->title;

Outputs:, (*22)

<title>Page Title</title>
<meta name="title" property="og:title" content="Page Title" />
<meta property="og:site_name" content="Site Title" />

The Versions

07/05 2015

dev-master

9999999-dev

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

07/05 2015

v0.2.17

0.2.17.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

07/05 2015

v0.2.16

0.2.16.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

05/05 2015

v0.2.15

0.2.15.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

05/05 2015

v0.2.14

0.2.14.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

05/05 2015

v0.2.13

0.2.13.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

05/05 2015

v0.2.12

0.2.12.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

05/05 2015

v0.2.11

0.2.11.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

04/05 2015

v0.2.10

0.2.10.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

04/05 2015

v0.2.9

0.2.9.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

The Development Requires

by jake johns

01/05 2015

v0.2.8

0.2.8.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns

29/04 2015

v0.2.7

0.2.7.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns

29/04 2015

v0.2.6

0.2.6.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns

29/04 2015

v0.2.5

0.2.5.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns

29/04 2015

v0.2.4

0.2.4.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns

29/04 2015

v0.2.3

0.2.3.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns

28/04 2015

v0.2.2

0.2.2.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns

28/04 2015

v0.2.1

0.2.1.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns

28/04 2015

v0.2.0

0.2.0.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns

15/04 2015

v0.1.0

0.1.0.0

helpers for html stuff

  Sources   Download

AGPL-3.0

The Requires

 

by jake johns