-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
101 lines (92 loc) · 2.75 KB
/
bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* stefanwimmer128/html-builder - bootstrap.php
* @author Stefan Wimmer <[email protected]>
* @license ISC
* @copyright Copyright (c) 2020, Stefan Wimmer
*/
namespace Stefanwimmer128\HtmlBuilder;
use Stefanwimmer128\HtmlBuilder\Components\ElementList;
use Stefanwimmer128\HtmlBuilder\Parser\AbstractParser;
use Stefanwimmer128\HtmlBuilder\Utilities\HtmlBuilderUtility;
if (! function_exists(__NAMESPACE__ . '\h')) {
/**
* Create element from input using parser (default: Emmet)
* @param string $input
* @param mixed ...$args
* @return HtmlElement
* @package Stefanwimmer128\HtmlBuilder
*/
function h(string $input, ...$args): HtmlElement {
return AbstractParser::parse($input)->toElement(...$args);
}
}
if (! function_exists(__NAMESPACE__ . '\tag')) {
/**
* Create tag element
* @param string $tag
* @param mixed ...$args
* @return HtmlTag
* @package Stefanwimmer128\HtmlBuilder
*/
function tag(string $tag = 'div', ...$args): HtmlTag {
return new HtmlTag($tag, ...$args);
}
}
if (! function_exists(__NAMESPACE__ . '\text')) {
/**
* Create text element
* @param string $text
* @return HtmlText
* @package Stefanwimmer128\HtmlBuilder
*/
function text(string $text): HtmlText {
return new HtmlText($text);
}
}
if (! function_exists(__NAMESPACE__ . '\raw')) {
/**
* Create raw string
* @param string $value
* @return RawString
* @package Stefanwimmer128\HtmlBuilder
*/
function raw(string $value): RawString {
return new RawString($value);
}
}
if (! function_exists(__NAMESPACE__ . '\capture')) {
/**
* Captures output (echo) and returns it as raw string
* @param callable $callable
* @param mixed ...$args
* @return RawString
* @package Stefanwimmer128\HtmlBuilder
*/
function capture(callable $callable, ...$args): RawString {
return raw(HtmlBuilderUtility::capture($callable, ...$args));
}
}
if (! function_exists(__NAMESPACE__ . '\map')) {
/**
* array_map with keys
* @param array $array
* @param callable $callable
* @return array
* @package Stefanwimmer128\HtmlBuilder
*/
function map(array $array, callable $callable): array {
return HtmlBuilderUtility::map($array, $callable);
}
}
if (! function_exists(__NAMESPACE__ . '\render')) {
/**
* Render elements as HTML
* @param mixed ...$elements
* @return string
* @package Stefanwimmer128\HtmlBuilder
*/
function render(...$elements): string {
return (new ElementList($elements))->render();
}
}