1 | <?php namespace Arcanedev\LaravelHtml; |
||
13 | class HtmlBuilder extends Builder implements HtmlBuilderInterface |
||
14 | { |
||
15 | /* ------------------------------------------------------------------------------------------------ |
||
16 | | Properties |
||
17 | | ------------------------------------------------------------------------------------------------ |
||
18 | */ |
||
19 | /** |
||
20 | * The URL generator instance. |
||
21 | * |
||
22 | * @var \Illuminate\Contracts\Routing\UrlGenerator |
||
23 | */ |
||
24 | protected $url; |
||
25 | |||
26 | /* ------------------------------------------------------------------------------------------------ |
||
27 | | Constructor |
||
28 | | ------------------------------------------------------------------------------------------------ |
||
29 | */ |
||
30 | /** |
||
31 | * Create a new HTML builder instance. |
||
32 | * |
||
33 | * @param \Illuminate\Contracts\Routing\UrlGenerator $url |
||
34 | */ |
||
35 | 1096 | public function __construct(UrlGenerator $url = null) |
|
39 | |||
40 | /* ------------------------------------------------------------------------------------------------ |
||
41 | | Main Functions |
||
42 | | ------------------------------------------------------------------------------------------------ |
||
43 | */ |
||
44 | /** |
||
45 | * Convert an HTML string to entities. |
||
46 | * |
||
47 | * @param string $value |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | 102 | public function entities($value) |
|
55 | |||
56 | /** |
||
57 | * Convert entities to HTML characters. |
||
58 | * |
||
59 | * @param string $value |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | 16 | public function decode($value) |
|
67 | |||
68 | /** |
||
69 | * Generate a link to a JavaScript file. |
||
70 | * |
||
71 | * @param string $url |
||
72 | * @param array $attributes |
||
73 | * @param bool $secure |
||
74 | * |
||
75 | * @return \Illuminate\Support\HtmlString |
||
76 | */ |
||
77 | 16 | public function script($url, $attributes = [], $secure = null) |
|
85 | |||
86 | /** |
||
87 | * Generate a link to a CSS file. |
||
88 | * |
||
89 | * @param string $url |
||
90 | * @param array $attributes |
||
91 | * @param bool $secure |
||
92 | * |
||
93 | * @return \Illuminate\Support\HtmlString |
||
94 | */ |
||
95 | 16 | public function style($url, $attributes = [], $secure = null) |
|
108 | |||
109 | /** |
||
110 | * Generate an HTML image element. |
||
111 | * |
||
112 | * @param string $url |
||
113 | * @param string $alt |
||
114 | * @param array $attributes |
||
115 | * @param bool $secure |
||
116 | * |
||
117 | * @return \Illuminate\Support\HtmlString |
||
118 | */ |
||
119 | 16 | public function image($url, $alt = null, $attributes = [], $secure = null) |
|
127 | |||
128 | /** |
||
129 | * Generate a link to a Favicon file. |
||
130 | * |
||
131 | * @param string $url |
||
132 | * @param array $attributes |
||
133 | * @param bool $secure |
||
134 | * |
||
135 | * @return \Illuminate\Support\HtmlString |
||
136 | */ |
||
137 | 16 | public function favicon($url, $attributes = [], $secure = null) |
|
149 | |||
150 | /** |
||
151 | * Generate a HTML link. |
||
152 | * |
||
153 | * @param string $url |
||
154 | * @param string $title |
||
155 | * @param array $attributes |
||
156 | * @param bool $secure |
||
157 | * @param bool $escaped |
||
158 | * |
||
159 | * @return \Illuminate\Support\HtmlString |
||
160 | */ |
||
161 | 72 | public function link($url, $title = null, $attributes = [], $secure = null, $escaped = true) |
|
174 | |||
175 | /** |
||
176 | * Generate a HTTPS HTML link. |
||
177 | * |
||
178 | * @param string $url |
||
179 | * @param string $title |
||
180 | * @param array $attributes |
||
181 | * @param bool $escaped |
||
182 | * |
||
183 | * @return \Illuminate\Support\HtmlString |
||
184 | */ |
||
185 | 16 | public function secureLink($url, $title = null, $attributes = [], $escaped = true) |
|
189 | |||
190 | /** |
||
191 | * Generate a HTML link to an asset. |
||
192 | * |
||
193 | * @param string $url |
||
194 | * @param string $title |
||
195 | * @param array $attributes |
||
196 | * @param bool $secure |
||
197 | * |
||
198 | * @return \Illuminate\Support\HtmlString |
||
199 | */ |
||
200 | 24 | public function linkAsset($url, $title = null, $attributes = [], $secure = null) |
|
206 | |||
207 | /** |
||
208 | * Generate a HTTPS HTML link to an asset. |
||
209 | * |
||
210 | * @param string $url |
||
211 | * @param string $title |
||
212 | * @param array $attributes |
||
213 | * |
||
214 | * @return \Illuminate\Support\HtmlString |
||
215 | */ |
||
216 | 8 | public function linkSecureAsset($url, $title = null, $attributes = []) |
|
220 | |||
221 | /** |
||
222 | * Generate a HTML link to a named route. |
||
223 | * |
||
224 | * @param string $name |
||
225 | * @param string $title |
||
226 | * @param array $parameters |
||
227 | * @param array $attributes |
||
228 | * @param bool $escaped |
||
229 | * |
||
230 | * @return \Illuminate\Support\HtmlString |
||
231 | */ |
||
232 | 8 | public function linkRoute($name, $title = null, $parameters = [], $attributes = [], $escaped = true) |
|
238 | |||
239 | /** |
||
240 | * Generate a HTML link to a controller action. |
||
241 | * |
||
242 | * @param string $action |
||
243 | * @param string $title |
||
244 | * @param array $parameters |
||
245 | * @param array $attributes |
||
246 | * @param bool $escaped |
||
247 | * |
||
248 | * @return \Illuminate\Support\HtmlString |
||
249 | */ |
||
250 | 8 | public function linkAction($action, $title = null, $parameters = [], $attributes = [], $escaped = true) |
|
256 | |||
257 | /** |
||
258 | * Generate a HTML link to an email address. |
||
259 | * |
||
260 | * @param string $email |
||
261 | * @param string $title |
||
262 | * @param array $attributes |
||
263 | * @param bool $escaped |
||
264 | * |
||
265 | * @return \Illuminate\Support\HtmlString |
||
266 | */ |
||
267 | 8 | public function mailto($email, $title = null, $attributes = [], $escaped = true) |
|
279 | |||
280 | /** |
||
281 | * Obfuscate an e-mail address to prevent spam-bots from sniffing it. |
||
282 | * |
||
283 | * @param string $email |
||
284 | * |
||
285 | * @return string |
||
286 | */ |
||
287 | 8 | public function email($email) |
|
291 | |||
292 | /** |
||
293 | * Generate an ordered list of items. |
||
294 | * |
||
295 | * @param array $list |
||
296 | * @param array $attributes |
||
297 | * |
||
298 | * @return \Illuminate\Support\HtmlString |
||
299 | */ |
||
300 | 16 | public function ol(array $list, array $attributes = []) |
|
306 | |||
307 | /** |
||
308 | * Generate an un-ordered list of items. |
||
309 | * |
||
310 | * @param array $list |
||
311 | * @param array $attributes |
||
312 | * |
||
313 | * @return \Illuminate\Support\HtmlString |
||
314 | */ |
||
315 | 16 | public function ul(array $list, array $attributes = []) |
|
321 | |||
322 | /** |
||
323 | * Generate a description list of items. |
||
324 | * |
||
325 | * @param array $list |
||
326 | * @param array $attributes |
||
327 | * |
||
328 | * @return \Illuminate\Support\HtmlString |
||
329 | */ |
||
330 | 24 | public function dl(array $list, array $attributes = []) |
|
331 | { |
||
332 | 24 | $attributes = $this->attributes($attributes); |
|
333 | 24 | ||
334 | 12 | $html = "<dl{$attributes}>"; |
|
335 | |||
336 | foreach ($list as $key => $value) { |
||
337 | $value = (array) $value; |
||
338 | $html .= "<dt>$key</dt>"; |
||
339 | |||
340 | foreach ($value as $vKey => $vValue) { |
||
341 | $html .= "<dd>$vValue</dd>"; |
||
342 | } |
||
343 | } |
||
344 | 856 | ||
345 | $html .= '</dl>'; |
||
346 | 856 | ||
347 | return $this->toHtmlString($html); |
||
348 | } |
||
349 | |||
350 | /** |
||
351 | * Generates non-breaking space entities based on a supplied multiplier. |
||
352 | * |
||
353 | * @param int $multiplier |
||
354 | * |
||
355 | * @return string |
||
356 | 16 | */ |
|
357 | public function nbsp($multiplier = 1) |
||
358 | 16 | { |
|
359 | return str_repeat(' ', $multiplier); |
||
360 | } |
||
361 | |||
362 | /** |
||
363 | * Build an HTML attribute string from an array. |
||
364 | * |
||
365 | * @param array $attributes |
||
366 | * |
||
367 | * @return string |
||
368 | */ |
||
369 | public function attributes(array $attributes) |
||
373 | 32 | ||
374 | 24 | /** |
|
375 | * Obfuscate a string to prevent spam-bots from sniffing it. |
||
376 | * |
||
377 | * @param string $value |
||
378 | * |
||
379 | * @return string |
||
380 | */ |
||
381 | public function obfuscate($value) |
||
385 | |||
386 | /** |
||
387 | * Generate a meta tag. |
||
388 | * |
||
389 | * @param string $name |
||
390 | * @param string $content |
||
391 | * @param array $attributes |
||
392 | * |
||
393 | * @return \Illuminate\Support\HtmlString |
||
394 | */ |
||
395 | public function meta($name, $content, array $attributes = []) |
||
401 | } |
||
402 |