forked from PeerJ/sanpi-assetic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
125 lines (106 loc) · 3.04 KB
/
functions.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
* This file is part of the Assetic package, an OpenSky project.
*
* (c) 2010-2014 OpenSky Project Inc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Assetic\Factory\AssetFactory;
use Assetic\Util\TraversableString;
if (function_exists('assetic_init')) {
return;
}
/**
* Initializes the global Assetic object.
*
* @param AssetFactory $factory The asset factory
*/
function assetic_init(AssetFactory $factory)
{
global $_assetic;
$_assetic = new stdClass();
$_assetic->factory = $factory;
}
/**
* Returns an array of javascript URLs.
*
* @param array|string $inputs Input strings
* @param array|string $filters Filter names
* @param array $options An array of options
*
* @return array An array of javascript URLs
*/
function assetic_javascripts($inputs = array(), $filters = array(), array $options = array())
{
if (!isset($options['output'])) {
$options['output'] = 'js/*.js';
}
return _assetic_urls($inputs, $filters, $options);
}
/**
* Returns an array of stylesheet URLs.
*
* @param array|string $inputs Input strings
* @param array|string $filters Filter names
* @param array $options An array of options
*
* @return array An array of stylesheet URLs
*/
function assetic_stylesheets($inputs = array(), $filters = array(), array $options = array())
{
if (!isset($options['output'])) {
$options['output'] = 'css/*.css';
}
return _assetic_urls($inputs, $filters, $options);
}
/**
* Returns an image URL.
*
* @param string $input An input
* @param array|string $filters Filter names
* @param array $options An array of options
*
* @return string An image URL
*/
function assetic_image($input, $filters = array(), array $options = array())
{
if (!isset($options['output'])) {
$options['output'] = 'images/*';
}
$urls = _assetic_urls($input, $filters, $options);
return current($urls);
}
/**
* Returns an array of asset urls.
*
* @param array|string $inputs Input strings
* @param array|string $filters Filter names
* @param array $options An array of options
*
* @return array An array of URLs
*/
function _assetic_urls($inputs = array(), $filters = array(), array $options = array())
{
global $_assetic;
if (!is_array($inputs)) {
$inputs = array_filter(array_map('trim', explode(',', $inputs)));
}
if (!is_array($filters)) {
$filters = array_filter(array_map('trim', explode(',', $filters)));
}
$coll = $_assetic->factory->createAsset($inputs, $filters, $options);
$debug = isset($options['debug']) ? $options['debug'] : $_assetic->factory->isDebug();
$combine = isset($options['combine']) ? $options['combine'] : !$debug;
$one = $coll->getTargetPath();
if ($combine) {
$many = array($one);
} else {
$many = array();
foreach ($coll as $leaf) {
$many[] = $leaf->getTargetPath();
}
}
return new TraversableString($one, $many);
}