Skip to content

Commit ea5c623

Browse files
Removed: Unused file
Added: Comments on dockblock Updated: Readme file
1 parent 168a0a4 commit ea5c623

20 files changed

Lines changed: 809 additions & 813 deletions

comblock-html.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
/**
4+
* Plugin bootstrap file for Comblock HTML UI.
5+
*
46
* @link https://github.com/rosario-fiorella/wordpress-comblock-html/
57
* @since 1.0.0
68
* @package wordpress-comblock-html
@@ -9,10 +11,10 @@
911
* @wordpress-plugin
1012
* Plugin Name: Comblock HTML UI
1113
* Plugin URI: https://github.com/rosario-fiorella/wordpress-comblock-html/
12-
* Description: WordPress plugin that provides a service class to generate html
14+
* Description: WordPress plugin that provides a service class to generate HTML.
1315
* Version: 1.0.0
14-
* Requires at least: 6.0
15-
* Requires PHP: 7.4
16+
* Requires at least: 6.8
17+
* Requires PHP: 8.1
1618
* Author: Rosario Fiorella
1719
* Author URI: https://github.com/rosario-fiorella/
1820
* Text Domain: comblock-html
@@ -26,18 +28,14 @@
2628
die;
2729
}
2830

29-
if (defined('WP_CLI') && WP_CLI) {
30-
return;
31-
}
31+
try {
32+
require_once plugin_dir_path(__FILE__) . 'includes/class-comblock-html.php';
3233

33-
/**
34-
* @see https://semver.org
35-
*/
36-
define('COMBLOCK_HTML_VERSION', '1.0.0');
37-
define('COMBLOCK_HTML_DOMAIN', 'comblock-html');
38-
define('COMBLOCK_HTML_PLUGIN_FILE', __FILE__);
39-
40-
require_once plugin_dir_path(__FILE__) . 'includes/class-comblock-html.php';
41-
42-
$comblock_html = new Comblock_Html();
43-
$comblock_html->run();
34+
$comblock_html = new Comblock_Html();
35+
$comblock_html->run();
36+
} catch (Throwable $e) {
37+
add_action('admin_notices', function () use ($e) {
38+
$html = sprintf('<div class="notice notice-error is-dismissible"><p>%s</p></div>', esc_html($e->getMessage()));
39+
echo wp_kses_post($html);
40+
});
41+
}

includes/class-comblock-html-activator.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

includes/class-comblock-html-deactivator.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

includes/class-comblock-html-document.php

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,90 @@
11
<?php
22

33
/**
4+
* Manages the construction of the HTML document using Comblock_Html_Dom objects.
5+
*
46
* @package comblock-html
57
* @subpackage comblock-html/includes
68
*/
79
class Comblock_Html_Document
810
{
911
/**
12+
* The DOMDocument representing the entire HTML document.
13+
*
1014
* @since 1.0.0
1115
* @var DOMDocument $dom
1216
*/
1317
public DOMDocument $dom;
1418

1519
/**
20+
* Collection of Comblock_Html_Dom nodes to be inserted into the document.
21+
*
1622
* @since 1.0.0
1723
* @access protected
18-
* @var ArrayObject $schema
24+
* @var ArrayObject<int, Comblock_Html_Dom> $schema
1925
*/
2026
protected ArrayObject $schema;
2127

2228
/**
29+
* Initializes the instance with a new DOMDocument and an empty schema.
30+
*
2331
* @since 1.0.0
2432
*/
2533
public function __construct()
2634
{
2735
$this->dom = new DOMDocument();
28-
2936
$this->schema = new ArrayObject();
3037
}
3138

3239
/**
40+
* Adds a Comblock_Html_Dom node to the collection.
41+
*
3342
* @since 1.0.0
34-
* @param Comblock_Html_Dom $node
35-
* @return void
43+
* @param Comblock_Html_Dom $node The node to add to the schema.
3644
*/
3745
public function add(Comblock_Html_Dom $node): void
3846
{
3947
$this->schema->append($node);
4048
}
4149

4250
/**
51+
* Generates the HTML output by processing the node structure and returning the markup.
52+
*
4353
* @since 1.0.0
44-
* @return string
54+
* @return string The generated HTML markup.
4555
*/
4656
public function view(): string
4757
{
4858
$this->process($this->schema->getArrayCopy());
4959

50-
return $this->dom->saveHTML();
60+
return $this->dom->saveHTML() ?: '';
5161
}
5262

5363
/**
64+
* Recursive process that builds DOM nodes from the Comblock_Html_Dom node structure.
65+
*
5466
* @since 1.0.0
5567
* @access protected
56-
* @param Comblock_Html_Node[] $scheme
57-
* @param null|DOMElement $parent
58-
* @return void
68+
* @param Comblock_Html_Dom[] $scheme Array of nodes to process.
69+
* @param DOMElement|null $parent The parent DOM node where children will be appended. If null, appends to the root.
5970
*/
6071
protected function process(array $scheme = [], ?DOMElement $parent = null): void
6172
{
6273
foreach ($scheme as $node) {
63-
/**
64-
* @var Comblock_Html_Dom $node
65-
*/
66-
$node;
74+
/** @var Comblock_Html_Dom $node */
6775

68-
/**
69-
* @var DOMElement $element
70-
*/
76+
/** @var DOMElement $element Newly created DOM node */
7177
$element = $this->dom->createElement($node->get_tag(), $node->get_value());
78+
7279
foreach ($node->get_attributes() as $name => $value) {
7380
$element->setAttribute($name, $value);
7481
}
7582

7683
if ($parent) {
77-
/**
78-
* @var null|DOMElement $child
79-
*/
84+
/** @var DOMElement $child Newly appended child node */
8085
$child = $parent->appendChild($element);
8186
} else {
82-
/**
83-
* @var null|DOMElement $child
84-
*/
87+
/** @var DOMElement $child Newly appended child node */
8588
$child = $this->dom->appendChild($element);
8689
}
8790

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
11
<?php
22

33
/**
4+
* Represents a DOM element within the comblock-html system.
5+
*
46
* @since 1.0.0
57
* @package comblock-html
68
* @subpackage comblock-html/includes
9+
* @author Rosario Fiorella
710
*/
811
class Comblock_Html_Dom
912
{
10-
/**
11-
* @since 1.0.0
12-
*/
13-
use Comblock_Html_Attribute;
13+
use Comblock_Html_Attribute;
14+
use Comblock_Html_Content;
15+
use Comblock_Html_Children;
1416

15-
/**
16-
* @since 1.0.0
17-
*/
18-
use Comblock_Html_Content;
17+
/**
18+
* The HTML tag name for this DOM element.
19+
*
20+
* @since 1.0.0
21+
* @access protected
22+
* @var string
23+
*/
24+
protected string $tag = '';
1925

20-
/**
21-
* @since 1.0.0
22-
*/
23-
use Comblock_Html_Children;
26+
/**
27+
* Initializes the DOM element with a sanitized tag name.
28+
*
29+
* @since 1.0.0
30+
* @param string $tag The name of the HTML tag.
31+
*/
32+
public function __construct(string $tag)
33+
{
34+
$this->tag = sanitize_key($tag);
35+
}
2436

25-
/**
26-
* @since 1.0.0
27-
* @access protected
28-
* @var string $tag
29-
*/
30-
protected string $tag;
31-
32-
/**
33-
* @since 1.0.0
34-
* @param string $tag
35-
*/
36-
public function __construct(string $tag)
37-
{
38-
$this->tag = esc_html($tag);
39-
}
40-
41-
/**
42-
* @since 1.0.0
43-
* @return string
44-
*/
45-
public function get_tag(): string
46-
{
47-
return $this->tag;
48-
}
37+
/**
38+
* Retrieves the tag name of this DOM element.
39+
*
40+
* @since 1.0.0
41+
* @return string The HTML tag name.
42+
*/
43+
public function get_tag(): string
44+
{
45+
return $this->tag;
46+
}
4947
}

includes/class-comblock-html-enqueue.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)