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

Commit 4925cc9

Browse files
committed
pre-release commit
1 parent 6a90c2d commit 4925cc9

File tree

4 files changed

+118
-11
lines changed

4 files changed

+118
-11
lines changed

README.md

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,115 @@
1-
# 8fold Markup
1+
# 8fold Markup for PHP
2+
3+
8fold Markup is NOT a new markup format akin to XML, HTML, YAML, and all the other MLs; instead, it is a library for generating most of those (XML and HTML) using PHP.
4+
5+
It uses a similar API found in [8fold Shoop](https://github.com/8fold/php-shoop) to create consistency across libraries.
6+
7+
## Installation
8+
9+
```
10+
composer require 8fold/php-markup
11+
```
12+
13+
## Usage
14+
15+
```php
16+
$element = Element::fold("hello");
17+
18+
print($lement->unfold());
19+
20+
// output: <hello></hello>
21+
```
22+
23+
You can also go straight to outputting a string.
24+
25+
```php
26+
$element = Element::fold("hello");
27+
28+
print($lement);
29+
30+
// output: <hello></hello>
31+
```
32+
33+
You can add attributes to the elements.
34+
35+
```php
36+
$element = Element::fold("hello")->attr("id my-element");
37+
38+
print($lement);
39+
40+
// output: <hello id="my-element"></hello>
41+
```
42+
43+
You can start with HTML, which is self-aware (understands and conforms to the w3c HTML specificaton).
44+
45+
If the HTML element is unknown, Markup will fall back to using Element.
46+
47+
```php
48+
$html = Html::p();
49+
50+
print($html->unfold());
51+
52+
print($html);
53+
```
54+
55+
There are two ways to create more compound elements (or components at this point). The first example uses `Html` while the second used `UIKit`.
56+
57+
If the `UIKit` component is unknown, it will fallback to `Html`.
58+
59+
```php
60+
$html = Html::ul(
61+
Html::li("Hello, "),
62+
Html::li("World!")
63+
);
64+
65+
print($html);
66+
67+
// output:
68+
// <ul><li>Hello, </li><li>World!</li></ul>
69+
70+
$uikit = UIKit::list(
71+
"Hello, ",
72+
"World!"
73+
);
74+
75+
print($uikit);
76+
77+
// output: same as above
78+
```
79+
80+
## Why?
281

382
When it comes to semi-sctructured data, XML and derivitives can be tedious and heavy on syntax. 8fold Markup makes outputing semf-sctructured data easier and allowing for more dynamism.
483

584
Markup minifies the output, making a smaller, faster package sent over the wire.
685

786
Markup prefers one I/O step to compile (unfold) the resulting plain text, which means there is no parsing of strings to arrive at the desired output.
887

9-
When it comes to HTML attributes will be consistently ordered and, if a given attribute is not a part of the W3C HTML5 specification or is deprecated for that element, it will automatically be removed; keeping your markup up to date without having to rewrite a bunch of HTML templates.
88+
When it comes to HTML, attributes will be consistently ordered and, if a given attribute is not a part of the W3C HTML5 specification or is deprecated for that element, it will automatically be removed; keeping your markup up to date without having to rewrite a bunch of HTML templates.
89+
90+
## Guiding Principles
91+
92+
Minimize I/O while maximizing flexibility and extensibility.
93+
94+
Standardize HTML output and allow users to set their own standards.
95+
96+
Simplify creation of complex but typical complex elements (UIKit).
97+
98+
## Governance
99+
100+
- Higher the number, higher the priority (labels on issues).
101+
- Benevolant Dictatorship for now.
102+
103+
## Contibuting
104+
105+
Anyone can submit PRs to add funcationality as we are only adding things we need for the solutions we are developing.
106+
107+
Each PR will be reviewed, including those submitted by core developers (no direct push).
108+
109+
## History
10110

11-
There are three possible entry points, all with in the Eightfold\Markup namespace:
111+
This library started as three (or more) separate libraries, each at varying degrees of stability.
12112

13-
1. Element: Allows you to generate any XML-based element you like with or without content.
14-
2. Html: Allows you to create HTML documents and elements with filtered and ordered attributes. (If an element is not found, it will fall back to Element.)
15-
3. UIKit: Simplifies construction and extension of Element and Html.
113+
`Element` was at 3.0.1; `Html` was also at 3.0.1; `UIKit` was never previously released to the public.
16114

17-
Please view the various test files to see the expected operations.
115+
This library replaces those three; deprecating them in the process. (The sunsetting period for the other libraries and projects will end on or after January 1st 2021.)

composer.lock

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

src/Element.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,9 @@ public function omitEndTag(bool $omit = true): Element
112112
$this->omitEndTag = $omit;
113113
return $this;
114114
}
115+
116+
public function __toString()
117+
{
118+
return $this->unfold();
119+
}
115120
}

tests/element/ElementTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class ElementTest extends TestCase
1313
public function testHtmlComponent()
1414
{
1515
$expected = '<html></html>';
16+
17+
$result = Element::fold("html");
18+
$this->assertEquals($expected, $result);
19+
1620
$result = Element::fold("html")->unfold('id my-component');
1721
$this->assertEquals($expected, $result);
1822

0 commit comments

Comments
 (0)