CSSClassNames
An API to support CSS class names., (*1)
Helper
<?php
namespace Brickrouge;
$class_names = [
'node-id' => 'node-id-13',
'node-slug' => 'node-slug-example',
'is-active' => true,
'is-disabled' => false
];
render_css_class($class_names)
// "node-id-13 node-slug-example is-active"
render_css_class($class_names, [ 'node-id', 'is-active', 'is-disabled' ]);
// "node-id-13 is-active"
render_css_class($class_names, 'node-id is-active is-disabled');
// "node-id-13 is-active"
render_css_class($class_names, [ '-node-id', '-node-slug' ]);
// "is-active"
render_css_class($class_names, '-node-id -node-slug');
// "is-active"
CSSClassNames and CSSClassNamesProperty
Classes that implements the CSSClassNames
interface might want to use the CSSClassNamesProperty
trait that provides support for the css_class
and css_class_names
magic properties., (*2)
<?php
namespace Icybee\Modules\Nodes;
use Brickrouge\CSSClassNames;
use Brickrouge\CSSClassNamesProperty;
// …
class Node extends ActiveRecord implements CSSClassNames
{
use CSSClassNamesProperty;
// …
/**
* Returns the CSS class names of the node.
*
* @return array[string]mixed
*/
protected function get_css_class_names()
{
$nid = $this->nid;
$slug = $this->slug;
return [
'type' => 'node',
'id' => $nid ? "node-{$nid}" : null,
'slug' => $slug ? "node-slug-{$slug}" : null,
'constructor' => 'constructor-' . \ICanBoogie\normalize($this->constructor)
];
}
}
An instance of such a Node
class could be used as follows:, (*3)
<?php
// …
$node->css_class;
// node node-123 node-slug-example constructor-nodes
$node->css_class_names;
// [ 'type' => node, 'id' => 'node-123', 'slug' => 'node-slug-example', 'constructor' => 'constructor-nodes' ]
$node->css_class('-slug -constructor');
// node node-123
$node->css_class('id slug');
// node-123 node-slug-example
Requirement
The package requires PHP 5.4 or later., (*4)
Installation
The recommended way to install this package is through Composer.
Create a composer.json
file and run php composer.phar install
command to install it:, (*5)
{
"minimum-stability": "dev",
"require":
{
"brickrouge/css-class-names": "*"
}
}
Cloning the repository
The package is available on GitHub, its repository can be
cloned with the following command line:, (*6)
$ git clone git://github.com/Brickrouge/CSSClassNames.git
Documentation
The documentation for the package and its dependencies can be generated with the make doc
command. The documentation is generated in the docs
directory using ApiGen.
The package directory can later by cleaned with the make clean
command., (*7)
Testing
The test suite is ran with the make test
command. Composer is
automatically installed as well as all the dependencies required to run the suite. The package
directory can later be cleaned with the make clean
command., (*8)
The package is continuously tested by Travis CI., (*9)
, (*10)
License
Brickrouge/CSSClassNames is licensed under the New BSD License - See the LICENSE file for details., (*11)