cnp/wp-atom-builder

Build filterable atomic elements.

v0.14 2016-09-09 18:12 UTC

This package is auto-updated.

Last update: 2024-11-15 02:48:44 UTC


README

##Atom Builder

The Atom class builds atomic markup from PHP arguments. For example, if you wanted this output:

<h2 class="section-title">A Section Title</h2>

You could use this PHP code to render it:

$section_title_args = [
  'tag' => 'h2',
  'content' => 'A Section Title'
];

$section_title = CNP\Atom::Assemble('section-title', $section_title_args);

echo $section_title;

Sure, this is slightly longer, but here's what is included in the Atom class:

###Filters

All the filters in the Atom class are namespaced to the name of the atom. An atom named 'section-title' would have an arguments filter named 'section-title_args'.

  1. $atom_name_args: filter the arguments array.
  2. $atom_name_classes: filter the classes array.
  3. $atom_name_id: filter the ID.
  4. $atom_name``$attribute_name_value: filter a specific attribute's value.
  5. $atom_name_attributes: filter the completed attributes array.
  6. $atom_name_content: filter the atom content.
  7. $atom_name_markup: filter the compiled markup.

Filtering the markup means that we can dynamically change the atom output on different areas of a site, without needing to change the atom arguments.

This also allows us to create generic blueprints that we can reuse from site-to-site, either adjusting arguments or filtering the atom where necessary.