brickrouge / css-class-names
An API to support CSS class names.
Installs: 2 211
Dependents: 5
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
README
An API to support CSS class names.
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.
<?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:
<?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.
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:
{ "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:
$ 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.
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.
The package is continuously tested by Travis CI.
License
Brickrouge/CSSClassNames is licensed under the New BSD License - See the LICENSE file for details.