Compare commits

..

No commits in common. "master" and "1.1.0" have entirely different histories.

19 changed files with 1814 additions and 1947 deletions

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2014 Matt Karl Copyright (c) 2013 Matt Karl
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

View File

@ -29,12 +29,6 @@ require 'vendor/autoload.php';
To create an HTML node, simply call global `html` method, passing in the tag name and then any attributes. To create an HTML node, simply call global `html` method, passing in the tag name and then any attributes.
```php ```php
// Enable the global use of html()
Canteen\HTML5\HTML5::useGlobal();
// Turn on autoloading if not using composer's autoloading
Canteen\HTML5\HTML5::autoload();
echo html('img src=home.jpg'); echo html('img src=home.jpg');
echo html('img', 'src=home.jpg'); echo html('img', 'src=home.jpg');
echo html('img', array('src'=>'home.jpg')); echo html('img', array('src'=>'home.jpg'));

View File

@ -10,4 +10,4 @@ docs.helpers=${docs.themedir}/path.js
git=git git=git
git.docs=gh-pages git.docs=gh-pages
git.master=master git.master=master
version=1.1.5 version=1.0.1

View File

@ -1,48 +1,31 @@
{ {
"name": "mibew/html5", "name": "canteen/html5",
"description" : "Create dynamic, valid HTML5 markup with a simple an intuitive PHP API", "description" : "Create dynamic, valid HTML5 markup with a simple an intuitive PHP API",
"version" : "1.1.5", "version" : "1.1.0",
"type": "library", "type": "library",
"keywords": [ "keywords": ["html5", "markup", "document", "html", "tags"],
"html5",
"markup",
"document",
"html",
"tags"
],
"license": "MIT", "license": "MIT",
"homepage" : "http://github.com/Mibew/CanteenHTML5", "homepage" : "http://github.com/Canteen/CanteenHTML5",
"time": "2021-07-09", "time": "2014-10-31",
"authors": [ "authors": [
{ {
"name": "Matt Karl", "name": "Matt Karl",
"email": "matt@mattkarl.com", "email": "matt@mattkarl.com",
"homepage": "http://github.com/bigtimebuddy" "homepage": "http://github.com/bigtimebuddy",
}, "role": "Developer"
{
"name": "Mibew Messenger project",
"homepage": "https://mibew.org/"
} }
], ],
"autoload": { "autoload": {
"psr-4": { "psr-4": {"Canteen\\HTML5\\": "src/"}
"Canteen\\HTML5\\": "src/"
},
"files": [
"src/HTML5.php"
]
}, },
"require": { "require": {
"php": ">=5.3.0" "php": ">=5.3.0"
}, },
"replace": {
"canteen/html5": "~1.1.4"
},
"minimum-stability": "dev", "minimum-stability": "dev",
"repositories": [ "repositories": [
{ {
"type": "vcs", "type": "vcs",
"url": "https://github.com/Mibew/CanteenHTML5" "url": "https://github.com/Canteen/CanteenHTML5"
} }
] ]
} }

View File

@ -17,7 +17,6 @@
// Add a link to the page // Add a link to the page
$link = html('a#google.external rel=external', 'Link', 'class="test something" target=blank rel=test'); $link = html('a#google.external rel=external', 'Link', 'class="test something" target=blank rel=test');
$link->href = 'http://google.com'; $link->href = 'http://google.com';
$link->onclick = "return confirm('Navigate away?');";
$link->appendTo($doc->body); $link->appendTo($doc->body);
// Create an unordered list for an array of items // Create an unordered list for an array of items
@ -53,3 +52,5 @@
// Output the result formatted nice with indents // Output the result formatted nice with indents
echo $doc; echo $doc;
?>

View File

@ -113,7 +113,7 @@ namespace Canteen\HTML5
// Match the name=value in the attributes string // Match the name=value in the attributes string
preg_match_all('/([a-z]+[a-z\-]*)\=("[^\"]*"|\'[^\']*\'|[^\s\"\']*)/',$str, $arr); preg_match_all('/([a-z]+[a-z\-]*)\=("[^\"]*"|\'[^\']*\'|[^\s\"\']*)/',$str, $arr);
foreach ($arr[1] as $i=>$name) foreach($arr[1] as $i=>$name)
{ {
$value = $arr[2][$i]; $value = $arr[2][$i];
@ -135,14 +135,10 @@ namespace Canteen\HTML5
public function __get($name) public function __get($name)
{ {
if (method_exists($this , $method =('get' . ucfirst($name)))) if (method_exists($this , $method =('get' . ucfirst($name))))
{
return $this->$method(); return $this->$method();
}
else else
{
throw new HTML5Error(HTML5Error::INVALID_GETTER, $name); throw new HTML5Error(HTML5Error::INVALID_GETTER, $name);
} }
}
/** /**
* General purpose setter for setting attribute->name and attribute->value * General purpose setter for setting attribute->name and attribute->value
@ -153,14 +149,10 @@ namespace Canteen\HTML5
public function __set($name, $value) public function __set($name, $value)
{ {
if (method_exists($this , $method =('set' . ucfirst($name)))) if (method_exists($this , $method =('set' . ucfirst($name))))
{
return $this->$method($value); return $this->$method($value);
}
else else
{
throw new HTML5Error(HTML5Error::INVALID_SETTER, $name); throw new HTML5Error(HTML5Error::INVALID_SETTER, $name);
} }
}
/** /**
* See if a property exists * See if a property exists
@ -174,3 +166,5 @@ namespace Canteen\HTML5
} }
} }
} }
?>

View File

@ -30,7 +30,9 @@ namespace Canteen\HTML5
*/ */
public function __toString() public function __toString()
{ {
return '<!-- ' . $this->_tag . ' -->'; return '<!-- '.$this->_tag.' -->';
} }
} }
} }
?>

View File

@ -70,7 +70,7 @@ namespace Canteen\HTML5
$this->body = html('body'); $this->body = html('body');
$this->title = html('title', $title); $this->title = html('title', $title);
$this->head->addChild(html('meta', 'charset=' . $charset)); $this->head->addChild(html('meta', 'charset='.$charset));
$this->head->addChild($this->title); $this->head->addChild($this->title);
$this->addChild($this->head); $this->addChild($this->head);
@ -86,9 +86,7 @@ namespace Canteen\HTML5
{ {
$result = $this->docType . parent::__toString(); $result = $this->docType . parent::__toString();
if ($this->beautify) if ($this->beautify)
{
$result = self::beautify($result); $result = self::beautify($result);
}
return $result; return $result;
} }
@ -115,3 +113,5 @@ namespace Canteen\HTML5
} }
} }
} }
?>

View File

@ -1,41 +0,0 @@
<?php
/**
* @module Canteen\HTML5
*/
namespace Canteen\HTML5
{
/**
* Represents a set of HTML tags without a wrapper.
* Do not initiate this class directly, use the `html()` function:
*
* $div = html('fragment');
*
* @class Fragment
* @extends NodeContainer
* @constructor
* @param {Node|Array} [children=null] The collection of children or single child
*/
class Fragment extends NodeContainer
{
public function __construct($children = null)
{
parent::__construct('fragment', $children, null);
}
/**
* Write to HTML
* @method __toString
* @return {String} The string representation of this HTML node
*/
public function __toString()
{
$buffer = '';
foreach ($this->getChildren() as $child)
{
$buffer .= $child->__toString();
}
return $buffer;
}
}
}

View File

@ -22,10 +22,7 @@ namespace Canteen\HTML5
spl_autoload_register(function($name) spl_autoload_register(function($name)
{ {
// Ignore class names not in the HTML5 namespace // Ignore class names not in the HTML5 namespace
if (!preg_match('/^Canteen\\\HTML5\\\/', $name)) if (!preg_match('/^Canteen\\\HTML5\\\/', $name)) return;
{
return;
}
// Remove the HTML5 namespace // Remove the HTML5 namespace
$name = preg_replace('/^Canteen\\\HTML5\\\/', '', $name); $name = preg_replace('/^Canteen\\\HTML5\\\/', '', $name);
@ -34,7 +31,7 @@ namespace Canteen\HTML5
$name = str_replace("\\", '/', $name); $name = str_replace("\\", '/', $name);
// Include the class relative to here // Include the class relative to here
include __DIR__ . '/' . $name . '.php'; include __DIR__.'/'.$name.'.php';
}); });
} }
@ -44,7 +41,7 @@ namespace Canteen\HTML5
*/ */
static public function useGlobal() static public function useGlobal()
{ {
include __DIR__ . '/html.php'; include __DIR__.'/html.php';
} }
} }
@ -112,11 +109,6 @@ namespace Canteen\HTML5
{ {
return new Text($childrenOrAttributes); return new Text($childrenOrAttributes);
} }
// Untagged container
else if ($tag == 'fragment')
{
return new Fragment($childrenOrAttributes);
}
// Check for task specification // Check for task specification
else if (isset(Specification::$TAGS[$tag])) else if (isset(Specification::$TAGS[$tag]))
{ {
@ -155,17 +147,15 @@ namespace Canteen\HTML5
new NodeContainer($tag, $childrenOrAttributes, $attributes); new NodeContainer($tag, $childrenOrAttributes, $attributes);
// Take the selectors convert them into id or class // Take the selectors convert them into id or class
foreach ($selectors[0] as $selector) foreach($selectors[0] as $selector)
{ {
switch ($selector[0]) switch($selector[0])
{ {
case '#' : case '#' :
$node->id = substr($selector, 1); $node->id = substr($selector, 1);
break; break;
case '.' : case '.' :
if ($node->class) { if ($node->class) $node->class .= ' ';
$node->class .= ' ';
}
$node->class .= substr($selector, 1); $node->class .= substr($selector, 1);
break; break;
} }

View File

@ -140,3 +140,5 @@ namespace Canteen\HTML5
} }
} }
} }
?>

View File

@ -12,12 +12,11 @@ namespace Canteen\HTML5
* echo html('br'); * echo html('br');
* *
* @class Node * @class Node
* @extends Proto
* @constructor * @constructor
* @param {String} [tag=null] The name of the tag * @param {String} [tag=null] The name of the tag
* @param {Array|String} [attributes=null] The collection of tag attributes * @param {Array|String} [attributes=null] The collection of tag attributes
*/ */
class Node extends Proto class Node
{ {
/** /**
* The string name of the tag * The string name of the tag
@ -134,18 +133,14 @@ namespace Canteen\HTML5
{ {
throw new HTML5Error(HTML5Error::EMPTY_ATTRIBUTE_NAME); throw new HTML5Error(HTML5Error::EMPTY_ATTRIBUTE_NAME);
} }
foreach ($this->_attributes as $i=>$attribute) foreach($this->_attributes as $i=>$attribute)
{ {
if ($attribute->name === $name) if ($attribute->name === $name)
{ {
if (!$this->isEmpty($value)) if (!$this->isEmpty($value))
{
$attribute->value = $value; $attribute->value = $value;
}
else else
{
unset($this->_attributes[$i]); unset($this->_attributes[$i]);
}
return $this; return $this;
} }
} }
@ -169,7 +164,7 @@ namespace Canteen\HTML5
{ {
throw new HTML5Error(HTML5Error::EMPTY_ATTRIBUTE_NAME); throw new HTML5Error(HTML5Error::EMPTY_ATTRIBUTE_NAME);
} }
foreach ($this->_attributes as $attribute) foreach($this->_attributes as $attribute)
{ {
if ($attribute->name === $name) if ($attribute->name === $name)
{ {
@ -190,7 +185,7 @@ namespace Canteen\HTML5
{ {
if (is_array($values)) if (is_array($values))
{ {
foreach ($values as $name=>$value) foreach($values as $name=>$value)
{ {
$this->setAttribute($name, $value); $this->setAttribute($name, $value);
} }
@ -241,7 +236,7 @@ namespace Canteen\HTML5
*/ */
public function getData($name) public function getData($name)
{ {
return $this->getAttribute('data-' . $name); return $this->getAttribute('data-'.$name);
} }
/** /**
@ -265,7 +260,7 @@ namespace Canteen\HTML5
{ {
$buffer = '<'; $buffer = '<';
$buffer .= $this->_tag; $buffer .= $this->_tag;
foreach ($this->_attributes as $attribute) foreach($this->_attributes as $attribute)
{ {
$buffer .= (string)$attribute; $buffer .= (string)$attribute;
} }
@ -341,3 +336,5 @@ namespace Canteen\HTML5
} }
} }
} }
?>

View File

@ -45,7 +45,7 @@ namespace Canteen\HTML5
} }
if (is_array($children)) if (is_array($children))
{ {
foreach ($children as $child) foreach($children as $child)
{ {
$this->addChild($child); $this->addChild($child);
} }
@ -83,7 +83,7 @@ namespace Canteen\HTML5
{ {
array_unshift($this->_children, $childNode); array_unshift($this->_children, $childNode);
} }
else if ($index > (count($this->_children) - 1)) else if ($index > $len)
{ {
$this->addChild($childNode); $this->addChild($childNode);
} }
@ -141,7 +141,7 @@ namespace Canteen\HTML5
throw new HTML5Error(HTML5Error::EMPTY_CHILD); throw new HTML5Error(HTML5Error::EMPTY_CHILD);
} }
for ($i = 0; $i < count($this->_children); $i++) for($i = 0; $i < count($this->_children); $i++)
{ {
$child = $this->_children[$i]; $child = $this->_children[$i];
if ($child === $childNode) if ($child === $childNode)
@ -223,7 +223,7 @@ namespace Canteen\HTML5
public function __toString() public function __toString()
{ {
$buffer = $this->writeOpen(false); $buffer = $this->writeOpen(false);
foreach ($this->_children as $child) foreach($this->_children as $child)
{ {
$buffer .= $child->__toString(); $buffer .= $child->__toString();
} }
@ -233,3 +233,5 @@ namespace Canteen\HTML5
} }
} }
} }
?>

View File

@ -1,37 +0,0 @@
<?php
/**
* @module Canteen\HTML5
*/
namespace Canteen\HTML5
{
/**
* Prototype class for all Canteen\HTML5 entities
*
* @class Proto
* @constructor
* @param {String} text the plain text string
*/
class Proto
{
/**
* General purpose getter to get attribute values
* @method __get
* @param {String} name The name of the property to set
*/
public function __get($name)
{
return null;
}
/**
* See if a property exists
* @method __isset
* @param {String} name The name of the attribute
*/
public function __isset($name)
{
return null;
}
}
}

View File

@ -37,7 +37,7 @@ namespace Canteen\HTML5
{ {
assert(is_array($elements)); assert(is_array($elements));
foreach ($elements as $child) foreach($elements as $child)
{ {
$this->addChild($child); $this->addChild($child);
} }
@ -68,3 +68,5 @@ namespace Canteen\HTML5
} }
} }
} }
?>

View File

@ -58,9 +58,7 @@ namespace Canteen\HTML5
'target' 'target'
), ),
'bdo' => array(), 'bdo' => array(),
'blockquote' => array( 'blockquote' => array('cite'),
'cite'
),
'body' => array(), 'body' => array(),
'br' => array(), 'br' => array(),
'button' => array( 'button' => array(
@ -84,9 +82,7 @@ namespace Canteen\HTML5
'cite' => array(), 'cite' => array(),
'code' => array(), 'code' => array(),
'col' => null, 'col' => null,
'colgroup' => array( 'colgroup' => array('span'),
'span'
),
'command' => array( 'command' => array(
'checked', 'checked',
'disabled', 'disabled',
@ -141,9 +137,7 @@ namespace Canteen\HTML5
'header' => array(), 'header' => array(),
'hgroup' => array(), 'hgroup' => array(),
'hr' => array(), 'hr' => array(),
'html' => array( 'html' => array('manifest'),
'manifest'
),
'img' => array( 'img' => array(
'alt', 'alt',
'crossorigin', 'crossorigin',
@ -153,13 +147,6 @@ namespace Canteen\HTML5
'width' 'width'
), ),
'i' => array(), 'i' => array(),
'iframe' => array(
'src',
'srcdoc',
'name',
'width',
'height'
),
'input' => array( 'input' => array(
'accept', 'accept',
'alt', 'alt',
@ -213,9 +200,7 @@ namespace Canteen\HTML5
'sizes', 'sizes',
'type' 'type'
), ),
'map' => array( 'map' => array('name'),
'name'
),
'mark' => array(), 'mark' => array(),
'menu' => array(), 'menu' => array(),
'meta' => array( 'meta' => array(
@ -274,9 +259,7 @@ namespace Canteen\HTML5
'max', 'max',
'value' 'value'
), ),
'q' => array( 'q' => array('cite'),
'cite'
),
'rp' => array(), 'rp' => array(),
'rt' => array(), 'rt' => array(),
'ruby' => array(), 'ruby' => array(),
@ -300,22 +283,18 @@ namespace Canteen\HTML5
'size' 'size'
), ),
'small' => array(), 'small' => array(),
'source' => array( 'source' => array('media',
'media',
'src', 'src',
'type' 'type'
), ),
'span' => array(), 'span' => array(),
'strong' => array(), 'strong' => array(),
'style' => array( 'style' => array('media',
'media',
'scoped', 'scoped',
'type' 'type'
), ),
'sub' => array(), 'sub' => array(),
'table' => array( 'table' => array('border'),
'border'
),
'tbody' => array(), 'tbody' => array(),
'td' => array( 'td' => array(
'colspan', 'colspan',
@ -343,9 +322,7 @@ namespace Canteen\HTML5
'scope' 'scope'
), ),
'thead' => array(), 'thead' => array(),
'time' => array( 'time' => array('datetime'),
'datetime'
),
'title' => array(), 'title' => array(),
'tr' => array(), 'tr' => array(),
'track' => array( 'track' => array(

View File

@ -46,7 +46,7 @@ namespace Canteen\HTML5
$row->addChild(html('th', html('span', $checkbox))); $row->addChild(html('th', html('span', $checkbox)));
} }
foreach ($headers as $header) foreach($headers as $header)
{ {
$row->addChild(html('th', $header)); $row->addChild(html('th', $header));
} }
@ -55,7 +55,7 @@ namespace Canteen\HTML5
$body = html('tbody'); $body = html('tbody');
foreach ($data as $d) foreach($data as $d)
{ {
$row = html('tr'); $row = html('tr');
@ -64,19 +64,16 @@ namespace Canteen\HTML5
$td = html('td', $td = html('td',
html( html(
'input', 'input',
'type=checkbox name=' . $checkbox . '[] value='.$d[$checkbox] 'type=checkbox name='.$checkbox.'[] value='.$d[$checkbox]
), ),
'class=' . $checkbox 'class='.$checkbox
); );
$row->addChild($td); $row->addChild($td);
} }
foreach ($d as $name=>$value) foreach($d as $name=>$value)
{ {
if ($name == $checkbox) if ($name == $checkbox) continue;
{ $td = html('td', $value, 'class='.$name);
continue;
}
$td = html('td', $value, 'class=' . $name);
$row->addChild($td); $row->addChild($td);
} }
$body->addChild($row); $body->addChild($row);
@ -85,3 +82,5 @@ namespace Canteen\HTML5
} }
} }
} }
?>

View File

@ -35,3 +35,5 @@ namespace Canteen\HTML5
} }
} }
} }
?>