-
Notifications
You must be signed in to change notification settings - Fork 1
/
Amslib_Resource_Compiler.php
executable file
·212 lines (188 loc) · 5.29 KB
/
Amslib_Resource_Compiler.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/*******************************************************************************
* Copyright (c) {15/03/2008} {Christopher Thomas}
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Contributors/Author:
* {Christopher Thomas} - Creator - [email protected]
*
*******************************************************************************/
/**
* class: Amslib_Resource_Compiler
*
* group: core
*
* file: Amslib_Resource_Compiler.php
*
* description: todo, write description
*
* todo: write documentation
*/
class Amslib_Resource_Compiler
{
static protected $stylesheet = array();
static protected $javascript = array();
static protected $js = array();
static protected $jsc = array();
static protected $jsi = array();
static protected $cssc = array();
static protected $cssm = array();
static protected $cssi = array();
static protected $css = array();
/**
* method: addStylesheet
*
* todo: write documentation
*/
static public function addStylesheet($id,$file,$conditional=NULL,$media=NULL)
{
if(!$id || !is_string($id) || !$file || !is_string($file)) return;
if(is_string($conditional) && strlen($conditional)){
self::$cssc[$conditional][$id] = $file;
}else if(is_string($media) && strlen($media)){
self::$cssm[$media][$id] = $file;
}else if(strpos($file,"?")){
self::$cssi[$id] = $file;
}else{
self::$css[$id] = $file;
}
}
/**
* method: compile
*
* todo: write documentation
*/
static public function compile()
{
self::compileStylesheet();
self::compileJavascript();
}
/**
* method: compileStylesheet
*
* todo: write documentation
*/
static protected function compileStylesheet()
{
self::$stylesheet = array();
$content = "";
foreach(self::$css as $file) $content .= file_get_contents(Amslib_File::absolute($file))."/**/";
self::$stylesheet[] = "<style type='text/css'>$content</style>";
foreach(self::$cssm as $media => $list){
foreach($list as $file) self::$stylesheet[] = "<link rel='stylesheet' type='text/css' href='$file' media='$media' />";
}
foreach(self::$cssc as $conditional => $list){
$content = "";
foreach($list as $file) $content .= file_get_contents(Amslib_File::absolute($file));
self::$stylesheet[] = "<!--[$conditional]><style type='text'css'>$content</style><![endif]-->";
}
foreach(self::$cssi as $file){
self::$stylesheet[] = "<link rel='stylesheet' type='text/css' href='$file' />";
}
}
/**
* method: compileJavascript
*
* todo: write documentation
*/
static protected function compileJavascript()
{
}
/**
* method: getStylesheet
*
* todo: write documentation
*/
static public function getStylesheet()
{
return implode("",self::$stylesheet);
}
/**
* method: removeStylesheet
*
* todo: write documentation
*/
static public function removeStylesheet($id)
{
// TODO: This functionality is broken until I can unify the resource models
//unset(self::$stylesheet[$id]);
}
/**
* method: addJavascript
*
* todo: write documentation
*/
static public function addJavascript($id,$file,$conditional=NULL)
{
if($id && $file){
if(is_string($conditional) && strlen($conditional)){
self::$jsc[$conditional][$id] = $file;
}else if(strpos($file,"?")){
self::$jsi[$id] = $file;
}else{
self::$js[$id] = $file;
}
}
}
/**
* method: getJavascript
*
* todo: write documentation
*/
static public function getJavascript()
{
$output = "";
$content = "";
foreach(self::$js as $file) $content .= file_get_contents(Amslib_File::absolute($file));
$output .= "<script type='text/javascript'>$content</script>";
foreach(self::$jsc as $condition => $list){
$content = "";
foreach($list as $file) $content .= file_get_contents(Amslib_File::absolute($file));
$output .= "<!--[$conditional]><script type='text/javascript'>$content</script><![endif]-->";
}
foreach(self::$jsi as $file){
$output .= "<script type='text/javascript' src='$file'></script>";
}
return $output;
}
/**
* method: removeJavascript
*
* todo: write documentation
*/
static public function removeJavascript($id)
{
// TODO: This functionality is broken until I can unify the resource models
//unset(self::$javascript[$id]);
}
/**
* method: addGoogleFont
*
* todo: write documentation
*/
static public function addGoogleFont($id,$font,$conditional=NULL)
{
Amslib_Resource::addStylesheet($id,"http://fonts.googleapis.com/css?$font",$conditional);
}
/**
* method: removeGoogleFont
*
* todo: write documentation
*/
static public function removeGoogleFont($id)
{
Amslib_Resource::removeStylesheet($id);
}
}