Completed
Pull Request — develop (#428)
by
unknown
09:46
created

AsseticConfiguration::buildCssWithSass()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 22
rs 8.9197
cc 4
eloc 14
nc 4
nop 1
1
<?php
2
/**
3
 * This file is part of BraincraftedBootstrapBundle.
4
 *
5
 * (c) 2012-2013 by Florian Eckerstorfer
6
 */
7
8
namespace Braincrafted\Bundle\BootstrapBundle\DependencyInjection;
9
10
/**
11
 * AsseticConfiguration
12
 *
13
 * @package    BraincraftedBootstrapBundle
14
 * @subpackage DependencyInjection
15
 * @author     Florian Eckerstorfer <[email protected]>
16
 * @copyright  2012-2013 Florian Eckerstorfer
17
 * @license    http://opensource.org/licenses/MIT The MIT License
18
 * @link       http://bootstrap.braincrafted.com Bootstrap for Symfony2
19
 */
20
class AsseticConfiguration
21
{
22
    /**
23
     * Builds the assetic configuration.
24
     *
25
     * @param array $config
26
     *
27
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array<string,array|string>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
28
     */
29
    public function build(array $config)
30
    {
31
        $output = array();
32
33
        // Fix path in output dir
34
        if ('/' !== substr($config['output_dir'], -1) && strlen($config['output_dir']) > 0) {
35
            $config['output_dir'] .= '/';
36
        }
37
38
        // changed from css_preprocessor to css_preprocessor for 3.0
39
        if (in_array($config['css_preprocessor'], array('sass', 'scssphp'))) {
40
            $output['bootstrap_css'] = $this->buildCssWithSass($config);
41
        } elseif ('none' !== $config['css_preprocessor']) {
42
            $output['bootstrap_css'] = $this->buildCssWithLess($config);
43
        } else {
44
            $output['bootstrap_css'] = $this->buildCssWithoutLess($config);
45
        }
46
47
        $output['bootstrap_js'] = $this->buildJs($config);
48
        $output['jquery'] = $this->buildJquery($config);
49
        $output['jqueryui'] = $this->buildJqueryui($config);
50
51
        return $output;
52
    }
53
54
    /**
55
     * @param array $config
56
     *
57
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string[]|string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
58
     */
59
    protected function buildCssWithoutLess(array $config)
60
    {
61
        $inputs = array(
62
            $config['assets_dir'].'/dist/css/bootstrap.css',
63
        );
64
        if ('fa' === $config['icon_prefix']) {
65
            $inputs[] = $config['fontawesome_dir'].'/css/font-awesome.css';
66
        }
67
68
        return array(
69
            'inputs'  => $inputs,
70
            'filters' => array('cssrewrite'),
71
            'output'  => $config['output_dir'].'css/bootstrap.css'
72
        );
73
    }
74
75
    /**
76
     * @param array $config
77
     *
78
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array|string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
79
     */
80
    protected function buildCssWithLess(array $config)
81
    {
82
        $bootstrapFile = $config['assets_dir'].'/less/bootstrap.less';
83
        if (true === isset($config['customize']['variables_file']) &&
84
            null !== $config['customize']['variables_file']) {
85
            $bootstrapFile = $config['customize']['bootstrap_output'];
86
        }
87
88
        $inputs = array(
89
            $bootstrapFile,
90
            __DIR__.'/../Resources/less/form.less'
91
        );
92
        if ('fa' === $config['icon_prefix']) {
93
            $inputs[] = $config['fontawesome_dir'].'/less/font-awesome.less';
94
        }
95
96
        return array(
97
            'inputs'  => $inputs,
98
            'filters' => array($config['css_preprocessor']),
99
            'output'  => $config['output_dir'].'css/bootstrap.css'
100
        );
101
    }
102
103
    /**
104
     * @param array $config
105
     *
106
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array|string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
107
     */
108
    protected function buildCssWithSass(array $config)
109
    {
110
        $bootstrapFile = $config['assets_dir'].'/stylesheets/_bootstrap.scss';
111
        if (true === isset($config['customize']['variables_file']) &&
112
            null !== $config['customize']['variables_file']) {
113
            $bootstrapFile = $config['customize']['bootstrap_output'];
114
        }
115
116
        $inputs = array(
117
            $bootstrapFile,
118
            __DIR__.'/../Resources/sass/form.scss'
119
        );
120
        if ('fa' === $config['icon_prefix']) {
121
            $inputs[] = $config['fontawesome_dir'].'/scss/font-awesome.scss';
122
        }
123
124
        return array(
125
            'inputs'  => $inputs,
126
            'filters' => array($config['css_preprocessor']),
127
            'output'  => $config['output_dir'].'css/bootstrap.css'
128
        );
129
    }
130
131
    /**
132
     * @param array $config
133
     *
134
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string[]|string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
135
     */
136
    protected function buildJs(array $config)
137
    {
138
        $path = !in_array($config['css_preprocessor'], array('sass', 'scssphp')) ? "/js" : "/javascripts/bootstrap";
139
140
        return array(
141
            'inputs'  => array(
142
                $config['assets_dir'].$path.'/transition.js',
143
                $config['assets_dir'].$path.'/alert.js',
144
                $config['assets_dir'].$path.'/button.js',
145
                $config['assets_dir'].$path.'/carousel.js',
146
                $config['assets_dir'].$path.'/collapse.js',
147
                $config['assets_dir'].$path.'/dropdown.js',
148
                $config['assets_dir'].$path.'/modal.js',
149
                $config['assets_dir'].$path.'/tooltip.js',
150
                $config['assets_dir'].$path.'/popover.js',
151
                $config['assets_dir'].$path.'/scrollspy.js',
152
                $config['assets_dir'].$path.'/tab.js',
153
                $config['assets_dir'].$path.'/affix.js',
154
                __DIR__.'/../Resources/js/bc-bootstrap-collection.js'
155
            ),
156
            'output'        => $config['output_dir'].'js/bootstrap.js'
157
        );
158
    }
159
160
    /**
161
     * @param array $config
162
     *
163
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array|string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
164
     */
165
    protected function buildJquery(array $config)
166
    {
167
        return array(
168
            'inputs' => array($config['jquery_path']),
169
            'output' => $config['output_dir'].'js/jquery.js'
170
        );
171
    }
172
173
    protected function buildJqueryui(array $config)
174
    {
175
        return array(
176
            'inputs' => array($config['jqueryui_path']),
177
            'output' => $config['output_dir'].'js/jquery-ui.js'
178
        );
179
    }
180
}
181