diff --git a/HtmlBuilder.php b/HtmlBuilder.php
index 5929c97..d98f3c9 100644
--- a/HtmlBuilder.php
+++ b/HtmlBuilder.php
@@ -11,6 +11,13 @@ class HtmlBuilder {
*/
protected $url;
+ /**
+ * The registered html macros.
+ *
+ * @var array
+ */
+ protected $macros;
+
/**
* Create a new HTML builder instance.
*
@@ -22,6 +29,18 @@ class HtmlBuilder {
$this->url = $url;
}
+ /**
+ * Register a custom HTML macro.
+ *
+ * @param string $name
+ * @param callable $macro
+ * @return void
+ */
+ public function macro($name, $macro)
+ {
+ $this->macros[$name] = $macro;
+ }
+
/**
* Convert an HTML string to entities.
*
@@ -275,4 +294,21 @@ class HtmlBuilder {
if ( ! is_null($value)) return $key.'="'.e($value).'"';
}
+ /**
+ * Dynamically handle calls to the html class.
+ *
+ * @param string $method
+ * @param array $parameters
+ * @return mixed
+ */
+ public function __call($method, $parameters)
+ {
+ if (isset($this->macros[$method]))
+ {
+ return call_user_func_array($this->macros[$method], $parameters);
+ }
+
+ throw new \BadMethodCallException("Method {$method} does not exist.");
+ }
+
}