Skip to content

Commit

Permalink
Merge pull request #184 from lukeraymonddowning/2.x_parse
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Apr 12, 2024
2 parents c68f9e4 + cbf8f32 commit 9c030e6
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 11 deletions.
12 changes: 11 additions & 1 deletion src/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,24 @@ function style(string $name, ?Closure $callback = null): Style

if (! function_exists('Termwind\render')) {
/**
* Render HTML to a string.
* Render HTML to the terminal.
*/
function render(string $html, int $options = OutputInterface::OUTPUT_NORMAL): void
{
(new HtmlRenderer)->render($html, $options);
}
}

if (! function_exists('Termwind\parse')) {
/**
* Parse HTML to a string that can be rendered in the terminal.
*/
function parse(string $html): string
{
return (new HtmlRenderer)->parse($html)->toString();
}
}

if (! function_exists('Termwind\terminal')) {
/**
* Returns a Terminal instance.
Expand Down
10 changes: 0 additions & 10 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@
Styles::flush();
})->in(__DIR__);

/**
* Parses the given html to string.
*/
function parse(string $html): string
{
$html = (new HtmlRenderer)->parse($html);

return $html->toString();
}

/**
* Gets a input stream resource from a string.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/a.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse('<a>link text</a>');

Expand Down
2 changes: 2 additions & 0 deletions tests/br.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse('<br/>');

Expand Down
1 change: 1 addition & 0 deletions tests/classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Termwind\Exceptions\ColorNotFound;
use Termwind\Exceptions\InvalidStyle;
use function Termwind\parse;

test('font bold', function () {
$html = parse('<div class="font-bold">text</div>');
Expand Down
2 changes: 2 additions & 0 deletions tests/code.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse(<<<'HTML'
<div>
Expand Down
1 change: 1 addition & 0 deletions tests/colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Termwind\Exceptions\InvalidColor;

use function Termwind\parse;
use function Termwind\style;

it('allows the creation of colors', function () {
Expand Down
2 changes: 2 additions & 0 deletions tests/div.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse('<div>text</div>');

Expand Down
1 change: 1 addition & 0 deletions tests/dl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Termwind\Exceptions\InvalidChild;
use function Termwind\parse;

it('accepts multiple elements', function () {
$dl = parse(<<<'HTML'
Expand Down
2 changes: 2 additions & 0 deletions tests/em.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse('<em>text</em>');

Expand Down
2 changes: 2 additions & 0 deletions tests/hr.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
putenv('COLUMNS=10');

Expand Down
1 change: 1 addition & 0 deletions tests/mediaQueries.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Termwind\Actions\StyleToMethod;
use function Termwind\parse;

it('supports styling', function ($name) {
putenv('COLUMNS='.StyleToMethod::MEDIA_QUERY_BREAKPOINTS[$name]);
Expand Down
1 change: 1 addition & 0 deletions tests/ol.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Termwind\Exceptions\InvalidChild;
use function Termwind\parse;

it('renders the element', function () {
$html = parse('<ol><li>list text 1</li></ol>');
Expand Down
2 changes: 2 additions & 0 deletions tests/paragraph.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse('<p>text</p>');

Expand Down
2 changes: 2 additions & 0 deletions tests/pre.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$content = ' <h1>Introduction</h1>
Expand Down
1 change: 1 addition & 0 deletions tests/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use function Termwind\render;
use function Termwind\renderUsing;
use function Termwind\parse;

it('can render complex html', function () {
$html = parse(<<<'HTML'
Expand Down
2 changes: 2 additions & 0 deletions tests/s.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse('<s>text</s>');

Expand Down
2 changes: 2 additions & 0 deletions tests/span.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse('<span>text</span>');

Expand Down
2 changes: 2 additions & 0 deletions tests/strong.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse('<strong>text</strong>');

Expand Down
1 change: 1 addition & 0 deletions tests/style.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Termwind\Exceptions\StyleNotFound;

use function Termwind\parse;
use function Termwind\style;

it('allows the creation of styles', function () {
Expand Down
2 changes: 2 additions & 0 deletions tests/table.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('can render table without thead, tbody, tfoot to a string', function () {
$html = parse(<<<'HTML'
<table style="box">
Expand Down
2 changes: 2 additions & 0 deletions tests/u.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Termwind\parse;

it('renders the element', function () {
$html = parse('<u>text</u>');

Expand Down
1 change: 1 addition & 0 deletions tests/ul.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Termwind\Exceptions\InvalidChild;
use function Termwind\parse;

it('renders the element', function () {
$html = parse('<ul><li>list text 1</li></ul>');
Expand Down

0 comments on commit 9c030e6

Please sign in to comment.