Completed
Push — master ( 195b94...858be2 )
by Mohamed
07:34
created

HtmlBuilder::trim()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Extensions\Html;
13
14
use GrahamCampbell\Markdown\Facades\Markdown;
15
16
/**
17
 * HtmlBuilder is a class to extend Laravel HtmlBuilder to add extra view macro.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
class HtmlBuilder extends \Illuminate\Html\HtmlBuilder
22
{
23
    use Traits\BlueBoxTrait,
24
        Traits\TabTrait,
25
        Traits\DateTimeTrait;
26
27
    /**
28
     * Limit the number of characters in a string, & remove <p> tag.
29
     *
30
     * @param string $content
31
     * @param int    $size
32
     *
33
     * @return string
34
     */
35 2
    public function trim($content, $size = 60)
36
    {
37 2
        return str_replace(['<p>', '</p>'], '', str_limit($content, $size));
38
    }
39
40
    /**
41
     * Format Markdown to Html.
42
     *
43
     * @param string $content
44
     *
45
     * @return string
46
     */
47 24
    public function format($content)
48
    {
49 24
        return Markdown::convertToHtml($this->filterIssueNo($content));
50
    }
51
52
    /**
53
     * Format issue number in string into a url to the issue.
54
     *
55
     * @param string $content
56
     *
57
     * @return string
58
     */
59 24
    public function filterIssueNo($content)
60
    {
61 24
        $link = $this->link('/project/issue/$3', '$1 #$3', ['title' => '$1 #$3', 'class' => 'issue-link']);
62
63 24
        return preg_replace('/((?:' . trans('tinyissue.issue') . ')?)(\s*)#(\d+)/i', $link, $content);
64
    }
65
66
    /**
67
     * Render loading Html.
68
     *
69
     * @param string $message
70
     *
71
     * @return string
72
     */
73
    public function loader($message)
74
    {
75
        return '<div class="loader">'
76
                . $this->image(\URL::asset('images/icons/loader.gif'))
77
                . '<span>' . trans('tinyissue.' . $message) . '</span>'
78
                . '</div>';
79
    }
80
81
    /**
82
     * Format issue tag in string into Html.
83
     *
84
     * @param string      $tag
85
     * @param string|null $group
86
     *
87
     * @return string
88
     */
89 16
    public function formatIssueTag($tag, $group = null)
90
    {
91 16
        if (null === $group && strpos($tag, ':') !== false) {
92
            list(, $tag) = explode(':', $tag);
93
        }
94
95 16
        return '<span class="issue-tag"><span class="title">' . $tag . '</span></span>';
96
    }
97
}
98