Skip to content

Commit

Permalink
because of html refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mlantz committed Oct 15, 2021
1 parent 4f8f508 commit 870c75d
Show file tree
Hide file tree
Showing 16 changed files with 317 additions and 44 deletions.
6 changes: 3 additions & 3 deletions src/Html/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

class Button extends HtmlSnippet
{
public static function content($options = [])
public static function render($options = [])
{
$options['class'] = $options['class'] ?? config('forms.buttons.submit');

$attributes = self::attributes($options);
$attributes = self::attributes($options['attributes']);

$content = '';

Expand All @@ -20,6 +20,6 @@ public static function content($options = [])

throw_if(empty($content), 'You cannot have an empty button');

return "<button {$attributes}>{$content}</button>";
return "<button{$attributes}>{$content}</button>";
}
}
4 changes: 2 additions & 2 deletions src/Html/Div.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

class Div extends HtmlSnippet
{
public static function content($options = [])
public static function render($options = [])
{
$content = '';

$attributes = self::attributes($options);
$attributes = self::attributes($options['attributes']);

if (isset($options['content'])) {
$content = $options['content'];
Expand Down
2 changes: 1 addition & 1 deletion src/Html/DivClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class DivClose extends HtmlSnippet
{
public static function content($options = [])
public static function render($options = [])
{
return '</div>';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Html/DivOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class DivOpen extends HtmlSnippet
{
public static function content($options = [])
public static function render($options = [])
{
$attributes = self::attributes($options);
$attributes = self::attributes($options['attributes']);

return "<div{$attributes}>";
}
Expand Down
5 changes: 2 additions & 3 deletions src/Html/Heading.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

class Heading extends HtmlSnippet
{
public static function content($options = [])
public static function render($options = [])
{
$class = '';
$content = '';
$level = 3;

$attributes = self::attributes($options);
$attributes = self::attributes($options['attributes']);

if (isset($options['content'])) {
$content = $options['content'];
Expand Down
4 changes: 2 additions & 2 deletions src/Html/HoneyPot.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static function make($content = null, $name = null)
{
$options = [
'type' => 'html',
'content' => (string) self::content(),
'content' => null,
];

if (is_null($name)) {
Expand All @@ -21,7 +21,7 @@ public static function make($content = null, $name = null)
return (new HtmlConfigProcessor($name, $options));
}

public static function content($options = [])
public static function render($options = [])
{
return view('honeypot::honeypotFormFields');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Html/HrTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class HrTag extends HtmlSnippet
{
public static function content($options = [])
public static function render($options = [])
{
$attributes = self::attributes($options);
$attributes = self::attributes($options['attributes']);

return "<hr{$attributes}>";
}
Expand Down
17 changes: 9 additions & 8 deletions src/Html/HtmlSnippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class HtmlSnippet
{
public static $tag;

public static function getHtmlOptions()
{
return [
Expand All @@ -16,9 +18,9 @@ public static function getHtmlOptions()
];
}

public static function content($options = [])
public static function render($options = [])
{
return [];
return '';
}

public static function attributes($options = [])
Expand Down Expand Up @@ -59,21 +61,20 @@ public static function attributeElement($key, $value)

public static function make($content = null, $name = null)
{
if (is_array($content) || is_null($content)) {
$content = static::content($content);
}

throw_if(is_null($content), new Exception('Content cannot be null'));

if (is_null($name)) {
$name = 'html-snippet-' . Str::uuid();
}

$options = [
'instance' => new static(),
'type' => 'html',
'content' => $content,
];

if (is_array($content)) {
$options = array_merge($options, $content);
}

return (new HtmlConfigProcessor($name, $options));
}
}
6 changes: 3 additions & 3 deletions src/Html/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

class Link extends HtmlSnippet
{
public static function content($options = [])
public static function render($options = [])
{
$options['class'] = $options['class'] ?? config('forms.buttons.submit');

$attributes = self::attributes($options);
$attributes = self::attributes($options['attributes']);

$content = '';

Expand All @@ -18,6 +18,6 @@ public static function content($options = [])

throw_if(empty($content), 'You cannot have an empty button');

return "<a {$attributes}>{$content}</a>";
return "<a{$attributes}>{$content}</a>";
}
}
4 changes: 2 additions & 2 deletions src/Html/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

class Span extends HtmlSnippet
{
public static function content($options = [])
public static function render($options = [])
{
$content = '';

$attributes = self::attributes($options);
$attributes = self::attributes($options['attributes']);

if (isset($options['content'])) {
$content = $options['content'];
Expand Down
38 changes: 37 additions & 1 deletion src/Services/FieldConfigProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FieldConfigProcessor
public $wrapper;
public $table_class;
public $label_class;
public $instance;

public function __construct($name, $options)
{
Expand Down Expand Up @@ -79,7 +80,7 @@ public function __toString()
{
$config = $this->toArray();

return app(FieldMaker::class)->make($this->name, $config);
return app(FieldMaker::class)->make($this->name, $config, $this->instance);
}

public function required()
Expand Down Expand Up @@ -159,6 +160,34 @@ public function model($value)
return $this;
}

public function modelMethod($value)
{
$this->model_options['model_method'] = $value;

return $this;
}

public function modelParams($value)
{
$this->model_options['model_params'] = $value;

return $this;
}

public function modelValue($value)
{
$this->model_options['model_value'] = $value;

return $this;
}

public function modelLabel($value)
{
$this->model_options['model_label'] = $value;

return $this;
}

public function groupClass($value)
{
$this->wrapper = $value;
Expand Down Expand Up @@ -399,4 +428,11 @@ public function selectOptions($array)

return $this;
}

public function instance($value)
{
$this->instance = $value;

return $this;
}
}
2 changes: 1 addition & 1 deletion src/Services/FieldMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function make(string $column, array $columnConfig, $object = null)
->setLivewireOnKeydown($this->livewireOnKeydown);

if ($columnConfig['type'] === 'html') {
return $columnConfig['content'];
return $columnConfig['instance']::render($columnConfig);
}

$field = null;
Expand Down
Loading

0 comments on commit 870c75d

Please sign in to comment.