Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #235. Rename attributes to properties. Rename methods #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/DetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
*/
final class DetailView extends Widget
{
private array $attributes = [];
private array $containerAttributes = [];
private array $properties = [];
private array $containerProperties = [];
private array|object $data = [];
private array $dataAttributes = [];
private array $fields = [];
Expand All @@ -46,7 +46,7 @@ final class DetailView extends Widget
private string $labelTag = 'dt';
private string $labelTemplate = '<{labelTag}{labelAttributes}>{label}</{labelTag}>';
private string $template = "<div{attributes}>\n{header}\n<dl{containerAttributes}>\n{items}\n</dl>\n</div>";
private array|Closure $valueAttributes = [];
private array|Closure $valueProperties = [];
private string $valueFalse = 'false';
private string $valueTag = 'dd';
private string $valueTemplate = '<{valueTag}{valueAttributes}>{value}</{valueTag}>';
Expand All @@ -57,10 +57,10 @@ final class DetailView extends Widget
*
* @param array $values Attribute values indexed by attribute names.
*/
public function attributes(array $values): self
public function properties(array $values): self
{
$new = clone $this;
$new->attributes = $values;
$new->properties = $values;

return $new;
}
Expand All @@ -70,10 +70,10 @@ public function attributes(array $values): self
*
* @param array $values Attribute values indexed by attribute names.
*/
public function containerAttributes(array $values): self
public function containerProperties(array $values): self
{
$new = clone $this;
$new->containerAttributes = $values;
$new->containerProperties = $values;

return $new;
}
Expand Down Expand Up @@ -208,10 +208,10 @@ public function template(string $value): self
*
* @param array $values Attribute values indexed by attribute names.
*/
public function valueAttributes(array $values): self
public function valueProperties(array $values): self
{
$new = clone $this;
$new->valueAttributes = $values;
$new->valueProperties = $values;

return $new;
}
Expand Down Expand Up @@ -281,8 +281,8 @@ public function render(): string
strtr(
$this->template,
[
'{attributes}' => Html::renderTagAttributes($this->attributes),
'{containerAttributes}' => Html::renderTagAttributes($this->containerAttributes),
'{attributes}' => Html::renderTagAttributes($this->properties),
'{containerAttributes}' => Html::renderTagAttributes($this->containerProperties),
Comment on lines -284 to +285
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong. These are HTML tag attributes.

@vjik which properties/attributes did you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. All HTML-related "attributes" must be keep.

Need to rename "attribute" that means "property of object": DataField::$attribute and related variables and methods.

'{dataAttributes}' => Html::renderTagAttributes($this->dataAttributes),
'{header}' => $this->header,
'{items}' => $this->renderItems(),
Expand Down Expand Up @@ -323,7 +323,7 @@ private function normalizeColumns(array $fields): array
$labelTag = $field->getLabelTag() === '' ? $this->labelTag : $field->getLabelTag();
$valueTag = $field->getValueTag() === '' ? $this->valueTag : $field->getValueTag();
$valueAttributes = $field->getValueAttributes() === []
? $this->valueAttributes : $field->getValueAttributes();
? $this->valueProperties : $field->getValueAttributes();

$normalized[] = [
'label' => Html::encode($field->getLabel()),
Expand Down
6 changes: 3 additions & 3 deletions tests/DetailView/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testAttributes(): void
</div>
HTML,
DetailView::widget()
->attributes(['class' => 'test-class'])
->properties(['class' => 'test-class'])
->fields(
DataField::create()->attribute('id'),
DataField::create()->attribute('username'),
Expand Down Expand Up @@ -91,7 +91,7 @@ public function testContainerAttributes(): void
DataField::create()->attribute('username'),
DataField::create()->attribute('total'),
)
->containerAttributes(['class' => 'test-class'])
->containerProperties(['class' => 'test-class'])
->data(['id' => 1, 'username' => 'tests 1', 'total' => '10'])
->render(),
);
Expand Down Expand Up @@ -299,7 +299,7 @@ public function testValueAttributes(): void
DataField::create()->attribute('total'),
)
->data(['id' => 1, 'username' => 'tests 1', 'total' => '10'])
->valueAttributes(['class' => 'test-value'])
->valueProperties(['class' => 'test-value'])
->render(),
);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/DetailView/Bootstrap5Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public function testRender(): void
</div>
HTML,
DetailView::widget()
->attributes(['class' => 'container'])
->properties(['class' => 'container'])
->fields(
DataField::create()->attribute('id')->label('Id'),
DataField::create()->attribute('login'),
DataField::create()->attribute('created_at')->label('Created At'),
)
->containerAttributes(['class' => 'row flex-column justify-content-center align-items-center'])
->containerProperties(['class' => 'row flex-column justify-content-center align-items-center'])
->data(
[
'id' => 1,
Expand All @@ -67,7 +67,7 @@ public function testRender(): void
H2::tag()->addClass('text-center')->content('<strong>Bootstrap 5</strong>')->encode(false)->render()
)
->labelAttributes(['class' => 'fw-bold'])
->valueAttributes(['class' => 'alert alert-info'])
->valueProperties(['class' => 'alert alert-info'])
->render(),
);
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public function testRenderWithTable(): void
</table>
HTML,
DetailView::widget()
->attributes(['class' => 'table table-success table-striped'])
->properties(['class' => 'table table-success table-striped'])
->fields(
DataField::create()->attribute('id')->label('Id'),
DataField::create()->attribute('login'),
Expand Down
6 changes: 3 additions & 3 deletions tests/DetailView/ImmutableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ final class ImmutableTest extends TestCase
public function testImmutable(): void
{
$detailView = DetailView::widget();
$this->assertNotSame($detailView, $detailView->attributes([]));
$this->assertNotSame($detailView, $detailView->properties([]));
$this->assertNotSame($detailView, $detailView->fields(DataField::create()));
$this->assertNotSame($detailView, $detailView->containerAttributes([]));
$this->assertNotSame($detailView, $detailView->containerProperties([]));
$this->assertNotSame($detailView, $detailView->data([]));
$this->assertNotSame($detailView, $detailView->dataAttributes([]));
$this->assertNotSame($detailView, $detailView->header(''));
Expand All @@ -37,7 +37,7 @@ public function testImmutable(): void
$this->assertNotSame($detailView, $detailView->labelTag(''));
$this->assertNotSame($detailView, $detailView->labelTemplate(''));
$this->assertNotSame($detailView, $detailView->template(''));
$this->assertNotSame($detailView, $detailView->valueAttributes([]));
$this->assertNotSame($detailView, $detailView->valueProperties([]));
$this->assertNotSame($detailView, $detailView->valueFalse(''));
$this->assertNotSame($detailView, $detailView->valueTag(''));
$this->assertNotSame($detailView, $detailView->valueTemplate(''));
Expand Down
Loading