Completed
Push — master ( acb1c9...dbdab7 )
by Cheren
03:07
created

AssetsHelper::materialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package   Core
10
 * @license   MIT
11
 * @copyright MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link      https://github.com/CakeCMS/Core".
13
 * @author    Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\View\Helper;
17
18
use JBZoo\Utils\Str;
19
20
/**
21
 * Class AssetsHelper
22
 *
23
 * @package Core\View\Helper
24
 * @property \Cake\View\Helper\UrlHelper $Url
25
 * @property \Core\View\Helper\HtmlHelper $Html
26
 */
27
class AssetsHelper extends AppHelper
28
{
29
30
    /**
31
     * Use helpers.
32
     *
33
     * @var array
34
     */
35
    public $helpers = [
36
        'Url'  => ['className' => 'Core.Url'],
37
        'Html' => ['className' => 'Core.Html'],
38
    ];
39
40
    /**
41
     * Default assets options.
42
     *
43
     * @var array
44
     */
45
    protected $_options = [
46
        'block'    => true,
47
        'fullBase' => true,
48
    ];
49
50
    /**
51
     * Include bootstrap.
52
     *
53
     * @return $this
54
     */
55 View Code Duplication
    public function bootstrap()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $this->jquery();
58
        $this->Html->script('libs/bootstrap.min.js', $this->_options);
59
        $this->Html->css('libs/bootstrap.min.css', $this->_options);
60
        return $this;
61
    }
62
63
    /**
64
     * Include fancybox.
65
     *
66
     * @return $this
67
     */
68 View Code Duplication
    public function fancyBox()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $this->jquery();
71
        $this->Html->script('libs/fancybox.min.js', $this->_options);
72
        $this->Html->css('libs/fancybox.min.css', $this->_options);
73
        return $this;
74
    }
75
76
    /**
77
     * Include font awesome.
78
     *
79
     * @return $this
80
     */
81
    public function fontAwesome()
82
    {
83
        $this->Html->css('libs/font-awesome.min.css', $this->_options);
84
        return $this;
85
    }
86
87
    /**
88
     * Include jquery lib.
89
     *
90
     * @return $this
91
     */
92
    public function jquery()
93
    {
94
        $this->Html->script('libs/jquery.min.js', $this->_options);
95
        return $this;
96
    }
97
98
    /**
99
     * Include jquery factory.
100
     *
101
     * @return $this
102
     */
103
    public function jqueryFactory()
104
    {
105
        $this->jquery();
106
        $this->Html->script(['libs/utils.min.js', 'libs/jquery-factory.min.js'], $this->_options);
107
        return $this;
108
    }
109
110
    /**
111
     * Include materialize design.
112
     *
113
     * @return $this
114
     */
115 View Code Duplication
    public function materialize()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        $this->jquery();
118
        $this->Html->script('libs/materialize.min.js', $this->_options);
119
        $this->Html->css('libs/materialize.min.css', $this->_options);
120
        return $this;
121
    }
122
123
    /**
124
     * Include sweet alert.
125
     *
126
     * @return $this
127
     */
128 View Code Duplication
    public function sweetAlert()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
129
    {
130
        $this->jquery();
131
        $this->Html->script('libs/sweetalert.min.js', $this->_options);
132
        $this->Html->css('libs/sweetalert.min.css', $this->_options);
133
        return $this;
134
    }
135
136
    /**
137
     * Include ui kit framework.
138
     *
139
     * @return $this
140
     */
141 View Code Duplication
    public function uikit()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
142
    {
143
        $this->jquery();
144
        $this->Html->script('libs/uikit.min.js', $this->_options);
145
        $this->Html->css('libs/uikit.min.css', $this->_options);
146
        return $this;
147
    }
148
149
    /**
150
     * Autoload plugin assets.
151
     *
152
     * @return void
153
     */
154
    public function loadPluginAssets()
155
    {
156
        $plugin = (string) $this->request->param('plugin');
157
        $prefix = ($this->request->param('prefix')) ? $this->request->param('prefix') . '/' : null;
158
        $action = (string) $this->request->param('action');
159
160
        $controller = (string) $this->request->param('controller');
161
        $widgetName = Str::slug($controller . '-' . $action) . '.js';
162
        $cssOptions = ['block' => 'css_bottom', 'fullBase' => true];
163
164
        $this->Html->css($plugin . '.' . $prefix . 'styles.css', $cssOptions);
165
        $this->Html->less($plugin . '.' . $prefix . 'styles.less', $cssOptions);
166
        $this->Html->script([
167
            $plugin . '.' . $prefix . 'widget/' . $widgetName,
168
            $plugin . '.' . $prefix . 'script.js',
169
        ], ['block' => 'script_bottom', 'fullBase' => true]);
170
    }
171
}
172