Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit b481f0f

Browse files
authored
Merge pull request #21 from 8fold/8fold-sites
incorporate Shoop more
2 parents b0da464 + dea83c2 commit b481f0f

File tree

14 files changed

+199
-179
lines changed

14 files changed

+199
-179
lines changed

.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ root = true
22

33
[*]
44
indent_style = tab
5+
indent_size = 4
56
end_of_line = lf
67
charset = utf-8
78
trim_trailing_whitespace = true
@@ -11,5 +12,6 @@ insert_final_newline = true
1112
indent_style = space
1213
indent_size = 4
1314

14-
[*.yml, *.js, *.json]
15+
[*{.js,.json,.scss}]
16+
indent_style = space
1517
indent_size = 2

composer.json

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
{
2-
"name": "8fold/php-markup",
3-
"description": "8fold Markup seeks to make writing semi-structured data easier while allowing for more dynamism.",
4-
"type": "library",
5-
"license": "MIT",
6-
"authors": [
7-
{
8-
"name": "Josh Bruce",
9-
"email": "[email protected]"
10-
}
11-
],
12-
"require": {
13-
"php": ">=7.0",
14-
"8fold/php-shoop": "0.3.*",
15-
"nesbot/carbon": "2.35.*",
16-
"league/commonmark": "1.4.*"
17-
},
18-
"require-dev": {
19-
"phpunit/phpunit": "9.1.*",
20-
"phpunit/php-code-coverage": "8.0.*"
21-
},
22-
"autoload": {
23-
"psr-4": {
24-
"Eightfold\\Markup\\": "./src/"
25-
}
26-
},
27-
"autoload-dev": {
28-
"psr-4": {
29-
"Eightfold\\Markup\\Tests\\": "./tests/"
30-
}
31-
},
32-
"config": {
33-
"preferred-install": "dist"
34-
},
2+
"name": "8fold/php-markup",
3+
"description": "8fold Markup seeks to make writing semi-structured data easier while allowing for more dynamism.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Josh Bruce",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": ">=7.0",
14+
"8fold/php-shoop": "0.4.*",
15+
"nesbot/carbon": "2.35.*",
16+
"league/commonmark": "1.4.*"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "9.1.*",
20+
"phpunit/php-code-coverage": "8.0.*"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"Eightfold\\Markup\\": "./src/"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Eightfold\\Markup\\Tests\\": "./tests/"
30+
}
31+
},
32+
"config": {
33+
"preferred-install": "dist"
34+
},
3535
"prefer-stable": true
3636
}

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Element.php

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class Element
1616

1717
protected $content;
1818

19-
protected $extends;
19+
// protected $extends;
2020

21-
protected $omitEndTag = false;
21+
protected $attributes;
2222

23-
protected $attributes = [];
23+
protected $omitEndTag = false;
2424

2525
static public function fold($element, ...$content)
2626
{
@@ -32,47 +32,53 @@ public function __construct($element, ...$content)
3232
$this->element = Type::sanitizeType($element, ESString::class)
3333
->replace(["_" => "-"]);
3434
$this->content = Type::sanitizeType($content, ESArray::class);
35+
$this->attributes = Shoop::dictionary([]);
3536
}
3637

3738
public function unfold()
3839
{
39-
return Shoop::string($this->compiledElement())->start("<")->plus(
40-
$this->compiledAttributes()
41-
)->end(">")->plus(
42-
$this->content->each(function($value) {
43-
if (is_string($value) || is_int($value)) {
44-
return (string) $value;
45-
46-
} elseif (is_a($value, Element::class) || is_subclass_of($value, Element::class)) {
47-
return $value->unfold();
48-
49-
}
50-
})->join("")
51-
)->plus(
52-
($this->omitEndTag) ? "" : Shoop::string($this->compiledElement())->start("</")->end(">")
53-
)->unfold();
40+
return Shoop::string($this->element)
41+
->start("<")->plus($this->compiledAttributes())->end(">")
42+
->plus($this->compiledContent())->plus(
43+
($this->omitEndTag)
44+
? ""
45+
: Shoop::string($this->element)->start("</")->end(">")
46+
)->unfold();
5447
}
5548

5649
public function attr(string ...$attributes): Element
5750
{
5851
if ($this->attributes === null) {
59-
$this->attributes = Shoop::array($attributes)->unfold();
52+
$this->attributes = Shoop::dictionary([]);
53+
}
6054

61-
} else {
62-
$current = $this->attributes;
63-
$new = $attributes;
64-
$merged = array_merge($current, $new);
65-
$unique = array_unique($merged);
66-
$this->attributes = Shoop::array($unique)->unfold();
55+
Shoop::array($attributes)->each(function($string) {
56+
list($attr, $value) = Shoop::string($string)
57+
->divide(" ", false, 2);
58+
$this->attributes = $this->attributes->plus($value, $attr);
59+
});
6760

68-
}
6961
return $this;
7062
}
7163

64+
protected function attributes(): ESArray
65+
{
66+
if ($this->attributes === null) {
67+
return Shoop::array([]);
68+
}
69+
return $this->attributes->each(function($value, $attr) {
70+
return "{$attr} {$value}";
71+
});
72+
}
73+
7274
public function extends($extends): Element
7375
{
7476
$extends = Type::sanitizeType($extends, ESString::class);
75-
$this->extends = $extends;
77+
$elem = $this->element;
78+
79+
$this->element = $extends;
80+
$this->attr("is {$elem}");
81+
7682
return $this;
7783
}
7884

@@ -84,26 +90,32 @@ public function omitEndTag(bool $omit = true): Element
8490

8591
protected function compiledElement()
8692
{
87-
$elem = $this->element;
88-
if (strlen($this->extends) > 0) {
89-
$elem = $this->extends;
90-
$this->attributes[] = "is {$this->element}";
91-
}
92-
return $elem;
93+
return $this->element;
9394
}
9495

9596
protected function compiledAttributes(): string
9697
{
97-
$compiled = Shoop::array($this->attributes)->each(function($attribute) {
98-
list($member, $value) = explode(" ", $attribute, 2);
99-
return ($member === $value && strlen($member) > 0)
100-
? $member : "{$member}=\"{$value}\"";
101-
});
98+
return $this->attributes->each(function($value, $attribute) {
99+
return ($attribute === $value && strlen($attribute) > 0)
100+
? $attribute : "{$attribute}=\"{$value}\"";
102101

103-
if ($compiled->int()->isGreaterThanUnfolded(0)) {
104-
return $compiled->join(" ")->start(" ");
105-
}
106-
return "";
102+
})->isEmpty(function($result, $array) {
103+
return ($result) ? "" : $array->join(" ")->start(" ");
104+
105+
});
106+
}
107+
108+
protected function compiledContent()
109+
{
110+
return $this->content->each(function($value) {
111+
if (is_string($value) || is_int($value)) {
112+
return (string) $value;
113+
114+
} elseif (is_a($value, Element::class) || is_subclass_of($value, Element::class)) {
115+
return $value->unfold();
116+
117+
}
118+
})->join("");
107119
}
108120

109121
public function __toString()

src/Html/Data/Attributes/Aria.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
namespace Eightfold\Markup\Html\Data\Attributes;
44

5-
/**
6-
* @version 1.0.0
7-
*
8-
* Aria attributes
9-
*/
105
abstract class Aria
116
{
127
static public function globals()

src/Html/Elements/Forms/Button.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111

1212
use Eightfold\Markup\Html\Data\Attributes\Content;
1313

14-
/**
15-
* @version 1.0.0
16-
*
17-
* Button
18-
*
19-
*
20-
*/
2114
class Button extends HtmlElement implements HtmlElementInterface
2215
{
2316
static public function elementName(): string

0 commit comments

Comments
 (0)