|
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? |
2 | 81 |
|
3 | 82 | 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.
|
4 | 83 |
|
5 | 84 | Markup minifies the output, making a smaller, faster package sent over the wire.
|
6 | 85 |
|
7 | 86 | 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.
|
8 | 87 |
|
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 |
10 | 110 |
|
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. |
12 | 112 |
|
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. |
16 | 114 |
|
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.) |
0 commit comments