Version Description
Download this release
Release Info
Developer | oncletom |
Plugin | WP-LESS |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 1.2
- bootstrap.php +1 -1
- lib/Compiler.class.php +30 -0
- lib/Configuration.class.php +2 -2
- lib/Exception.class.php +11 -2
- lib/Plugin.class.php +23 -1
- lib/Stylesheet.class.php +50 -7
- lib/helper/ThemeHelper.php +48 -0
- lib/vendor/lessphp/LICENSE +658 -178
- lib/vendor/lessphp/README +8 -15
- lib/vendor/lessphp/docs/docs.html +24 -18
- lib/vendor/lessphp/docs/style.css +9 -70
- lib/vendor/lessphp/lessc.inc.php +892 -835
- lib/vendor/lessphp/plessc +10 -3
- readme.txt +12 -2
bootstrap.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: WP LESS
|
4 |
Description: LESS extends CSS with variables, mixins, operations and nested rules. This plugin magically parse all your <code>*.less</code> files queued with <code>wp_enqueue_style</code> in WordPress.
|
5 |
Author: Oncle Tom
|
6 |
-
Version: 1.
|
7 |
Author URI: http://case.oncle-tom.net/
|
8 |
Plugin URI: http://wordpress.org/extend/plugins/wp-less/
|
9 |
|
3 |
Plugin Name: WP LESS
|
4 |
Description: LESS extends CSS with variables, mixins, operations and nested rules. This plugin magically parse all your <code>*.less</code> files queued with <code>wp_enqueue_style</code> in WordPress.
|
5 |
Author: Oncle Tom
|
6 |
+
Version: 1.2
|
7 |
Author URI: http://case.oncle-tom.net/
|
8 |
Plugin URI: http://wordpress.org/extend/plugins/wp-less/
|
9 |
|
lib/Compiler.class.php
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* LESS compiler
|
4 |
+
*
|
5 |
+
* @author oncletom
|
6 |
+
* @extends lessc
|
7 |
+
* @package wp-less
|
8 |
+
* @subpackage lib
|
9 |
+
* @since 1.2
|
10 |
+
* @version 1.0
|
11 |
+
*/
|
12 |
+
class WPLessCompiler extends lessc
|
13 |
+
{
|
14 |
+
/**
|
15 |
+
* Parse a LESS file
|
16 |
+
*
|
17 |
+
* @see lessc::parse
|
18 |
+
* @author oncletom
|
19 |
+
* @throws Exception
|
20 |
+
* @param string $text [optional] Custom CSS to parse
|
21 |
+
* @return string CSS output
|
22 |
+
*/
|
23 |
+
public function parse($text = null)
|
24 |
+
{
|
25 |
+
$output = parent::parse($text);
|
26 |
+
$output = apply_filters('wp-less_compiler_parse', $output);
|
27 |
+
|
28 |
+
return $output;
|
29 |
+
}
|
30 |
+
}
|
lib/Configuration.class.php
CHANGED
@@ -10,7 +10,7 @@ class WPLessConfiguration extends WPPluginToolkitConfiguration
|
|
10 |
/**
|
11 |
* Refers to the version of the plugin
|
12 |
*/
|
13 |
-
const VERSION = '1.
|
14 |
|
15 |
|
16 |
protected function configure()
|
@@ -20,6 +20,6 @@ class WPLessConfiguration extends WPPluginToolkitConfiguration
|
|
20 |
|
21 |
protected function configureOptions()
|
22 |
{
|
23 |
-
|
24 |
}
|
25 |
}
|
10 |
/**
|
11 |
* Refers to the version of the plugin
|
12 |
*/
|
13 |
+
const VERSION = '1.2';
|
14 |
|
15 |
|
16 |
protected function configure()
|
20 |
|
21 |
protected function configureOptions()
|
22 |
{
|
23 |
+
|
24 |
}
|
25 |
}
|
lib/Exception.class.php
CHANGED
@@ -1,12 +1,21 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Basic Exception
|
4 |
-
*
|
5 |
* @author oncletom
|
6 |
* @package wp-less
|
7 |
* @subpackage lib
|
8 |
*/
|
9 |
class WPLessException extends Exception
|
10 |
{
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Basic Exception
|
4 |
+
*
|
5 |
* @author oncletom
|
6 |
* @package wp-less
|
7 |
* @subpackage lib
|
8 |
*/
|
9 |
class WPLessException extends Exception
|
10 |
{
|
11 |
+
/**
|
12 |
+
* Override the display output of the exception for WordPress
|
13 |
+
*
|
14 |
+
* @author oncletom
|
15 |
+
* @see Exception::__toString()
|
16 |
+
*/
|
17 |
+
public function __toString()
|
18 |
+
{
|
19 |
+
wp_die($this->getMessage().'<br /><pre>'.$this->getTraceAsString().'</pre>', 'WP-LESS exception');
|
20 |
+
}
|
21 |
}
|
lib/Plugin.class.php
CHANGED
@@ -22,6 +22,27 @@ class WPLessPlugin extends WPPluginToolkitPlugin
|
|
22 |
*/
|
23 |
public static $match_pattern = '/\.less$/U';
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
/**
|
26 |
* Find any style to process
|
27 |
*
|
@@ -126,7 +147,7 @@ class WPLessPlugin extends WPPluginToolkitPlugin
|
|
126 |
*
|
127 |
* @author oncletom
|
128 |
* @since 1.1
|
129 |
-
* @version 1.
|
130 |
*/
|
131 |
public function registerHooks()
|
132 |
{
|
@@ -139,6 +160,7 @@ class WPLessPlugin extends WPPluginToolkitPlugin
|
|
139 |
{
|
140 |
do_action('wp-less_init', $this);
|
141 |
add_action('wp_print_styles', array($this, 'processStylesheets'));
|
|
|
142 |
}
|
143 |
else
|
144 |
{
|
22 |
*/
|
23 |
public static $match_pattern = '/\.less$/U';
|
24 |
|
25 |
+
/**
|
26 |
+
* Correct Stylesheet URI
|
27 |
+
*
|
28 |
+
* It enables the cache without loosing reference to URI
|
29 |
+
*
|
30 |
+
* @author oncletom
|
31 |
+
* @since 1.2
|
32 |
+
* @version 1.0
|
33 |
+
* @param string $css parsed CSS
|
34 |
+
* @param WPLessStylesheet Stylesheet currently processed
|
35 |
+
* @return string parsed and fixed CSS
|
36 |
+
*/
|
37 |
+
public function filterStylesheetUri($css, WPLessStylesheet $stylesheet)
|
38 |
+
{
|
39 |
+
$token = '@'.uniqid('wpless', true).'@';
|
40 |
+
$css = preg_replace('#(url\s*\([\'"])([^/]+)#siU', '\1'.$token.'\2', $css);
|
41 |
+
$css = str_replace($token, dirname($stylesheet->getSourceUri()).'/', $css);
|
42 |
+
|
43 |
+
return $css;
|
44 |
+
}
|
45 |
+
|
46 |
/**
|
47 |
* Find any style to process
|
48 |
*
|
147 |
*
|
148 |
* @author oncletom
|
149 |
* @since 1.1
|
150 |
+
* @version 1.1
|
151 |
*/
|
152 |
public function registerHooks()
|
153 |
{
|
160 |
{
|
161 |
do_action('wp-less_init', $this);
|
162 |
add_action('wp_print_styles', array($this, 'processStylesheets'));
|
163 |
+
add_filter('wp-less_stylesheet_parse', array($this, 'filterStylesheetUri'), 10, 2);
|
164 |
}
|
165 |
else
|
166 |
{
|
lib/Stylesheet.class.php
CHANGED
@@ -13,9 +13,11 @@ class WPLessStylesheet
|
|
13 |
protected $compiler,
|
14 |
$stylesheet;
|
15 |
|
16 |
-
protected $
|
|
|
17 |
$source_uri,
|
18 |
$target_path,
|
|
|
19 |
$target_uri;
|
20 |
|
21 |
public static $upload_dir,
|
@@ -40,6 +42,8 @@ class WPLessStylesheet
|
|
40 |
}
|
41 |
|
42 |
$this->configurePath();
|
|
|
|
|
43 |
do_action('wp-less_stylesheet_construct', $this);
|
44 |
}
|
45 |
|
@@ -80,6 +84,38 @@ class WPLessStylesheet
|
|
80 |
$this->target_uri = self::$upload_uri.$target_file;
|
81 |
}
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
/**
|
84 |
* Returns source content (CSS to parse)
|
85 |
*
|
@@ -155,12 +191,14 @@ class WPLessStylesheet
|
|
155 |
*
|
156 |
* @author oncletom
|
157 |
* @since 1.0
|
158 |
-
* @version 1.
|
|
|
|
|
159 |
* @return string
|
160 |
*/
|
161 |
-
public function getTargetUri()
|
162 |
{
|
163 |
-
return $this->target_uri;
|
164 |
}
|
165 |
|
166 |
/**
|
@@ -173,7 +211,7 @@ class WPLessStylesheet
|
|
173 |
*/
|
174 |
public function hasToCompile()
|
175 |
{
|
176 |
-
return
|
177 |
}
|
178 |
|
179 |
/**
|
@@ -181,7 +219,7 @@ class WPLessStylesheet
|
|
181 |
*
|
182 |
* @author oncletom
|
183 |
* @since 1.0
|
184 |
-
* @version 1.
|
185 |
* @throws Exception in case of parsing went bad
|
186 |
*/
|
187 |
public function save()
|
@@ -191,8 +229,13 @@ class WPLessStylesheet
|
|
191 |
try
|
192 |
{
|
193 |
do_action('wp-less_stylesheet_save_pre', $this);
|
194 |
-
|
|
|
|
|
|
|
195 |
chmod($this->getTargetPath(), 0666);
|
|
|
|
|
196 |
do_action('wp-less_stylesheet_save_post', $this);
|
197 |
}
|
198 |
catch(Exception $e)
|
13 |
protected $compiler,
|
14 |
$stylesheet;
|
15 |
|
16 |
+
protected $is_new = true,
|
17 |
+
$source_path,
|
18 |
$source_uri,
|
19 |
$target_path,
|
20 |
+
$target_timestamp,
|
21 |
$target_uri;
|
22 |
|
23 |
public static $upload_dir,
|
42 |
}
|
43 |
|
44 |
$this->configurePath();
|
45 |
+
$this->configureVersion();
|
46 |
+
|
47 |
do_action('wp-less_stylesheet_construct', $this);
|
48 |
}
|
49 |
|
84 |
$this->target_uri = self::$upload_uri.$target_file;
|
85 |
}
|
86 |
|
87 |
+
/**
|
88 |
+
* Configures version and timestamp
|
89 |
+
*
|
90 |
+
* It can be run only after paths have been configured. Otherwise (or if the calculation went wrong),
|
91 |
+
* an exception will be thrown.
|
92 |
+
*
|
93 |
+
* @author oncletom
|
94 |
+
* @since 1.2
|
95 |
+
* @version 1.0
|
96 |
+
* @throws WPLessException
|
97 |
+
*/
|
98 |
+
public function configureVersion()
|
99 |
+
{
|
100 |
+
if (!$this->getTargetPath())
|
101 |
+
{
|
102 |
+
throw new WPLessException("Can't configure any version if there is no target path.");
|
103 |
+
}
|
104 |
+
|
105 |
+
if (file_exists($this->getTargetPath()))
|
106 |
+
{
|
107 |
+
$this->is_new = false;
|
108 |
+
$this->target_timestamp = filemtime($this->getTargetPath());
|
109 |
+
}
|
110 |
+
else
|
111 |
+
{
|
112 |
+
$this->is_new = true;
|
113 |
+
$this->target_timestamp = time();
|
114 |
+
}
|
115 |
+
|
116 |
+
$this->stylesheet->ver = $this->target_timestamp;
|
117 |
+
}
|
118 |
+
|
119 |
/**
|
120 |
* Returns source content (CSS to parse)
|
121 |
*
|
191 |
*
|
192 |
* @author oncletom
|
193 |
* @since 1.0
|
194 |
+
* @version 1.1
|
195 |
+
* @param boolean $append_version
|
196 |
+
* @param string $version_prefix
|
197 |
* @return string
|
198 |
*/
|
199 |
+
public function getTargetUri($append_version = false, $version_prefix = '?ver=')
|
200 |
{
|
201 |
+
return $this->target_uri.(!!$append_version ? $version_prefix.$this->target_timestamp : '');
|
202 |
}
|
203 |
|
204 |
/**
|
211 |
*/
|
212 |
public function hasToCompile()
|
213 |
{
|
214 |
+
return $this->is_new || filemtime($this->getSourcePath()) > $this->target_timestamp;
|
215 |
}
|
216 |
|
217 |
/**
|
219 |
*
|
220 |
* @author oncletom
|
221 |
* @since 1.0
|
222 |
+
* @version 1.1
|
223 |
* @throws Exception in case of parsing went bad
|
224 |
*/
|
225 |
public function save()
|
229 |
try
|
230 |
{
|
231 |
do_action('wp-less_stylesheet_save_pre', $this);
|
232 |
+
$compiler = new WPLessCompiler($this->getSourcePath());
|
233 |
+
|
234 |
+
$output = apply_filters('wp-less_stylesheet_parse', $compiler->parse(), $this);
|
235 |
+
file_put_contents($this->getTargetPath(), $output);
|
236 |
chmod($this->getTargetPath(), 0666);
|
237 |
+
|
238 |
+
$this->is_new = false;
|
239 |
do_action('wp-less_stylesheet_save_post', $this);
|
240 |
}
|
241 |
catch(Exception $e)
|
lib/helper/ThemeHelper.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* LESSify a stylesheet on the fly
|
4 |
+
*
|
5 |
+
* <pre>
|
6 |
+
* <head>
|
7 |
+
* <title><?php wp_title() ?></title>
|
8 |
+
* <link rel="stylesheet" media="all" type="text/css" href="<?php echo wp_lessify(get_bloginfo('template_dir').'/myfile.less') ?>" />
|
9 |
+
* </head>
|
10 |
+
* </pre>
|
11 |
+
*
|
12 |
+
* @todo hook on WordPress cache system
|
13 |
+
* @author oncletom
|
14 |
+
* @since 1.2
|
15 |
+
* @version 1.0
|
16 |
+
* @param string $stylesheet_uri
|
17 |
+
* @param string $cache_key
|
18 |
+
* @param string $version_prefix
|
19 |
+
* @return string processed URI
|
20 |
+
*/
|
21 |
+
function wp_lessify($stylesheet_uri, $cache_key = null, $version_prefix = '?ver=')
|
22 |
+
{
|
23 |
+
static $wp_less_uri_cache;
|
24 |
+
$cache_key = 'wp-less-'.($cache_key === '' ? md5($stylesheet_uri) : $cache_key);
|
25 |
+
|
26 |
+
if (is_null($wp_less_uri_cache))
|
27 |
+
{
|
28 |
+
$wp_less_uri_cache = array();
|
29 |
+
}
|
30 |
+
|
31 |
+
if (isset($wp_less_uri_cache[$cache_key]))
|
32 |
+
{
|
33 |
+
return $wp_less_uri_cache[$cache_key];
|
34 |
+
}
|
35 |
+
|
36 |
+
/*
|
37 |
+
* Register a fake stylesheet to make the process possible
|
38 |
+
* It relies on a _WP_Dependency object
|
39 |
+
*/
|
40 |
+
wp_register_style($cache_key, $stylesheet_uri);
|
41 |
+
$stylesheet = WPLessPlugin::getInstance()->processStylesheet($cache_key);
|
42 |
+
wp_deregister_style($cache_key);
|
43 |
+
$wp_less_uri_cache[$cache_key] = $stylesheet->getTargetUri(true, $version_prefix);
|
44 |
+
|
45 |
+
unset($stylesheet);
|
46 |
+
return $wp_less_uri_cache[$cache_key];
|
47 |
+
}
|
48 |
+
|
lib/vendor/lessphp/LICENSE
CHANGED
@@ -1,180 +1,660 @@
|
|
|
|
|
|
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 |
|
1 |
+
For ease of distribution, lessphp 0.2.0 is under a dual license.
|
2 |
+
You are free to pick which one suits your needs.
|
3 |
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
MIT LICENSE
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
Copyright (c) 2010 Leaf Corcoran, http://leafo.net/lessphp
|
13 |
+
|
14 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
15 |
+
a copy of this software and associated documentation files (the
|
16 |
+
"Software"), to deal in the Software without restriction, including
|
17 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
18 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
19 |
+
permit persons to whom the Software is furnished to do so, subject to
|
20 |
+
the following conditions:
|
21 |
+
|
22 |
+
The above copyright notice and this permission notice shall be
|
23 |
+
included in all copies or substantial portions of the Software.
|
24 |
+
|
25 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
26 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
27 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
28 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
29 |
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
30 |
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
31 |
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
GPL VERSION 3
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
GNU GENERAL PUBLIC LICENSE
|
42 |
+
Version 3, 29 June 2007
|
43 |
+
|
44 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
45 |
+
Everyone is permitted to copy and distribute verbatim copies
|
46 |
+
of this license document, but changing it is not allowed.
|
47 |
+
|
48 |
+
Preamble
|
49 |
+
|
50 |
+
The GNU General Public License is a free, copyleft license for
|
51 |
+
software and other kinds of works.
|
52 |
+
|
53 |
+
The licenses for most software and other practical works are designed
|
54 |
+
to take away your freedom to share and change the works. By contrast,
|
55 |
+
the GNU General Public License is intended to guarantee your freedom to
|
56 |
+
share and change all versions of a program--to make sure it remains free
|
57 |
+
software for all its users. We, the Free Software Foundation, use the
|
58 |
+
GNU General Public License for most of our software; it applies also to
|
59 |
+
any other work released this way by its authors. You can apply it to
|
60 |
+
your programs, too.
|
61 |
+
|
62 |
+
When we speak of free software, we are referring to freedom, not
|
63 |
+
price. Our General Public Licenses are designed to make sure that you
|
64 |
+
have the freedom to distribute copies of free software (and charge for
|
65 |
+
them if you wish), that you receive source code or can get it if you
|
66 |
+
want it, that you can change the software or use pieces of it in new
|
67 |
+
free programs, and that you know you can do these things.
|
68 |
+
|
69 |
+
To protect your rights, we need to prevent others from denying you
|
70 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
71 |
+
certain responsibilities if you distribute copies of the software, or if
|
72 |
+
you modify it: responsibilities to respect the freedom of others.
|
73 |
+
|
74 |
+
For example, if you distribute copies of such a program, whether
|
75 |
+
gratis or for a fee, you must pass on to the recipients the same
|
76 |
+
freedoms that you received. You must make sure that they, too, receive
|
77 |
+
or can get the source code. And you must show them these terms so they
|
78 |
+
know their rights.
|
79 |
+
|
80 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
81 |
+
(1) assert copyright on the software, and (2) offer you this License
|
82 |
+
giving you legal permission to copy, distribute and/or modify it.
|
83 |
+
|
84 |
+
For the developers' and authors' protection, the GPL clearly explains
|
85 |
+
that there is no warranty for this free software. For both users' and
|
86 |
+
authors' sake, the GPL requires that modified versions be marked as
|
87 |
+
changed, so that their problems will not be attributed erroneously to
|
88 |
+
authors of previous versions.
|
89 |
+
|
90 |
+
Some devices are designed to deny users access to install or run
|
91 |
+
modified versions of the software inside them, although the manufacturer
|
92 |
+
can do so. This is fundamentally incompatible with the aim of
|
93 |
+
protecting users' freedom to change the software. The systematic
|
94 |
+
pattern of such abuse occurs in the area of products for individuals to
|
95 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
96 |
+
have designed this version of the GPL to prohibit the practice for those
|
97 |
+
products. If such problems arise substantially in other domains, we
|
98 |
+
stand ready to extend this provision to those domains in future versions
|
99 |
+
of the GPL, as needed to protect the freedom of users.
|
100 |
+
|
101 |
+
Finally, every program is threatened constantly by software patents.
|
102 |
+
States should not allow patents to restrict development and use of
|
103 |
+
software on general-purpose computers, but in those that do, we wish to
|
104 |
+
avoid the special danger that patents applied to a free program could
|
105 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
106 |
+
patents cannot be used to render the program non-free.
|
107 |
+
|
108 |
+
The precise terms and conditions for copying, distribution and
|
109 |
+
modification follow.
|
110 |
+
|
111 |
+
TERMS AND CONDITIONS
|
112 |
+
|
113 |
+
0. Definitions.
|
114 |
+
|
115 |
+
"This License" refers to version 3 of the GNU General Public License.
|
116 |
+
|
117 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
118 |
+
works, such as semiconductor masks.
|
119 |
+
|
120 |
+
"The Program" refers to any copyrightable work licensed under this
|
121 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
122 |
+
"recipients" may be individuals or organizations.
|
123 |
+
|
124 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
125 |
+
in a fashion requiring copyright permission, other than the making of an
|
126 |
+
exact copy. The resulting work is called a "modified version" of the
|
127 |
+
earlier work or a work "based on" the earlier work.
|
128 |
+
|
129 |
+
A "covered work" means either the unmodified Program or a work based
|
130 |
+
on the Program.
|
131 |
+
|
132 |
+
To "propagate" a work means to do anything with it that, without
|
133 |
+
permission, would make you directly or secondarily liable for
|
134 |
+
infringement under applicable copyright law, except executing it on a
|
135 |
+
computer or modifying a private copy. Propagation includes copying,
|
136 |
+
distribution (with or without modification), making available to the
|
137 |
+
public, and in some countries other activities as well.
|
138 |
+
|
139 |
+
To "convey" a work means any kind of propagation that enables other
|
140 |
+
parties to make or receive copies. Mere interaction with a user through
|
141 |
+
a computer network, with no transfer of a copy, is not conveying.
|
142 |
+
|
143 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
144 |
+
to the extent that it includes a convenient and prominently visible
|
145 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
146 |
+
tells the user that there is no warranty for the work (except to the
|
147 |
+
extent that warranties are provided), that licensees may convey the
|
148 |
+
work under this License, and how to view a copy of this License. If
|
149 |
+
the interface presents a list of user commands or options, such as a
|
150 |
+
menu, a prominent item in the list meets this criterion.
|
151 |
+
|
152 |
+
1. Source Code.
|
153 |
+
|
154 |
+
The "source code" for a work means the preferred form of the work
|
155 |
+
for making modifications to it. "Object code" means any non-source
|
156 |
+
form of a work.
|
157 |
+
|
158 |
+
A "Standard Interface" means an interface that either is an official
|
159 |
+
standard defined by a recognized standards body, or, in the case of
|
160 |
+
interfaces specified for a particular programming language, one that
|
161 |
+
is widely used among developers working in that language.
|
162 |
+
|
163 |
+
The "System Libraries" of an executable work include anything, other
|
164 |
+
than the work as a whole, that (a) is included in the normal form of
|
165 |
+
packaging a Major Component, but which is not part of that Major
|
166 |
+
Component, and (b) serves only to enable use of the work with that
|
167 |
+
Major Component, or to implement a Standard Interface for which an
|
168 |
+
implementation is available to the public in source code form. A
|
169 |
+
"Major Component", in this context, means a major essential component
|
170 |
+
(kernel, window system, and so on) of the specific operating system
|
171 |
+
(if any) on which the executable work runs, or a compiler used to
|
172 |
+
produce the work, or an object code interpreter used to run it.
|
173 |
+
|
174 |
+
The "Corresponding Source" for a work in object code form means all
|
175 |
+
the source code needed to generate, install, and (for an executable
|
176 |
+
work) run the object code and to modify the work, including scripts to
|
177 |
+
control those activities. However, it does not include the work's
|
178 |
+
System Libraries, or general-purpose tools or generally available free
|
179 |
+
programs which are used unmodified in performing those activities but
|
180 |
+
which are not part of the work. For example, Corresponding Source
|
181 |
+
includes interface definition files associated with source files for
|
182 |
+
the work, and the source code for shared libraries and dynamically
|
183 |
+
linked subprograms that the work is specifically designed to require,
|
184 |
+
such as by intimate data communication or control flow between those
|
185 |
+
subprograms and other parts of the work.
|
186 |
+
|
187 |
+
The Corresponding Source need not include anything that users
|
188 |
+
can regenerate automatically from other parts of the Corresponding
|
189 |
+
Source.
|
190 |
+
|
191 |
+
The Corresponding Source for a work in source code form is that
|
192 |
+
same work.
|
193 |
+
|
194 |
+
2. Basic Permissions.
|
195 |
+
|
196 |
+
All rights granted under this License are granted for the term of
|
197 |
+
copyright on the Program, and are irrevocable provided the stated
|
198 |
+
conditions are met. This License explicitly affirms your unlimited
|
199 |
+
permission to run the unmodified Program. The output from running a
|
200 |
+
covered work is covered by this License only if the output, given its
|
201 |
+
content, constitutes a covered work. This License acknowledges your
|
202 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
203 |
+
|
204 |
+
You may make, run and propagate covered works that you do not
|
205 |
+
convey, without conditions so long as your license otherwise remains
|
206 |
+
in force. You may convey covered works to others for the sole purpose
|
207 |
+
of having them make modifications exclusively for you, or provide you
|
208 |
+
with facilities for running those works, provided that you comply with
|
209 |
+
the terms of this License in conveying all material for which you do
|
210 |
+
not control copyright. Those thus making or running the covered works
|
211 |
+
for you must do so exclusively on your behalf, under your direction
|
212 |
+
and control, on terms that prohibit them from making any copies of
|
213 |
+
your copyrighted material outside their relationship with you.
|
214 |
+
|
215 |
+
Conveying under any other circumstances is permitted solely under
|
216 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
217 |
+
makes it unnecessary.
|
218 |
+
|
219 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
220 |
+
|
221 |
+
No covered work shall be deemed part of an effective technological
|
222 |
+
measure under any applicable law fulfilling obligations under article
|
223 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
224 |
+
similar laws prohibiting or restricting circumvention of such
|
225 |
+
measures.
|
226 |
+
|
227 |
+
When you convey a covered work, you waive any legal power to forbid
|
228 |
+
circumvention of technological measures to the extent such circumvention
|
229 |
+
is effected by exercising rights under this License with respect to
|
230 |
+
the covered work, and you disclaim any intention to limit operation or
|
231 |
+
modification of the work as a means of enforcing, against the work's
|
232 |
+
users, your or third parties' legal rights to forbid circumvention of
|
233 |
+
technological measures.
|
234 |
+
|
235 |
+
4. Conveying Verbatim Copies.
|
236 |
+
|
237 |
+
You may convey verbatim copies of the Program's source code as you
|
238 |
+
receive it, in any medium, provided that you conspicuously and
|
239 |
+
appropriately publish on each copy an appropriate copyright notice;
|
240 |
+
keep intact all notices stating that this License and any
|
241 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
242 |
+
keep intact all notices of the absence of any warranty; and give all
|
243 |
+
recipients a copy of this License along with the Program.
|
244 |
+
|
245 |
+
You may charge any price or no price for each copy that you convey,
|
246 |
+
and you may offer support or warranty protection for a fee.
|
247 |
+
|
248 |
+
5. Conveying Modified Source Versions.
|
249 |
+
|
250 |
+
You may convey a work based on the Program, or the modifications to
|
251 |
+
produce it from the Program, in the form of source code under the
|
252 |
+
terms of section 4, provided that you also meet all of these conditions:
|
253 |
+
|
254 |
+
a) The work must carry prominent notices stating that you modified
|
255 |
+
it, and giving a relevant date.
|
256 |
+
|
257 |
+
b) The work must carry prominent notices stating that it is
|
258 |
+
released under this License and any conditions added under section
|
259 |
+
7. This requirement modifies the requirement in section 4 to
|
260 |
+
"keep intact all notices".
|
261 |
+
|
262 |
+
c) You must license the entire work, as a whole, under this
|
263 |
+
License to anyone who comes into possession of a copy. This
|
264 |
+
License will therefore apply, along with any applicable section 7
|
265 |
+
additional terms, to the whole of the work, and all its parts,
|
266 |
+
regardless of how they are packaged. This License gives no
|
267 |
+
permission to license the work in any other way, but it does not
|
268 |
+
invalidate such permission if you have separately received it.
|
269 |
+
|
270 |
+
d) If the work has interactive user interfaces, each must display
|
271 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
272 |
+
interfaces that do not display Appropriate Legal Notices, your
|
273 |
+
work need not make them do so.
|
274 |
+
|
275 |
+
A compilation of a covered work with other separate and independent
|
276 |
+
works, which are not by their nature extensions of the covered work,
|
277 |
+
and which are not combined with it such as to form a larger program,
|
278 |
+
in or on a volume of a storage or distribution medium, is called an
|
279 |
+
"aggregate" if the compilation and its resulting copyright are not
|
280 |
+
used to limit the access or legal rights of the compilation's users
|
281 |
+
beyond what the individual works permit. Inclusion of a covered work
|
282 |
+
in an aggregate does not cause this License to apply to the other
|
283 |
+
parts of the aggregate.
|
284 |
+
|
285 |
+
6. Conveying Non-Source Forms.
|
286 |
+
|
287 |
+
You may convey a covered work in object code form under the terms
|
288 |
+
of sections 4 and 5, provided that you also convey the
|
289 |
+
machine-readable Corresponding Source under the terms of this License,
|
290 |
+
in one of these ways:
|
291 |
+
|
292 |
+
a) Convey the object code in, or embodied in, a physical product
|
293 |
+
(including a physical distribution medium), accompanied by the
|
294 |
+
Corresponding Source fixed on a durable physical medium
|
295 |
+
customarily used for software interchange.
|
296 |
+
|
297 |
+
b) Convey the object code in, or embodied in, a physical product
|
298 |
+
(including a physical distribution medium), accompanied by a
|
299 |
+
written offer, valid for at least three years and valid for as
|
300 |
+
long as you offer spare parts or customer support for that product
|
301 |
+
model, to give anyone who possesses the object code either (1) a
|
302 |
+
copy of the Corresponding Source for all the software in the
|
303 |
+
product that is covered by this License, on a durable physical
|
304 |
+
medium customarily used for software interchange, for a price no
|
305 |
+
more than your reasonable cost of physically performing this
|
306 |
+
conveying of source, or (2) access to copy the
|
307 |
+
Corresponding Source from a network server at no charge.
|
308 |
+
|
309 |
+
c) Convey individual copies of the object code with a copy of the
|
310 |
+
written offer to provide the Corresponding Source. This
|
311 |
+
alternative is allowed only occasionally and noncommercially, and
|
312 |
+
only if you received the object code with such an offer, in accord
|
313 |
+
with subsection 6b.
|
314 |
+
|
315 |
+
d) Convey the object code by offering access from a designated
|
316 |
+
place (gratis or for a charge), and offer equivalent access to the
|
317 |
+
Corresponding Source in the same way through the same place at no
|
318 |
+
further charge. You need not require recipients to copy the
|
319 |
+
Corresponding Source along with the object code. If the place to
|
320 |
+
copy the object code is a network server, the Corresponding Source
|
321 |
+
may be on a different server (operated by you or a third party)
|
322 |
+
that supports equivalent copying facilities, provided you maintain
|
323 |
+
clear directions next to the object code saying where to find the
|
324 |
+
Corresponding Source. Regardless of what server hosts the
|
325 |
+
Corresponding Source, you remain obligated to ensure that it is
|
326 |
+
available for as long as needed to satisfy these requirements.
|
327 |
+
|
328 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
329 |
+
you inform other peers where the object code and Corresponding
|
330 |
+
Source of the work are being offered to the general public at no
|
331 |
+
charge under subsection 6d.
|
332 |
+
|
333 |
+
A separable portion of the object code, whose source code is excluded
|
334 |
+
from the Corresponding Source as a System Library, need not be
|
335 |
+
included in conveying the object code work.
|
336 |
+
|
337 |
+
A "User Product" is either (1) a "consumer product", which means any
|
338 |
+
tangible personal property which is normally used for personal, family,
|
339 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
340 |
+
into a dwelling. In determining whether a product is a consumer product,
|
341 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
342 |
+
product received by a particular user, "normally used" refers to a
|
343 |
+
typical or common use of that class of product, regardless of the status
|
344 |
+
of the particular user or of the way in which the particular user
|
345 |
+
actually uses, or expects or is expected to use, the product. A product
|
346 |
+
is a consumer product regardless of whether the product has substantial
|
347 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
348 |
+
the only significant mode of use of the product.
|
349 |
+
|
350 |
+
"Installation Information" for a User Product means any methods,
|
351 |
+
procedures, authorization keys, or other information required to install
|
352 |
+
and execute modified versions of a covered work in that User Product from
|
353 |
+
a modified version of its Corresponding Source. The information must
|
354 |
+
suffice to ensure that the continued functioning of the modified object
|
355 |
+
code is in no case prevented or interfered with solely because
|
356 |
+
modification has been made.
|
357 |
+
|
358 |
+
If you convey an object code work under this section in, or with, or
|
359 |
+
specifically for use in, a User Product, and the conveying occurs as
|
360 |
+
part of a transaction in which the right of possession and use of the
|
361 |
+
User Product is transferred to the recipient in perpetuity or for a
|
362 |
+
fixed term (regardless of how the transaction is characterized), the
|
363 |
+
Corresponding Source conveyed under this section must be accompanied
|
364 |
+
by the Installation Information. But this requirement does not apply
|
365 |
+
if neither you nor any third party retains the ability to install
|
366 |
+
modified object code on the User Product (for example, the work has
|
367 |
+
been installed in ROM).
|
368 |
+
|
369 |
+
The requirement to provide Installation Information does not include a
|
370 |
+
requirement to continue to provide support service, warranty, or updates
|
371 |
+
for a work that has been modified or installed by the recipient, or for
|
372 |
+
the User Product in which it has been modified or installed. Access to a
|
373 |
+
network may be denied when the modification itself materially and
|
374 |
+
adversely affects the operation of the network or violates the rules and
|
375 |
+
protocols for communication across the network.
|
376 |
+
|
377 |
+
Corresponding Source conveyed, and Installation Information provided,
|
378 |
+
in accord with this section must be in a format that is publicly
|
379 |
+
documented (and with an implementation available to the public in
|
380 |
+
source code form), and must require no special password or key for
|
381 |
+
unpacking, reading or copying.
|
382 |
+
|
383 |
+
7. Additional Terms.
|
384 |
+
|
385 |
+
"Additional permissions" are terms that supplement the terms of this
|
386 |
+
License by making exceptions from one or more of its conditions.
|
387 |
+
Additional permissions that are applicable to the entire Program shall
|
388 |
+
be treated as though they were included in this License, to the extent
|
389 |
+
that they are valid under applicable law. If additional permissions
|
390 |
+
apply only to part of the Program, that part may be used separately
|
391 |
+
under those permissions, but the entire Program remains governed by
|
392 |
+
this License without regard to the additional permissions.
|
393 |
+
|
394 |
+
When you convey a copy of a covered work, you may at your option
|
395 |
+
remove any additional permissions from that copy, or from any part of
|
396 |
+
it. (Additional permissions may be written to require their own
|
397 |
+
removal in certain cases when you modify the work.) You may place
|
398 |
+
additional permissions on material, added by you to a covered work,
|
399 |
+
for which you have or can give appropriate copyright permission.
|
400 |
+
|
401 |
+
Notwithstanding any other provision of this License, for material you
|
402 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
403 |
+
that material) supplement the terms of this License with terms:
|
404 |
+
|
405 |
+
a) Disclaiming warranty or limiting liability differently from the
|
406 |
+
terms of sections 15 and 16 of this License; or
|
407 |
+
|
408 |
+
b) Requiring preservation of specified reasonable legal notices or
|
409 |
+
author attributions in that material or in the Appropriate Legal
|
410 |
+
Notices displayed by works containing it; or
|
411 |
+
|
412 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
413 |
+
requiring that modified versions of such material be marked in
|
414 |
+
reasonable ways as different from the original version; or
|
415 |
+
|
416 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
417 |
+
authors of the material; or
|
418 |
+
|
419 |
+
e) Declining to grant rights under trademark law for use of some
|
420 |
+
trade names, trademarks, or service marks; or
|
421 |
+
|
422 |
+
f) Requiring indemnification of licensors and authors of that
|
423 |
+
material by anyone who conveys the material (or modified versions of
|
424 |
+
it) with contractual assumptions of liability to the recipient, for
|
425 |
+
any liability that these contractual assumptions directly impose on
|
426 |
+
those licensors and authors.
|
427 |
+
|
428 |
+
All other non-permissive additional terms are considered "further
|
429 |
+
restrictions" within the meaning of section 10. If the Program as you
|
430 |
+
received it, or any part of it, contains a notice stating that it is
|
431 |
+
governed by this License along with a term that is a further
|
432 |
+
restriction, you may remove that term. If a license document contains
|
433 |
+
a further restriction but permits relicensing or conveying under this
|
434 |
+
License, you may add to a covered work material governed by the terms
|
435 |
+
of that license document, provided that the further restriction does
|
436 |
+
not survive such relicensing or conveying.
|
437 |
+
|
438 |
+
If you add terms to a covered work in accord with this section, you
|
439 |
+
must place, in the relevant source files, a statement of the
|
440 |
+
additional terms that apply to those files, or a notice indicating
|
441 |
+
where to find the applicable terms.
|
442 |
+
|
443 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
444 |
+
form of a separately written license, or stated as exceptions;
|
445 |
+
the above requirements apply either way.
|
446 |
+
|
447 |
+
8. Termination.
|
448 |
+
|
449 |
+
You may not propagate or modify a covered work except as expressly
|
450 |
+
provided under this License. Any attempt otherwise to propagate or
|
451 |
+
modify it is void, and will automatically terminate your rights under
|
452 |
+
this License (including any patent licenses granted under the third
|
453 |
+
paragraph of section 11).
|
454 |
+
|
455 |
+
However, if you cease all violation of this License, then your
|
456 |
+
license from a particular copyright holder is reinstated (a)
|
457 |
+
provisionally, unless and until the copyright holder explicitly and
|
458 |
+
finally terminates your license, and (b) permanently, if the copyright
|
459 |
+
holder fails to notify you of the violation by some reasonable means
|
460 |
+
prior to 60 days after the cessation.
|
461 |
+
|
462 |
+
Moreover, your license from a particular copyright holder is
|
463 |
+
reinstated permanently if the copyright holder notifies you of the
|
464 |
+
violation by some reasonable means, this is the first time you have
|
465 |
+
received notice of violation of this License (for any work) from that
|
466 |
+
copyright holder, and you cure the violation prior to 30 days after
|
467 |
+
your receipt of the notice.
|
468 |
+
|
469 |
+
Termination of your rights under this section does not terminate the
|
470 |
+
licenses of parties who have received copies or rights from you under
|
471 |
+
this License. If your rights have been terminated and not permanently
|
472 |
+
reinstated, you do not qualify to receive new licenses for the same
|
473 |
+
material under section 10.
|
474 |
+
|
475 |
+
9. Acceptance Not Required for Having Copies.
|
476 |
+
|
477 |
+
You are not required to accept this License in order to receive or
|
478 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
479 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
480 |
+
to receive a copy likewise does not require acceptance. However,
|
481 |
+
nothing other than this License grants you permission to propagate or
|
482 |
+
modify any covered work. These actions infringe copyright if you do
|
483 |
+
not accept this License. Therefore, by modifying or propagating a
|
484 |
+
covered work, you indicate your acceptance of this License to do so.
|
485 |
+
|
486 |
+
10. Automatic Licensing of Downstream Recipients.
|
487 |
+
|
488 |
+
Each time you convey a covered work, the recipient automatically
|
489 |
+
receives a license from the original licensors, to run, modify and
|
490 |
+
propagate that work, subject to this License. You are not responsible
|
491 |
+
for enforcing compliance by third parties with this License.
|
492 |
+
|
493 |
+
An "entity transaction" is a transaction transferring control of an
|
494 |
+
organization, or substantially all assets of one, or subdividing an
|
495 |
+
organization, or merging organizations. If propagation of a covered
|
496 |
+
work results from an entity transaction, each party to that
|
497 |
+
transaction who receives a copy of the work also receives whatever
|
498 |
+
licenses to the work the party's predecessor in interest had or could
|
499 |
+
give under the previous paragraph, plus a right to possession of the
|
500 |
+
Corresponding Source of the work from the predecessor in interest, if
|
501 |
+
the predecessor has it or can get it with reasonable efforts.
|
502 |
+
|
503 |
+
You may not impose any further restrictions on the exercise of the
|
504 |
+
rights granted or affirmed under this License. For example, you may
|
505 |
+
not impose a license fee, royalty, or other charge for exercise of
|
506 |
+
rights granted under this License, and you may not initiate litigation
|
507 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
508 |
+
any patent claim is infringed by making, using, selling, offering for
|
509 |
+
sale, or importing the Program or any portion of it.
|
510 |
+
|
511 |
+
11. Patents.
|
512 |
+
|
513 |
+
A "contributor" is a copyright holder who authorizes use under this
|
514 |
+
License of the Program or a work on which the Program is based. The
|
515 |
+
work thus licensed is called the contributor's "contributor version".
|
516 |
+
|
517 |
+
A contributor's "essential patent claims" are all patent claims
|
518 |
+
owned or controlled by the contributor, whether already acquired or
|
519 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
520 |
+
by this License, of making, using, or selling its contributor version,
|
521 |
+
but do not include claims that would be infringed only as a
|
522 |
+
consequence of further modification of the contributor version. For
|
523 |
+
purposes of this definition, "control" includes the right to grant
|
524 |
+
patent sublicenses in a manner consistent with the requirements of
|
525 |
+
this License.
|
526 |
+
|
527 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
528 |
+
patent license under the contributor's essential patent claims, to
|
529 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
530 |
+
propagate the contents of its contributor version.
|
531 |
+
|
532 |
+
In the following three paragraphs, a "patent license" is any express
|
533 |
+
agreement or commitment, however denominated, not to enforce a patent
|
534 |
+
(such as an express permission to practice a patent or covenant not to
|
535 |
+
sue for patent infringement). To "grant" such a patent license to a
|
536 |
+
party means to make such an agreement or commitment not to enforce a
|
537 |
+
patent against the party.
|
538 |
+
|
539 |
+
If you convey a covered work, knowingly relying on a patent license,
|
540 |
+
and the Corresponding Source of the work is not available for anyone
|
541 |
+
to copy, free of charge and under the terms of this License, through a
|
542 |
+
publicly available network server or other readily accessible means,
|
543 |
+
then you must either (1) cause the Corresponding Source to be so
|
544 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
545 |
+
patent license for this particular work, or (3) arrange, in a manner
|
546 |
+
consistent with the requirements of this License, to extend the patent
|
547 |
+
license to downstream recipients. "Knowingly relying" means you have
|
548 |
+
actual knowledge that, but for the patent license, your conveying the
|
549 |
+
covered work in a country, or your recipient's use of the covered work
|
550 |
+
in a country, would infringe one or more identifiable patents in that
|
551 |
+
country that you have reason to believe are valid.
|
552 |
+
|
553 |
+
If, pursuant to or in connection with a single transaction or
|
554 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
555 |
+
covered work, and grant a patent license to some of the parties
|
556 |
+
receiving the covered work authorizing them to use, propagate, modify
|
557 |
+
or convey a specific copy of the covered work, then the patent license
|
558 |
+
you grant is automatically extended to all recipients of the covered
|
559 |
+
work and works based on it.
|
560 |
+
|
561 |
+
A patent license is "discriminatory" if it does not include within
|
562 |
+
the scope of its coverage, prohibits the exercise of, or is
|
563 |
+
conditioned on the non-exercise of one or more of the rights that are
|
564 |
+
specifically granted under this License. You may not convey a covered
|
565 |
+
work if you are a party to an arrangement with a third party that is
|
566 |
+
in the business of distributing software, under which you make payment
|
567 |
+
to the third party based on the extent of your activity of conveying
|
568 |
+
the work, and under which the third party grants, to any of the
|
569 |
+
parties who would receive the covered work from you, a discriminatory
|
570 |
+
patent license (a) in connection with copies of the covered work
|
571 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
572 |
+
for and in connection with specific products or compilations that
|
573 |
+
contain the covered work, unless you entered into that arrangement,
|
574 |
+
or that patent license was granted, prior to 28 March 2007.
|
575 |
+
|
576 |
+
Nothing in this License shall be construed as excluding or limiting
|
577 |
+
any implied license or other defenses to infringement that may
|
578 |
+
otherwise be available to you under applicable patent law.
|
579 |
+
|
580 |
+
12. No Surrender of Others' Freedom.
|
581 |
+
|
582 |
+
If conditions are imposed on you (whether by court order, agreement or
|
583 |
+
otherwise) that contradict the conditions of this License, they do not
|
584 |
+
excuse you from the conditions of this License. If you cannot convey a
|
585 |
+
covered work so as to satisfy simultaneously your obligations under this
|
586 |
+
License and any other pertinent obligations, then as a consequence you may
|
587 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
588 |
+
to collect a royalty for further conveying from those to whom you convey
|
589 |
+
the Program, the only way you could satisfy both those terms and this
|
590 |
+
License would be to refrain entirely from conveying the Program.
|
591 |
+
|
592 |
+
13. Use with the GNU Affero General Public License.
|
593 |
+
|
594 |
+
Notwithstanding any other provision of this License, you have
|
595 |
+
permission to link or combine any covered work with a work licensed
|
596 |
+
under version 3 of the GNU Affero General Public License into a single
|
597 |
+
combined work, and to convey the resulting work. The terms of this
|
598 |
+
License will continue to apply to the part which is the covered work,
|
599 |
+
but the special requirements of the GNU Affero General Public License,
|
600 |
+
section 13, concerning interaction through a network will apply to the
|
601 |
+
combination as such.
|
602 |
+
|
603 |
+
14. Revised Versions of this License.
|
604 |
+
|
605 |
+
The Free Software Foundation may publish revised and/or new versions of
|
606 |
+
the GNU General Public License from time to time. Such new versions will
|
607 |
+
be similar in spirit to the present version, but may differ in detail to
|
608 |
+
address new problems or concerns.
|
609 |
+
|
610 |
+
Each version is given a distinguishing version number. If the
|
611 |
+
Program specifies that a certain numbered version of the GNU General
|
612 |
+
Public License "or any later version" applies to it, you have the
|
613 |
+
option of following the terms and conditions either of that numbered
|
614 |
+
version or of any later version published by the Free Software
|
615 |
+
Foundation. If the Program does not specify a version number of the
|
616 |
+
GNU General Public License, you may choose any version ever published
|
617 |
+
by the Free Software Foundation.
|
618 |
+
|
619 |
+
If the Program specifies that a proxy can decide which future
|
620 |
+
versions of the GNU General Public License can be used, that proxy's
|
621 |
+
public statement of acceptance of a version permanently authorizes you
|
622 |
+
to choose that version for the Program.
|
623 |
+
|
624 |
+
Later license versions may give you additional or different
|
625 |
+
permissions. However, no additional obligations are imposed on any
|
626 |
+
author or copyright holder as a result of your choosing to follow a
|
627 |
+
later version.
|
628 |
+
|
629 |
+
15. Disclaimer of Warranty.
|
630 |
+
|
631 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
632 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
633 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
634 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
635 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
636 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
637 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
638 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
639 |
+
|
640 |
+
16. Limitation of Liability.
|
641 |
+
|
642 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
643 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
644 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
645 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
646 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
647 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
648 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
649 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
650 |
+
SUCH DAMAGES.
|
651 |
+
|
652 |
+
17. Interpretation of Sections 15 and 16.
|
653 |
+
|
654 |
+
If the disclaimer of warranty and limitation of liability provided
|
655 |
+
above cannot be given local legal effect according to their terms,
|
656 |
+
reviewing courts shall apply local law that most closely approximates
|
657 |
+
an absolute waiver of all civil liability in connection with the
|
658 |
+
Program, unless a warranty or assumption of liability accompanies a
|
659 |
+
copy of the Program in return for a fee.
|
660 |
|
lib/vendor/lessphp/README
CHANGED
@@ -1,18 +1,16 @@
|
|
1 |
-
lessphp v0.
|
2 |
-
http://leafo.net/lessphp
|
3 |
-
========================================
|
4 |
|
5 |
-
lessphp is a compiler for LESS written in php.
|
|
|
6 |
|
7 |
-
|
8 |
-
How to use in your php project
|
9 |
-
========================================
|
10 |
|
11 |
Copy less.inc.php to your include directory and include it into your project.
|
12 |
|
13 |
There are a few ways to interface with the compiler. The easiest is to have it
|
14 |
compile a LESS file when the page is requested. The static function
|
15 |
-
less::ccompile
|
16 |
is newer than the output file.
|
17 |
|
18 |
try {
|
@@ -38,10 +36,7 @@ In addition to loading from file, you can also parse from a string like so:
|
|
38 |
$lesscode = 'body { ... }';
|
39 |
$out = $lc->parse($lesscode);
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
How to use from the command line
|
44 |
-
========================================
|
45 |
|
46 |
An additional script has been included to use the compiler from the command
|
47 |
line. In the simplest invocation, you specify an input file and the compiled
|
@@ -49,7 +44,7 @@ css is written to standard out:
|
|
49 |
|
50 |
~> plessc input.less > output.css
|
51 |
|
52 |
-
Using the -r
|
53 |
the argument is left off, from standard in:
|
54 |
|
55 |
~> plessc -r "my less code here"
|
@@ -62,5 +57,3 @@ compile as needed to the output file
|
|
62 |
Errors from watch mode are written to standard out.
|
63 |
|
64 |
|
65 |
-
|
66 |
-
|
1 |
+
# lessphp v0.2.0
|
2 |
+
#### <http://leafo.net/lessphp>
|
|
|
3 |
|
4 |
+
`lessphp` is a compiler for LESS written in php.
|
5 |
+
For a complete description of the language see <http://leafo.net/lessphp/docs/>
|
6 |
|
7 |
+
### How to use in your php project
|
|
|
|
|
8 |
|
9 |
Copy less.inc.php to your include directory and include it into your project.
|
10 |
|
11 |
There are a few ways to interface with the compiler. The easiest is to have it
|
12 |
compile a LESS file when the page is requested. The static function
|
13 |
+
`less::ccompile`, checked compile, will compile the input LESS file only when it
|
14 |
is newer than the output file.
|
15 |
|
16 |
try {
|
36 |
$lesscode = 'body { ... }';
|
37 |
$out = $lc->parse($lesscode);
|
38 |
|
39 |
+
### How to use from the command line
|
|
|
|
|
|
|
40 |
|
41 |
An additional script has been included to use the compiler from the command
|
42 |
line. In the simplest invocation, you specify an input file and the compiled
|
44 |
|
45 |
~> plessc input.less > output.css
|
46 |
|
47 |
+
Using the -r flag, you can specify LESS code directly as an argument or, if
|
48 |
the argument is left off, from standard in:
|
49 |
|
50 |
~> plessc -r "my less code here"
|
57 |
Errors from watch mode are written to standard out.
|
58 |
|
59 |
|
|
|
|
lib/vendor/lessphp/docs/docs.html
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
</head>
|
11 |
<body>
|
12 |
|
13 |
-
<h1>Documentation - lessphp v0.
|
14 |
<div class="content">
|
15 |
|
16 |
<ul id="nav">
|
@@ -25,19 +25,20 @@
|
|
25 |
<ul><li><a href="#import">Import Statement</a></li></ul>
|
26 |
<ul><li><a href="#strings">String Mixins</a></li></ul>
|
27 |
<ul><li><a href="#misc">Miscellaneous</a></li></ul>
|
|
|
28 |
</li>
|
29 |
<li><a href="#interface">The Interface</a></li>
|
30 |
</ul>
|
31 |
-
|
32 |
-
<p
|
33 |
-
|
34 |
-
a
|
35 |
-
|
36 |
-
</p>
|
37 |
|
38 |
<a name="start"></a>
|
39 |
<h2>Getting Started</h2>
|
40 |
<p>Download the latest version of <strong>lessphp</strong> <a href="http://leafo.net/lessphp/">here</a>.</p>
|
|
|
41 |
|
42 |
</div>
|
43 |
|
@@ -84,13 +85,14 @@ pre {
|
|
84 |
with number and color value types.<p>
|
85 |
|
86 |
<p>Operations on units will keep the unit of the rightmost value,
|
87 |
-
unless it is unit-less, then
|
88 |
|
89 |
<pre class="code">body {
|
90 |
color: #001 + #abc; // evaulates to #aabbdd:
|
91 |
width: 3430px + 22; // evaluates to 3452px;
|
92 |
margin: (1.5em / 2) + 2px; // evaluates to 2.85px;
|
93 |
margin: 20 + 2px; // evaluates to 22px;
|
|
|
94 |
}</pre>
|
95 |
|
96 |
<p>It is important to notice that in the example above the output will print the margin property twice.
|
@@ -253,7 +255,7 @@ body {
|
|
253 |
|
254 |
#something {
|
255 |
@what: 200;
|
256 |
-
|
257 |
}</pre>
|
258 |
|
259 |
<p>In the output, <code>body .class</code> has width set to 5, and <code>#something</code> has width set to 201. It appears from that result that
|
@@ -270,14 +272,14 @@ body {
|
|
270 |
the chain of dereferencing.</p>
|
271 |
|
272 |
|
273 |
-
|
274 |
-
|
275 |
-
<
|
276 |
-
<
|
277 |
-
<
|
278 |
-
<b>
|
279 |
-
|
280 |
-
</
|
281 |
|
282 |
</div>
|
283 |
|
@@ -328,12 +330,16 @@ If you need more control then you can make your own instance of <code>lessc</cod
|
|
328 |
import directory</p>
|
329 |
|
330 |
|
|
|
|
|
|
|
|
|
331 |
|
332 |
<br />
|
333 |
<br />
|
334 |
<hr />
|
335 |
<p class="foot">
|
336 |
-
<a href="http://leafo.net/lessphp/">http://leafo.net/lessphp</a> - Last updated
|
337 |
|
338 |
</div>
|
339 |
|
10 |
</head>
|
11 |
<body>
|
12 |
|
13 |
+
<h1>Documentation - lessphp v0.2.0</h1>
|
14 |
<div class="content">
|
15 |
|
16 |
<ul id="nav">
|
25 |
<ul><li><a href="#import">Import Statement</a></li></ul>
|
26 |
<ul><li><a href="#strings">String Mixins</a></li></ul>
|
27 |
<ul><li><a href="#misc">Miscellaneous</a></li></ul>
|
28 |
+
<ul><li><a href="#differences">Differences from Ruby LESS</a></li></ul>
|
29 |
</li>
|
30 |
<li><a href="#interface">The Interface</a></li>
|
31 |
</ul>
|
32 |
+
|
33 |
+
<p><strong>lessphp</strong> is a compiler that generates css from a small superset language that adds
|
34 |
+
many additional features seen in other languages. It is based off an original Ruby implementation
|
35 |
+
called <a href="http://lesscss.org/">LESS</a>. For the most part, <strong>lessphp</strong> is syntactically
|
36 |
+
compatible with LESS, with the exception of a few things noted below.</p>
|
|
|
37 |
|
38 |
<a name="start"></a>
|
39 |
<h2>Getting Started</h2>
|
40 |
<p>Download the latest version of <strong>lessphp</strong> <a href="http://leafo.net/lessphp/">here</a>.</p>
|
41 |
+
<p>You can also find the latest development version in the <a href="http://github.com/leafo/lessphp">git repository</a>.</p>
|
42 |
|
43 |
</div>
|
44 |
|
85 |
with number and color value types.<p>
|
86 |
|
87 |
<p>Operations on units will keep the unit of the rightmost value,
|
88 |
+
unless it is unit-less, then the leftmost unit will be kept for the result. See the following examples below.<p>
|
89 |
|
90 |
<pre class="code">body {
|
91 |
color: #001 + #abc; // evaulates to #aabbdd:
|
92 |
width: 3430px + 22; // evaluates to 3452px;
|
93 |
margin: (1.5em / 2) + 2px; // evaluates to 2.85px;
|
94 |
margin: 20 + 2px; // evaluates to 22px;
|
95 |
+
font-family: "Some " + "Family; // evaluates to "Some Family"
|
96 |
}</pre>
|
97 |
|
98 |
<p>It is important to notice that in the example above the output will print the margin property twice.
|
255 |
|
256 |
#something {
|
257 |
@what: 200;
|
258 |
+
body > .class;
|
259 |
}</pre>
|
260 |
|
261 |
<p>In the output, <code>body .class</code> has width set to 5, and <code>#something</code> has width set to 201. It appears from that result that
|
272 |
the chain of dereferencing.</p>
|
273 |
|
274 |
|
275 |
+
<a name="differences"></a>
|
276 |
+
<h2>Differences from Ruby LESS</h2>
|
277 |
+
<p class="important">Report missing ones <a href="http://github.com/leafo/lessphp/issues">here</a>.</p>
|
278 |
+
<ul>
|
279 |
+
<li>Arguments to mixins are separated by <code>;</code> instead of <code>,</code>.
|
280 |
+
<p><b>Rationale</b>: the value of a css property can contain commas, so by using a comma as an argument separator you limit the kinds of input you can pass to a mixin.</p>
|
281 |
+
</li>
|
282 |
+
</ul>
|
283 |
|
284 |
</div>
|
285 |
|
330 |
import directory</p>
|
331 |
|
332 |
|
333 |
+
<h2>Library Functions</h2>
|
334 |
+
<p>Functions within the compiler class that are prefixed with <code>lib_</code> are visible visible to the less
|
335 |
+
code while it is being parsed. The easiest way to add your own functions is to subclass <code>lessc</code> and insert
|
336 |
+
the implementations.</p>
|
337 |
|
338 |
<br />
|
339 |
<br />
|
340 |
<hr />
|
341 |
<p class="foot">
|
342 |
+
<a href="http://leafo.net/lessphp/">http://leafo.net/lessphp</a> - Last updated March 9th 2010</p>
|
343 |
|
344 |
</div>
|
345 |
|
lib/vendor/lessphp/docs/style.css
CHANGED
@@ -75,73 +75,6 @@ hr {
|
|
75 |
background: none;
|
76 |
}
|
77 |
|
78 |
-
.demo {
|
79 |
-
border: 1px solid #777777;
|
80 |
-
margin: 1.0em;
|
81 |
-
}
|
82 |
-
|
83 |
-
table.demo {
|
84 |
-
width: 938px;
|
85 |
-
}
|
86 |
-
|
87 |
-
div.demo {
|
88 |
-
margin-bottom: 0;
|
89 |
-
padding: 0.5em 0em;
|
90 |
-
}
|
91 |
-
|
92 |
-
.demo .input, .demo .output {
|
93 |
-
width: 50%;
|
94 |
-
padding: 0.5em;
|
95 |
-
}
|
96 |
-
|
97 |
-
.demo .output {
|
98 |
-
background: #f4f4f4;
|
99 |
-
border-left: 1px dashed #777;
|
100 |
-
}
|
101 |
-
|
102 |
-
.demo textarea {
|
103 |
-
width: 99%;
|
104 |
-
}
|
105 |
-
|
106 |
-
.demo pre {
|
107 |
-
overflow-x: auto;
|
108 |
-
white-space: pre-wrap;
|
109 |
-
white-space: -moz-pre-wrap !important;
|
110 |
-
white-space: -pre-wrap;
|
111 |
-
white-space: -o-pre-wrap;
|
112 |
-
word-wrap: break-word;
|
113 |
-
}
|
114 |
-
|
115 |
-
.demo .buttons {
|
116 |
-
text-align: right;
|
117 |
-
}
|
118 |
-
|
119 |
-
.examples {
|
120 |
-
display: none;
|
121 |
-
}
|
122 |
-
|
123 |
-
.comments {
|
124 |
-
margin: 0.0em 1.0em;
|
125 |
-
padding: 0.5em;
|
126 |
-
border: 1px solid #777777;
|
127 |
-
}
|
128 |
-
|
129 |
-
#twitter {
|
130 |
-
border: 0;
|
131 |
-
text-decoration: none;
|
132 |
-
display: block;
|
133 |
-
position: absolute;
|
134 |
-
top:4px;
|
135 |
-
left:776px;
|
136 |
-
}
|
137 |
-
|
138 |
-
#twitter:hover {
|
139 |
-
background: none;
|
140 |
-
}
|
141 |
-
|
142 |
-
#twitter img {
|
143 |
-
border: 0;
|
144 |
-
}
|
145 |
|
146 |
p.important {
|
147 |
background-color: #FBE7E7;
|
@@ -151,7 +84,6 @@ p.important {
|
|
151 |
margin: 0.5em 0.0em 0.5em 0.5em;
|
152 |
}
|
153 |
|
154 |
-
|
155 |
.info {
|
156 |
background: #ECFBE7;
|
157 |
background: #E0FAD7;
|
@@ -185,8 +117,8 @@ p.important {
|
|
185 |
.Function { color: #ffd2a7; }
|
186 |
.Type { color: #ffffb6; }
|
187 |
pre.code { font-family: monospace;
|
188 |
-
color: #f6f3e8;
|
189 |
-
background-color: #
|
190 |
background-color: #101010;
|
191 |
padding: 1.0em 4.0em;
|
192 |
margin: 1.0em;
|
@@ -200,6 +132,13 @@ pre.code u {
|
|
200 |
text-decoration: none;
|
201 |
}
|
202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
.Delimiter { color: #00a0a0; }
|
205 |
.PreProc { color: #96cbfe; }
|
75 |
background: none;
|
76 |
}
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
p.important {
|
80 |
background-color: #FBE7E7;
|
84 |
margin: 0.5em 0.0em 0.5em 0.5em;
|
85 |
}
|
86 |
|
|
|
87 |
.info {
|
88 |
background: #ECFBE7;
|
89 |
background: #E0FAD7;
|
117 |
.Function { color: #ffd2a7; }
|
118 |
.Type { color: #ffffb6; }
|
119 |
pre.code { font-family: monospace;
|
120 |
+
color: #f6f3e8;
|
121 |
+
background-color: #000000;
|
122 |
background-color: #101010;
|
123 |
padding: 1.0em 4.0em;
|
124 |
margin: 1.0em;
|
132 |
text-decoration: none;
|
133 |
}
|
134 |
|
135 |
+
code {
|
136 |
+
background-color: #E7F3FB;
|
137 |
+
color: #182F51;
|
138 |
+
font-weight: bold;
|
139 |
+
padding: 0px 2px;
|
140 |
+
}
|
141 |
+
|
142 |
|
143 |
.Delimiter { color: #00a0a0; }
|
144 |
.PreProc { color: #96cbfe; }
|
lib/vendor/lessphp/lessc.inc.php
CHANGED
@@ -1,168 +1,128 @@
|
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
-
*
|
6 |
*
|
7 |
-
*
|
8 |
-
* adapted from http://lesscss.org/docs.html
|
9 |
*
|
10 |
-
*
|
|
|
11 |
*/
|
12 |
|
13 |
-
|
14 |
-
// future todo: define type names as constants
|
15 |
-
|
16 |
-
// todo: potential problem with parse tree search order:
|
17 |
//
|
18 |
-
//
|
19 |
-
//
|
20 |
-
// moved to ault['color']; That is then seen as a second value in the list
|
21 |
-
//
|
22 |
-
// solution, enforce at least a space, } or {, or ; after match
|
23 |
-
// i can consume the spaces but not the symbols
|
24 |
-
// need more time to think about this, maybe leaving order requirement is good
|
25 |
//
|
26 |
|
27 |
-
class lessc
|
28 |
-
{
|
29 |
private $buffer;
|
30 |
-
private $
|
31 |
-
private $
|
32 |
-
private $
|
33 |
-
|
34 |
-
private $
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
);
|
|
|
41 |
|
42 |
-
// delayed
|
43 |
-
private $
|
44 |
-
|
45 |
-
// the default set of units
|
46 |
-
private $units = array(
|
47 |
-
'px', '%', 'in', 'cm', 'mm', 'em', 'ex', 'pt', 'pc', 's');
|
48 |
|
49 |
public $importDisabled = false;
|
50 |
public $importDir = '';
|
51 |
|
52 |
-
|
53 |
-
{
|
54 |
-
if ($
|
55 |
-
|
56 |
-
$this->matchString =
|
57 |
-
'('.implode('|',array_map(array($this, 'preg_quote'), array_keys($this->precedence))).')';
|
58 |
-
}
|
59 |
-
|
60 |
-
// load a css from file
|
61 |
-
public function load($fname)
|
62 |
-
{
|
63 |
-
if (!is_file($fname)) {
|
64 |
-
throw new Exception('load error: failed to find '.$fname);
|
65 |
-
}
|
66 |
-
$pi = pathinfo($fname);
|
67 |
|
68 |
-
|
69 |
-
$this->
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
$this->buffer = $this->removeComments($this->buffer);
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
87 |
}
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
97 |
}
|
98 |
|
99 |
-
//
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
// read a chunk off the head of the buffer
|
105 |
-
// chunks are separated by ; (in most cases)
|
106 |
-
private function readChunk()
|
107 |
-
{
|
108 |
-
if ($this->buffer == '') return false;
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
// blocks
|
113 |
-
// }
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
$this->keyword($name)->literal(':')->propertyValue($value)->end()->advance();
|
118 |
-
$this->append($name, $value);
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
else
|
124 |
-
return $this->compileProperty($name,
|
125 |
-
array($this->getVal($name)))."\n";
|
126 |
-
} catch (exception $ex) {
|
127 |
-
$this->undo();
|
128 |
}
|
129 |
|
130 |
-
//
|
131 |
-
|
132 |
-
$this->tags($tags);
|
133 |
-
|
134 |
-
// it can only be a function if there is one tag
|
135 |
-
if (count($tags) == 1) {
|
136 |
-
try {
|
137 |
-
$save = $this->count;
|
138 |
-
$this->argumentDef($args);
|
139 |
-
} catch (exception $ex) {
|
140 |
-
$this->count = $save;
|
141 |
-
}
|
142 |
-
}
|
143 |
-
|
144 |
-
$this->literal('{')->advance();
|
145 |
-
$this->push();
|
146 |
-
|
147 |
// move @ tags out of variable namespace!
|
148 |
foreach($tags as &$tag) {
|
149 |
-
if ($tag{0} ==
|
150 |
}
|
151 |
|
152 |
-
$this->
|
153 |
-
|
154 |
|
155 |
return true;
|
156 |
-
}
|
157 |
-
$this->
|
158 |
}
|
159 |
|
160 |
-
//
|
161 |
-
|
162 |
-
$this->
|
163 |
-
|
164 |
-
$tags = $this->multiplyTags();
|
165 |
-
|
166 |
$env = end($this->env);
|
167 |
$ctags = $env['__tags'];
|
168 |
unset($env['__tags']);
|
@@ -171,462 +131,386 @@ class lessc
|
|
171 |
if (isset($env['__args'])) {
|
172 |
foreach ($env['__args'] as $arg) {
|
173 |
if (isset($arg[1])) {
|
174 |
-
$this->prepend(
|
175 |
-
}
|
176 |
}
|
177 |
}
|
178 |
-
|
179 |
if (!empty($tags))
|
180 |
$out = $this->compileBlock($tags, $env);
|
181 |
|
182 |
$this->pop();
|
183 |
|
184 |
// make the block(s) available in the new current scope
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
$this->
|
189 |
-
|
190 |
-
|
|
|
|
|
191 |
}
|
192 |
}
|
193 |
|
194 |
return isset($out) ? $out : true;
|
195 |
-
}
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
// look for import
|
200 |
-
try {
|
201 |
-
$this->import($url, $media)->advance();
|
202 |
if ($this->importDisabled) return "/* import is disabled */\n";
|
203 |
|
204 |
$full = $this->importDir.$url;
|
205 |
-
|
206 |
if (file_exists($file = $full) || file_exists($file = $full.'.less')) {
|
207 |
-
$
|
208 |
-
|
209 |
return true;
|
210 |
}
|
211 |
|
212 |
return '@import url("'.$url.'")'.($media ? ' '.$media : '').";\n";
|
213 |
-
} catch (exception $ex) {
|
214 |
-
$this->undo();
|
215 |
}
|
216 |
|
217 |
-
// setting
|
218 |
-
|
219 |
-
$this->
|
220 |
-
$this->append('@'.$name, $value);
|
221 |
return true;
|
222 |
-
}
|
223 |
-
$this->
|
224 |
}
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
// consumer is liberal. This causes errors to be hidden
|
230 |
-
try {
|
231 |
-
$this->tags($tags, true, '>');
|
232 |
-
|
233 |
-
// move @ tags out of variable namespace
|
234 |
-
foreach($tags as &$tag) {
|
235 |
-
if ($tag{0} == "@") $tag[0] = "%";
|
236 |
-
}
|
237 |
-
|
238 |
-
// look for arguments
|
239 |
-
$save = $this->count;
|
240 |
-
try {
|
241 |
-
$this->argumentValues($argv);
|
242 |
-
} catch (exception $ex) { $this->count = $save; }
|
243 |
-
|
244 |
-
$this->end()->advance();
|
245 |
-
|
246 |
-
// find the final environment
|
247 |
-
$env = $this->get(array_shift($tags));
|
248 |
-
|
249 |
-
while ($sub = array_shift($tags)) {
|
250 |
-
if (isset($env[$sub])) // todo add a type check for environment
|
251 |
-
$env = $env[$sub];
|
252 |
-
else {
|
253 |
-
$env = null;
|
254 |
-
break;
|
255 |
-
}
|
256 |
-
}
|
257 |
-
|
258 |
if ($env == null) return true;
|
259 |
|
260 |
// if we have arguments then insert them
|
261 |
if (!empty($env['__args'])) {
|
262 |
foreach($env['__args'] as $arg) {
|
263 |
-
$
|
264 |
$value = is_array($argv) ? array_shift($argv) : null;
|
265 |
// copy default value if there isn't one supplied
|
266 |
-
if ($value == null && isset($arg[1]))
|
267 |
$value = $arg[1];
|
268 |
|
269 |
-
// if ($value == null) continue; // don't define so it can search up
|
270 |
|
271 |
// create new entry if var doesn't exist in scope
|
272 |
-
if (isset($env[
|
273 |
-
array_unshift($env[
|
274 |
} else {
|
275 |
// new element
|
276 |
-
$env[
|
277 |
}
|
278 |
}
|
279 |
-
}
|
280 |
|
281 |
-
// set all properties
|
282 |
ob_start();
|
|
|
283 |
foreach ($env as $name => $value) {
|
284 |
-
//
|
285 |
-
if (
|
286 |
-
|
287 |
-
|
288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
while ($tval = array_shift($value))
|
295 |
-
$this->append($name, $tval);
|
296 |
-
} else
|
297 |
-
$this->set($name, $value);
|
298 |
-
}
|
299 |
}
|
300 |
|
301 |
return ob_get_clean();
|
302 |
-
}
|
303 |
-
|
304 |
-
// ignore spare ;
|
305 |
-
try {
|
306 |
-
$this->literal(';')->advance();
|
307 |
-
return true;
|
308 |
-
} catch (exception $ex) { $this->undo(); }
|
309 |
-
|
310 |
-
// something failed
|
311 |
-
// print_r($this->env);
|
312 |
-
$this->match("(.*?)(\n|$)", $m);
|
313 |
-
throw new exception('Failed to parse line '.$this->line."\nOffending line: ".$m[1]);
|
314 |
-
}
|
315 |
-
|
316 |
-
|
317 |
-
/**
|
318 |
-
* consume functions
|
319 |
-
*
|
320 |
-
* they return instance of class so they can be chained
|
321 |
-
* any return vals are put into referenced arguments
|
322 |
-
*/
|
323 |
-
|
324 |
-
// look for an import statement on the head of the buffer
|
325 |
-
private function import(&$url, &$media)
|
326 |
-
{
|
327 |
-
$this->literal('@import');
|
328 |
-
$save = $this->count;
|
329 |
-
try {
|
330 |
-
// todo: merge this with the keyword url('')
|
331 |
-
$this->literal('url(')->string($url)->literal(')');
|
332 |
-
} catch (exception $ex) {
|
333 |
-
$this->count = $save;
|
334 |
-
$this->string($url);
|
335 |
}
|
336 |
|
337 |
-
|
|
|
338 |
|
339 |
-
return
|
340 |
}
|
341 |
|
342 |
-
|
343 |
-
{
|
344 |
-
|
345 |
-
$this->literal('"', true);
|
346 |
-
$delim = '"';
|
347 |
-
} catch (exception $ex) {
|
348 |
-
$this->literal("'", true);
|
349 |
-
$delim = "'";
|
350 |
-
}
|
351 |
-
|
352 |
-
$this->to($delim, $string);
|
353 |
|
354 |
-
|
|
|
355 |
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
}
|
368 |
|
369 |
-
return $
|
370 |
}
|
371 |
|
372 |
-
//
|
373 |
-
|
374 |
-
|
375 |
-
$this->literal('(');
|
376 |
|
377 |
-
|
378 |
-
|
379 |
-
try {
|
380 |
-
$this->propertyValue($values[])->literal(';');
|
381 |
-
} catch (exception $ex) { break; }
|
382 |
}
|
383 |
-
|
384 |
-
$this->literal(')');
|
385 |
-
$args = $values;
|
386 |
|
387 |
-
return
|
388 |
-
}
|
389 |
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
$this->literal('(');
|
394 |
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
$values[] = $arg;
|
407 |
-
$this->literal($delim);
|
408 |
-
} catch (exception $ex) {
|
409 |
-
break;
|
410 |
-
}
|
411 |
}
|
412 |
|
413 |
-
$this->
|
414 |
-
|
415 |
-
|
416 |
-
return $this;
|
417 |
}
|
418 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
while (1) {
|
425 |
-
$this->tag($tmp, $simple);
|
426 |
-
$tags[] = trim($tmp);
|
427 |
|
428 |
-
|
429 |
-
|
|
|
|
|
|
|
|
|
|
|
430 |
}
|
|
|
431 |
|
432 |
-
return $
|
433 |
}
|
434 |
|
435 |
-
//
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
$
|
442 |
-
|
443 |
-
|
|
|
444 |
|
445 |
-
|
446 |
-
if (!$this->match('(['.$chars.'0-9]['.$chars.']*)', $m))
|
447 |
-
throw new exception('parse error: failed to parse tag');
|
448 |
|
449 |
-
|
450 |
|
451 |
-
|
|
|
452 |
}
|
453 |
|
454 |
-
//
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
if ((strlen($what) == 1 && $this->count < strlen($this->buffer) && $what != $this->buffer{$this->count}) ||
|
459 |
-
!$this->match($this->preg_quote($what), $m))
|
460 |
-
{
|
461 |
-
throw new
|
462 |
-
Exception('parse error: failed to prase literal '.$what);
|
463 |
-
}
|
464 |
-
return $this;
|
465 |
-
}
|
466 |
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
|
|
|
|
|
|
|
|
471 |
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
|
|
|
|
|
|
477 |
}
|
478 |
|
479 |
-
|
480 |
-
|
481 |
-
$value = $this->compressValues($out, ', ');
|
482 |
-
}
|
483 |
|
484 |
-
|
485 |
-
|
|
|
486 |
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
|
493 |
-
|
494 |
-
|
495 |
-
|
|
|
|
|
496 |
|
497 |
-
|
|
|
|
|
|
|
498 |
}
|
499 |
|
500 |
-
return
|
501 |
}
|
502 |
|
503 |
-
//
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
$this->literal('(')->expression($exp)->literal(')');
|
508 |
-
$lhs = $exp;
|
509 |
-
} catch (exception $ex) {
|
510 |
-
$this->value($lhs);
|
511 |
-
}
|
512 |
-
$result = $this->expHelper($lhs, 0);
|
513 |
-
return $this;
|
514 |
-
}
|
515 |
|
|
|
|
|
|
|
516 |
|
517 |
-
|
518 |
-
private function expHelper($lhs, $minP)
|
519 |
-
{
|
520 |
-
// while there is an operator and the precedence is greater or equal to min
|
521 |
-
while ($this->match($this->matchString, $m) && $this->precedence[$m[1]] >= $minP) {
|
522 |
-
// check for subexp
|
523 |
-
try {
|
524 |
-
$this->literal('(')->expression($exp)->literal(')');
|
525 |
-
$rhs = $exp;
|
526 |
-
} catch (exception $ex) {
|
527 |
-
$this->value($rhs);
|
528 |
-
}
|
529 |
|
530 |
-
|
531 |
-
if ($
|
532 |
-
$
|
|
|
|
|
|
|
533 |
}
|
534 |
-
|
535 |
-
// todo: find a way to precalculate non-delayed types
|
536 |
-
if (in_array($rhs[0], $this->dtypes) || in_array($lhs[0], $this->dtypes))
|
537 |
-
$lhs = array('expression', $m[1], $lhs, $rhs);
|
538 |
-
else
|
539 |
-
$lhs = $this->evaluate($m[1], $lhs, $rhs);
|
540 |
}
|
541 |
-
return $lhs;
|
542 |
-
}
|
543 |
-
|
544 |
-
// consume a css value:
|
545 |
-
// a keyword
|
546 |
-
// a variable (includes accessor);
|
547 |
-
// a color
|
548 |
-
// a unit (em, px, pt, %, mm), can also have no unit 4px + 3;
|
549 |
-
// a string
|
550 |
-
private function value(&$val)
|
551 |
-
{
|
552 |
-
try {
|
553 |
-
return $this->unit($val);
|
554 |
-
} catch (exception $ex) { /* $this->undo(); */ }
|
555 |
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
$this->accessor($a);
|
561 |
-
$tmp = $this->get($a[0]); // get env
|
562 |
-
$val = end($tmp[$a[1]]); // get latest var
|
563 |
-
|
564 |
-
return $this;
|
565 |
-
} catch (exception $ex) { $this->count = $save; /* $this->undo(); */ }
|
566 |
-
|
567 |
-
try {
|
568 |
-
return $this->color($val);
|
569 |
-
} catch (exception $ex) { /* $this->undo(); */ }
|
570 |
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
|
575 |
-
|
|
|
|
|
|
|
576 |
|
577 |
-
|
578 |
-
|
|
|
|
|
579 |
|
580 |
-
// a
|
581 |
-
|
582 |
-
|
583 |
-
$this->
|
584 |
-
|
585 |
-
|
586 |
-
}
|
|
|
|
|
|
|
587 |
|
588 |
-
|
589 |
-
$this->
|
590 |
-
|
591 |
-
|
592 |
-
} catch (exception $ex) { /* $this->undo(); */ }
|
593 |
|
|
|
|
|
|
|
594 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
595 |
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
|
|
|
|
|
|
|
|
600 |
|
601 |
-
|
602 |
-
|
|
|
|
|
603 |
|
604 |
-
|
605 |
-
|
|
|
606 |
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
612 |
|
613 |
-
|
614 |
-
throw new exception('parse error: failed to consume unit');
|
615 |
}
|
616 |
|
617 |
-
|
618 |
-
if (!isset($m[3])) $m[3] = 'number';
|
619 |
-
|
620 |
-
$unit = array($m[3], $m[1]);
|
621 |
-
return $this;
|
622 |
}
|
623 |
|
624 |
-
//
|
625 |
-
|
626 |
-
private function color(&$out)
|
627 |
-
{
|
628 |
$color = array('color');
|
629 |
-
|
|
|
630 |
if (isset($m[3])) {
|
631 |
$num = $m[3];
|
632 |
$width = 16;
|
@@ -640,148 +524,213 @@ class lessc
|
|
640 |
$t = $num % $width;
|
641 |
$num /= $width;
|
642 |
|
643 |
-
// todo: this is retarded
|
644 |
$color[$i] = $t * (256/$width) + $t * floor(16/$width);
|
645 |
-
}
|
|
|
|
|
|
|
|
|
646 |
|
647 |
-
|
648 |
-
|
649 |
-
try {
|
650 |
-
$this->literal('rgb');
|
651 |
-
|
652 |
-
try {
|
653 |
-
$this->literal('a');
|
654 |
-
$count = 4;
|
655 |
-
} catch (exception $ex) {
|
656 |
-
$count = 3;
|
657 |
-
}
|
658 |
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
$this->unit($color[], array('%'));
|
664 |
-
if ($i != $count) $this->literal(',');
|
665 |
-
|
666 |
-
if ($color[$i][0] == '%')
|
667 |
-
$color[$i] = 255 * ($color[$i][1] / 100);
|
668 |
-
else
|
669 |
-
$color[$i] = $color[$i][1];
|
670 |
-
}
|
671 |
|
672 |
-
|
|
|
|
|
|
|
|
|
673 |
|
674 |
-
|
675 |
-
|
676 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
|
678 |
-
|
|
|
|
|
|
|
|
|
|
|
679 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
680 |
}
|
681 |
|
682 |
-
$
|
683 |
-
return
|
684 |
}
|
685 |
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
690 |
}
|
691 |
|
692 |
-
|
693 |
-
{
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
|
|
|
|
|
|
|
|
706 |
}
|
707 |
}
|
|
|
|
|
708 |
|
709 |
-
|
|
|
710 |
|
711 |
-
|
|
|
|
|
712 |
|
713 |
-
|
714 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
715 |
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
|
|
720 |
|
721 |
-
$
|
722 |
-
return
|
723 |
}
|
724 |
|
725 |
-
//
|
726 |
-
|
727 |
-
|
728 |
-
if (
|
729 |
-
|
730 |
}
|
731 |
-
|
732 |
-
$word = $m[1];
|
733 |
-
return $this;
|
734 |
}
|
735 |
|
736 |
-
//
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
throw new exception('parse error: failed to consume to '.$what);
|
741 |
|
742 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
743 |
|
744 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
745 |
}
|
746 |
|
|
|
|
|
|
|
|
|
747 |
|
748 |
-
|
749 |
-
* compile functions turn data into css code
|
750 |
-
*/
|
751 |
-
private function compileBlock($rtags, $env)
|
752 |
-
{
|
753 |
// don't render functions
|
|
|
|
|
754 |
foreach ($rtags as $i => $tag) {
|
755 |
if (preg_match('/( |^)%/', $tag))
|
756 |
unset($rtags[$i]);
|
757 |
}
|
|
|
758 |
if (empty($rtags)) return '';
|
759 |
|
760 |
$props = 0;
|
761 |
-
// print all the properties
|
762 |
ob_start();
|
763 |
foreach ($env as $name => $value) {
|
764 |
// todo: change this, poor hack
|
765 |
// make a better name storage system!!! (value types are fine)
|
766 |
// but.. don't render special properties (blocks, vars, metadata)
|
767 |
-
if (isset($value[0]) && $name{0} !=
|
768 |
echo $this->compileProperty($name, $value, 1)."\n";
|
769 |
$props++;
|
770 |
}
|
771 |
}
|
772 |
$list = ob_get_clean();
|
773 |
|
774 |
-
if ($props == 0) return
|
775 |
|
776 |
// do some formatting
|
777 |
if ($props == 1) $list = ' '.trim($list).' ';
|
778 |
return implode(", ", $rtags).' {'.($props > 1 ? "\n" : '').
|
779 |
$list."}\n";
|
|
|
780 |
}
|
781 |
|
782 |
-
|
783 |
-
|
784 |
-
// compile all repeated properties
|
785 |
foreach ($value as $v)
|
786 |
$props[] = str_repeat(' ', $level).
|
787 |
$name.':'.$this->compileValue($v).';';
|
@@ -789,25 +738,26 @@ class lessc
|
|
789 |
return implode("\n", $props);
|
790 |
}
|
791 |
|
792 |
-
|
793 |
-
|
794 |
-
switch ($value[0]) {
|
795 |
case 'list':
|
|
|
|
|
796 |
return implode($value[1], array_map(array($this, 'compileValue'), $value[2]));
|
|
|
|
|
|
|
|
|
|
|
797 |
case 'expression':
|
|
|
|
|
|
|
798 |
return $this->compileValue($this->evaluate($value[1], $value[2], $value[3]));
|
799 |
-
|
800 |
-
case 'variable':
|
801 |
-
$tmp = $this->compileValue(
|
802 |
-
$this->getVal($value[1],
|
803 |
-
$this->pushName($value[1]))
|
804 |
-
);
|
805 |
-
$this->popName();
|
806 |
-
|
807 |
-
return $tmp;
|
808 |
-
|
809 |
case 'string':
|
810 |
-
//
|
|
|
|
|
811 |
$replace = array();
|
812 |
if (preg_match_all('/{(@[\w-_][0-9\w-_]*)}/', $value[1], $m)) {
|
813 |
foreach($m[1] as $name) {
|
@@ -815,177 +765,310 @@ class lessc
|
|
815 |
$replace[$name] = $this->compileValue(array('variable', $name));
|
816 |
}
|
817 |
}
|
818 |
-
foreach ($replace as $var=>$val)
|
819 |
-
|
|
|
|
|
|
|
|
|
|
|
820 |
|
821 |
return $value[1];
|
822 |
-
|
823 |
case 'color':
|
824 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
825 |
|
826 |
-
|
827 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
828 |
|
829 |
-
|
830 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
831 |
|
832 |
-
|
|
|
|
|
833 |
return $value[1].$value[0];
|
834 |
}
|
835 |
}
|
836 |
|
|
|
|
|
|
|
837 |
|
838 |
-
|
839 |
-
|
840 |
-
if (
|
841 |
-
return 'rgba('.$c[1].','.$c[2].','.$c[3].','.$c[4].')';
|
842 |
-
}
|
843 |
-
|
844 |
-
$out = '#';
|
845 |
-
foreach (range(1,3) as $i)
|
846 |
-
$out .= ($c[$i] < 16 ? '0' : '').dechex($c[$i]);
|
847 |
return $out;
|
848 |
}
|
849 |
|
|
|
|
|
|
|
|
|
|
|
|
|
850 |
|
851 |
-
|
852 |
-
|
853 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
854 |
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
{
|
859 |
-
$pushed = 0;
|
860 |
-
// figure out what expressions and variables are equal to
|
861 |
-
while (in_array($lft[0], $this->dtypes))
|
862 |
-
{
|
863 |
-
if ($lft[0] == 'expression')
|
864 |
-
$lft = $this->evaluate($lft[1], $lft[2], $lft[3]);
|
865 |
-
else if ($lft[0] == 'variable') {
|
866 |
-
$lft = $this->getVal($lft[1], $this->pushName($lft[1]), array('number', 0));
|
867 |
-
$pushed++;
|
868 |
-
}
|
869 |
|
870 |
-
|
871 |
-
|
|
|
|
|
872 |
|
873 |
-
while (in_array($
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
$rgt = $this->getVal($rgt[1], $this->pushName($rgt[1]), array('number', 0));
|
879 |
$pushed++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
880 |
}
|
881 |
}
|
|
|
882 |
while ($pushed != 0) { $this->popName(); $pushed--; }
|
|
|
|
|
883 |
|
884 |
-
|
885 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
886 |
}
|
887 |
|
888 |
-
if ($
|
889 |
-
return $this->op_color_number($op, $
|
890 |
}
|
891 |
|
892 |
-
if ($
|
893 |
-
return $this->op_number_color($op, $
|
894 |
}
|
895 |
|
896 |
-
//
|
897 |
-
|
898 |
-
|
|
|
899 |
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
|
904 |
-
|
905 |
-
|
906 |
-
else $type = $rgt[0];
|
907 |
|
908 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
909 |
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
$
|
916 |
-
break;
|
917 |
-
case '-':
|
918 |
-
$num[] = $lft[1] - $rgt[1];
|
919 |
-
break;
|
920 |
-
case '/';
|
921 |
-
if ($rgt[1] == 0) throw new exception("parse error: can't divide by zero");
|
922 |
-
$num[] = $lft[1] / $rgt[1];
|
923 |
-
break;
|
924 |
-
default:
|
925 |
-
throw new exception('parse error: number op number failed on op '.$op);
|
926 |
}
|
927 |
|
928 |
-
return $
|
929 |
}
|
930 |
|
931 |
-
|
932 |
-
{
|
933 |
if ($op == '+' || $op = '*') {
|
934 |
return $this->op_color_number($op, $rgt, $lft);
|
935 |
}
|
936 |
}
|
937 |
|
938 |
-
|
939 |
-
{
|
940 |
if ($rgt[0] == '%') $rgt[1] /= 100;
|
941 |
|
942 |
-
return $this->op_color_color($op, $lft,
|
943 |
-
|
944 |
}
|
945 |
|
946 |
-
|
947 |
-
|
948 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
949 |
|
950 |
-
|
|
|
|
|
|
|
|
|
|
|
951 |
case '+':
|
952 |
-
$
|
953 |
-
|
954 |
-
$newc[] = $lft[3] + $rgt[3];
|
955 |
-
break;
|
956 |
case '*':
|
957 |
-
$
|
958 |
-
|
959 |
-
$newc[] = $lft[3] * $rgt[3];
|
960 |
-
break;
|
961 |
case '-':
|
962 |
-
$
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
$
|
970 |
-
$newc[] = $lft[2] / $rgt[2];
|
971 |
-
$newc[] = $lft[3] / $rgt[3];
|
972 |
break;
|
973 |
default:
|
974 |
-
throw new exception('parse error:
|
975 |
}
|
976 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
977 |
}
|
978 |
|
|
|
|
|
|
|
|
|
979 |
|
980 |
-
|
981 |
-
|
982 |
-
|
|
|
|
|
|
|
|
|
|
|
983 |
|
984 |
-
//
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
989 |
if (empty($env)) $env = $this->env;
|
990 |
|
991 |
for ($i = count($env) - 1; $i >= 0; $i--)
|
@@ -994,12 +1077,10 @@ class lessc
|
|
994 |
return null;
|
995 |
}
|
996 |
|
997 |
-
|
998 |
// get the most recent value of a variable
|
999 |
// return default if it isn't found
|
1000 |
// $skip is number of vars to skip
|
1001 |
-
|
1002 |
-
{
|
1003 |
$val = $this->get($name);
|
1004 |
if ($val == null) return $default;
|
1005 |
|
@@ -1023,9 +1104,28 @@ class lessc
|
|
1023 |
return end($val);
|
1024 |
}
|
1025 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1026 |
// merge a block into the current env
|
1027 |
-
|
1028 |
-
{
|
1029 |
// if the current block isn't there then just set
|
1030 |
$top =& $this->env[count($this->env) - 1];
|
1031 |
if (!isset($top[$name])) return $this->set($name, $value);
|
@@ -1038,73 +1138,126 @@ class lessc
|
|
1038 |
}
|
1039 |
}
|
1040 |
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
$this->env[count($this->env) - 1][$name] = $value;
|
1045 |
-
}
|
1046 |
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1051 |
}
|
1052 |
|
1053 |
-
|
1054 |
-
|
1055 |
-
{
|
1056 |
-
if (isset($this->env[count($this->env) - 1][$name]))
|
1057 |
-
array_unshift($this->env[count($this->env) - 1][$name], $value);
|
1058 |
-
else $this->append($name, $value);
|
1059 |
}
|
1060 |
|
1061 |
-
//
|
1062 |
-
|
1063 |
-
{
|
1064 |
-
$
|
1065 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1066 |
}
|
1067 |
|
1068 |
-
// pop environment off the stack
|
1069 |
-
private function pop()
|
1070 |
-
{
|
1071 |
-
if ($this->level == 1)
|
1072 |
-
throw new exception('parse error: unexpected end of block');
|
1073 |
|
1074 |
-
|
1075 |
-
|
|
|
|
|
|
|
|
|
1076 |
}
|
1077 |
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
|
|
|
|
|
|
1081 |
|
1082 |
-
//
|
1083 |
-
|
|
|
1084 |
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
$
|
1089 |
-
$count = isset($count[$name]) ? $count[$name] : 0;
|
1090 |
|
1091 |
-
$this->
|
1092 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1093 |
}
|
1094 |
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
|
|
1098 |
}
|
1099 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1100 |
|
1101 |
// remove comments from $text
|
1102 |
// todo: make it work for all functions, not just url
|
1103 |
-
|
1104 |
-
|
1105 |
$out = '';
|
1106 |
|
1107 |
-
while (!empty($text) &&
|
1108 |
preg_match('/^(.*?)("|\'|\/\/|\/\*|url\(|$)/is', $text, $m))
|
1109 |
{
|
1110 |
if (!trim($text)) break;
|
@@ -1113,7 +1266,7 @@ class lessc
|
|
1113 |
$text = substr($text, strlen($m[0]));
|
1114 |
|
1115 |
switch ($m[2]) {
|
1116 |
-
case 'url(':
|
1117 |
preg_match('/^(.*?)(\)|$)/is', $text, $inner);
|
1118 |
$text = substr($text, strlen($inner[0]));
|
1119 |
$out .= $m[2].$inner[1].$inner[2];
|
@@ -1136,111 +1289,13 @@ class lessc
|
|
1136 |
}
|
1137 |
}
|
1138 |
|
1139 |
-
$this->count = 0;
|
1140 |
return $out;
|
1141 |
}
|
1142 |
|
1143 |
|
1144 |
-
// match text from the head while skipping $count characters
|
1145 |
-
// advances the temp counter if it succeeds
|
1146 |
-
private function match($regex, &$out, $eatWhitespace = true)
|
1147 |
-
{
|
1148 |
-
// if ($this->count > 100) echo '-- '.$this->count."\n";
|
1149 |
-
$r = '/^.{'.$this->count.'}'.$regex.($eatWhitespace ? '\s*' : '').'/is';
|
1150 |
-
if (preg_match($r, $this->buffer, $out)) {
|
1151 |
-
$this->count = strlen($out[0]);
|
1152 |
-
return true;
|
1153 |
-
}
|
1154 |
-
|
1155 |
-
return false;
|
1156 |
-
|
1157 |
-
}
|
1158 |
-
|
1159 |
-
private function peek($regex, &$out = null)
|
1160 |
-
{
|
1161 |
-
return preg_match('/^.{'.$this->count.'}'.$regex.'/is', $this->buffer, $out);
|
1162 |
-
}
|
1163 |
-
|
1164 |
-
|
1165 |
-
// compress a list of values into a single type
|
1166 |
-
// if the list contains one thing, then return that thing
|
1167 |
-
private function compressValues($values, $delim = ' ')
|
1168 |
-
{
|
1169 |
-
if (count($values) == 1) return $values[0];
|
1170 |
-
return array('list', $delim, $values);
|
1171 |
-
}
|
1172 |
-
|
1173 |
-
// make sure a color's components don't go out of bounds
|
1174 |
-
private function fixColor($c)
|
1175 |
-
{
|
1176 |
-
for ($i = 1; $i < 4; $i++) {
|
1177 |
-
if ($c[$i] < 0) $c[$i] = 0;
|
1178 |
-
if ($c[$i] > 255) $c[$i] = 255;
|
1179 |
-
$c[$i] = floor($c[$i]);
|
1180 |
-
}
|
1181 |
-
return $c;
|
1182 |
-
}
|
1183 |
-
|
1184 |
-
private function preg_quote($what)
|
1185 |
-
{
|
1186 |
-
// I don't know why it doesn't include it by default
|
1187 |
-
return preg_quote($what, '/');
|
1188 |
-
}
|
1189 |
-
|
1190 |
-
// reset all internal state to default
|
1191 |
-
private function reset()
|
1192 |
-
{
|
1193 |
-
$this->out = '';
|
1194 |
-
$this->env = array();
|
1195 |
-
$this->line = 1;
|
1196 |
-
$this->count = 0;
|
1197 |
-
}
|
1198 |
-
|
1199 |
-
// advance the buffer n places
|
1200 |
-
private function advance()
|
1201 |
-
{
|
1202 |
-
// this is probably slow
|
1203 |
-
$tmp = substr($this->buffer, 0, $this->count);
|
1204 |
-
$this->line += substr_count($tmp, "\n");
|
1205 |
-
|
1206 |
-
$this->buffer = substr($this->buffer, $this->count);
|
1207 |
-
$this->count = 0;
|
1208 |
-
}
|
1209 |
-
|
1210 |
-
// reset the temporary advance
|
1211 |
-
private function undo()
|
1212 |
-
{
|
1213 |
-
$this->count = 0;
|
1214 |
-
}
|
1215 |
-
|
1216 |
-
// find the cartesian product of all tags in stack
|
1217 |
-
private function multiplyTags($tags = array(' '), $d = null)
|
1218 |
-
{
|
1219 |
-
if ($d === null) $d = count($this->env) - 1;
|
1220 |
-
|
1221 |
-
$parents = $d == 0 ? $this->env[$d]['__tags']
|
1222 |
-
: $this->multiplyTags($this->env[$d]['__tags'], $d - 1);
|
1223 |
-
|
1224 |
-
$rtags = array();
|
1225 |
-
foreach ($parents as $p) {
|
1226 |
-
foreach ($tags as $t) {
|
1227 |
-
if ($t{0} == '@') continue; // skip functions
|
1228 |
-
$rtags[] = trim($p.($t{0} == ':' ? '' : ' ').$t);
|
1229 |
-
}
|
1230 |
-
}
|
1231 |
-
|
1232 |
-
return $rtags;
|
1233 |
-
}
|
1234 |
-
|
1235 |
-
|
1236 |
-
/**
|
1237 |
-
* static utility functions
|
1238 |
-
*/
|
1239 |
-
|
1240 |
// compile to $in to $out if $in is newer than $out
|
1241 |
// returns true when it compiles, false otherwise
|
1242 |
-
public static function ccompile($in, $out)
|
1243 |
-
{
|
1244 |
if (!is_file($out) || filemtime($in) > filemtime($out)) {
|
1245 |
$less = new lessc($in);
|
1246 |
file_put_contents($out, $less->parse());
|
@@ -1249,7 +1304,9 @@ class lessc
|
|
1249 |
|
1250 |
return false;
|
1251 |
}
|
|
|
1252 |
}
|
1253 |
|
1254 |
|
|
|
1255 |
?>
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
+
* lessphp v0.2.0
|
5 |
+
* http://leafo.net/lessphp
|
6 |
*
|
7 |
+
* LESS Css compiler, adapted from http://lesscss.org/docs.html
|
|
|
8 |
*
|
9 |
+
* Copyright 2010, Leaf Corcoran <leafot@gmail.com>
|
10 |
+
* Licensed under MIT or GPLv3, see LICENSE
|
11 |
*/
|
12 |
|
|
|
|
|
|
|
|
|
13 |
//
|
14 |
+
// investigate trouble with ^M
|
15 |
+
// fix the alpha value with color when using a percent
|
|
|
|
|
|
|
|
|
|
|
16 |
//
|
17 |
|
18 |
+
class lessc {
|
|
|
19 |
private $buffer;
|
20 |
+
private $count;
|
21 |
+
private $line;
|
22 |
+
private $expandStack;
|
23 |
+
|
24 |
+
private $env = array();
|
25 |
+
|
26 |
+
public $vPrefix = '@';
|
27 |
+
public $mPrefix = '$';
|
28 |
+
public $imPrefix = '!';
|
29 |
+
public $selfSelector = '&';
|
30 |
+
|
31 |
+
static private $precedence = array(
|
32 |
+
'+' => 0,
|
33 |
+
'-' => 0,
|
34 |
+
'*' => 1,
|
35 |
+
'/' => 1,
|
36 |
+
'%' => 1,
|
37 |
);
|
38 |
+
static private $operatorString; // regex string to match any of the operators
|
39 |
|
40 |
+
static private $dtypes = array('expression', 'variable', 'function', 'negative'); // types with delayed computation
|
41 |
+
static private $units = array(
|
42 |
+
'px', '%', 'in', 'cm', 'mm', 'em', 'ex', 'pt', 'pc', 'ms', 's', 'deg');
|
|
|
|
|
|
|
43 |
|
44 |
public $importDisabled = false;
|
45 |
public $importDir = '';
|
46 |
|
47 |
+
// compile chunk off the head of buffer
|
48 |
+
function chunk() {
|
49 |
+
if (empty($this->buffer)) return false;
|
50 |
+
$s = $this->seek();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
// a property
|
53 |
+
if ($this->keyword($key) && $this->assign() && $this->propertyValue($value) && $this->end()) {
|
54 |
+
// look for important prefix
|
55 |
+
if ($key{0} == $this->imPrefix && strlen($key) > 1) {
|
56 |
+
$key = substr($key, 1);
|
57 |
+
if ($value[0] == 'list' && $value[1] == ' ') {
|
58 |
+
$value[2][] = array('keyword', '!important');
|
59 |
+
} else {
|
60 |
+
$value = array('list', ' ', array($value, array('keyword', '!important')));
|
61 |
+
}
|
62 |
+
}
|
63 |
+
$this->append($key, $value);
|
|
|
|
|
64 |
|
65 |
+
if (count($this->env) == 1)
|
66 |
+
return $this->compileProperty($key, array($value))."\n";
|
67 |
+
else
|
68 |
+
return true;
|
69 |
+
} else {
|
70 |
+
$this->seek($s);
|
71 |
}
|
72 |
|
73 |
+
// look for special css @ directives
|
74 |
+
if (count($this->env) == 1 && $this->count < strlen($this->buffer) && $this->buffer[$this->count] == '@') {
|
75 |
+
// a font-face block
|
76 |
+
if ($this->literal('@font-face') && $this->literal('{')) {
|
77 |
+
$this->push();
|
78 |
+
$this->set('__tags', array('@font-face'));
|
79 |
+
$this->set('__dontsave', true);
|
80 |
+
return true;
|
81 |
+
} else {
|
82 |
+
$this->seek($s);
|
83 |
+
}
|
84 |
|
85 |
+
// charset
|
86 |
+
if ($this->literal('@charset') && $this->propertyValue($value) && $this->end()) {
|
87 |
+
return "@charset ".$this->compileValue($value).";\n";
|
88 |
+
} else {
|
89 |
+
$this->seek($s);
|
90 |
+
}
|
91 |
}
|
92 |
|
93 |
+
// opening abstract block
|
94 |
+
if ($this->tag($tag, true) && $this->argumentDef($args) && $this->literal('{')) {
|
95 |
+
$this->push();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
+
// move out of variable scope
|
98 |
+
if ($tag{0} == $this->vPrefix) $tag[0] = $this->mPrefix;
|
|
|
|
|
99 |
|
100 |
+
$this->set('__tags', array($tag));
|
101 |
+
if (isset($args)) $this->set('__args', $args);
|
|
|
|
|
102 |
|
103 |
+
return true;
|
104 |
+
} else {
|
105 |
+
$this->seek($s);
|
|
|
|
|
|
|
|
|
|
|
106 |
}
|
107 |
|
108 |
+
// opening css block
|
109 |
+
if ($this->tags($tags) && $this->literal('{')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
// move @ tags out of variable namespace!
|
111 |
foreach($tags as &$tag) {
|
112 |
+
if ($tag{0} == $this->vPrefix) $tag[0] = $this->mPrefix;
|
113 |
}
|
114 |
|
115 |
+
$this->push();
|
116 |
+
$this->set('__tags', $tags);
|
117 |
|
118 |
return true;
|
119 |
+
} else {
|
120 |
+
$this->seek($s);
|
121 |
}
|
122 |
|
123 |
+
// closing block
|
124 |
+
if ($this->literal('}')) {
|
125 |
+
$tags = $this->multiplyTags();
|
|
|
|
|
|
|
126 |
$env = end($this->env);
|
127 |
$ctags = $env['__tags'];
|
128 |
unset($env['__tags']);
|
131 |
if (isset($env['__args'])) {
|
132 |
foreach ($env['__args'] as $arg) {
|
133 |
if (isset($arg[1])) {
|
134 |
+
$this->prepend($this->vPrefix.$arg[0], $arg[1]);
|
135 |
+
}
|
136 |
}
|
137 |
}
|
138 |
+
|
139 |
if (!empty($tags))
|
140 |
$out = $this->compileBlock($tags, $env);
|
141 |
|
142 |
$this->pop();
|
143 |
|
144 |
// make the block(s) available in the new current scope
|
145 |
+
if (!isset($env['__dontsave'])) {
|
146 |
+
foreach ($ctags as $t) {
|
147 |
+
// if the block already exists then merge
|
148 |
+
if ($this->get($t, array(end($this->env)))) {
|
149 |
+
$this->merge($t, $env);
|
150 |
+
} else {
|
151 |
+
$this->set($t, $env);
|
152 |
+
}
|
153 |
}
|
154 |
}
|
155 |
|
156 |
return isset($out) ? $out : true;
|
157 |
+
}
|
158 |
+
|
159 |
+
// import statement
|
160 |
+
if ($this->import($url, $media)) {
|
|
|
|
|
|
|
161 |
if ($this->importDisabled) return "/* import is disabled */\n";
|
162 |
|
163 |
$full = $this->importDir.$url;
|
|
|
164 |
if (file_exists($file = $full) || file_exists($file = $full.'.less')) {
|
165 |
+
$loaded = $this->removeComments(ltrim(file_get_contents($file).";"));
|
166 |
+
$this->buffer = substr($this->buffer, 0, $this->count).$loaded.substr($this->buffer, $this->count);
|
167 |
return true;
|
168 |
}
|
169 |
|
170 |
return '@import url("'.$url.'")'.($media ? ' '.$media : '').";\n";
|
|
|
|
|
171 |
}
|
172 |
|
173 |
+
// setting variable
|
174 |
+
if ($this->variable($name) && $this->assign() && $this->propertyValue($value) && $this->end()) {
|
175 |
+
$this->append($this->vPrefix.$name, $value);
|
|
|
176 |
return true;
|
177 |
+
} else {
|
178 |
+
$this->seek($s);
|
179 |
}
|
180 |
|
181 |
+
// mixin/function expand
|
182 |
+
if ($this->tags($tags, true, '>') && ($this->argumentValues($argv) || true) && $this->end()) {
|
183 |
+
$env = $this->getEnv($tags);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
if ($env == null) return true;
|
185 |
|
186 |
// if we have arguments then insert them
|
187 |
if (!empty($env['__args'])) {
|
188 |
foreach($env['__args'] as $arg) {
|
189 |
+
$vname = $this->vPrefix.$arg[0];
|
190 |
$value = is_array($argv) ? array_shift($argv) : null;
|
191 |
// copy default value if there isn't one supplied
|
192 |
+
if ($value == null && isset($arg[1]))
|
193 |
$value = $arg[1];
|
194 |
|
195 |
+
// if ($value == null) continue; // don't define so it can search up
|
196 |
|
197 |
// create new entry if var doesn't exist in scope
|
198 |
+
if (isset($env[$vname])) {
|
199 |
+
array_unshift($env[$vname], $value);
|
200 |
} else {
|
201 |
// new element
|
202 |
+
$env[$vname] = array($value);
|
203 |
}
|
204 |
}
|
205 |
+
}
|
206 |
|
207 |
+
// set all properties
|
208 |
ob_start();
|
209 |
+
$blocks = array();
|
210 |
foreach ($env as $name => $value) {
|
211 |
+
// skip the metatdata
|
212 |
+
if (preg_match('/^__/', $name)) continue;
|
213 |
+
|
214 |
+
// if it is a block, remember it to compile after everything
|
215 |
+
// is mixed in
|
216 |
+
if (!isset($value[0]))
|
217 |
+
$blocks[] = array($name, $value);
|
218 |
+
|
219 |
+
// copy the data
|
220 |
+
// don't overwrite previous value, look in current env for name
|
221 |
+
if ($this->get($name, array(end($this->env)))) {
|
222 |
+
while ($tval = array_shift($value))
|
223 |
+
$this->append($name, $tval);
|
224 |
+
} else
|
225 |
+
$this->set($name, $value);
|
226 |
+
}
|
227 |
|
228 |
+
// render sub blocks
|
229 |
+
foreach ($blocks as $b) {
|
230 |
+
$rtags = $this->multiplyTags(array($b[0]));
|
231 |
+
echo $this->compileBlock($rtags, $b[1]);
|
|
|
|
|
|
|
|
|
|
|
232 |
}
|
233 |
|
234 |
return ob_get_clean();
|
235 |
+
} else {
|
236 |
+
$this->seek($s);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
}
|
238 |
|
239 |
+
// spare ;
|
240 |
+
if ($this->literal(';')) return true;
|
241 |
|
242 |
+
return false; // couldn't match anything, throw error
|
243 |
}
|
244 |
|
245 |
+
// recursively find the cartesian product of all tags in stack
|
246 |
+
function multiplyTags($tags = array(' '), $d = null) {
|
247 |
+
if ($d === null) $d = count($this->env) - 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
|
249 |
+
$parents = $d == 0 ? $this->env[$d]['__tags']
|
250 |
+
: $this->multiplyTags($this->env[$d]['__tags'], $d - 1);
|
251 |
|
252 |
+
$rtags = array();
|
253 |
+
foreach ($parents as $p) {
|
254 |
+
foreach ($tags as $t) {
|
255 |
+
if ($t{0} == $this->mPrefix) continue; // skip functions
|
256 |
+
$d = ' ';
|
257 |
+
if ($t{0} == ':' || $t{0} == $this->selfSelector) {
|
258 |
+
$t = ltrim($t, $this->selfSelector);
|
259 |
+
$d = '';
|
260 |
+
}
|
261 |
+
$rtags[] = trim($p.$d.$t);
|
262 |
+
}
|
263 |
}
|
264 |
|
265 |
+
return $rtags;
|
266 |
}
|
267 |
|
268 |
+
// a list of expressions
|
269 |
+
function expressionList(&$exps) {
|
270 |
+
$values = array();
|
|
|
271 |
|
272 |
+
while ($this->expression($exp)) {
|
273 |
+
$values[] = $exp;
|
|
|
|
|
|
|
274 |
}
|
|
|
|
|
|
|
275 |
|
276 |
+
if (count($values) == 0) return false;
|
|
|
277 |
|
278 |
+
$exps = $this->compressList($values, ' ');
|
279 |
+
return true;
|
280 |
+
}
|
|
|
281 |
|
282 |
+
// a single expression
|
283 |
+
function expression(&$out) {
|
284 |
+
$s = $this->seek();
|
285 |
+
$needWhite = true;
|
286 |
+
if ($this->literal('(') && $this->expression($exp) && $this->literal(')')) {
|
287 |
+
$lhs = $exp;
|
288 |
+
$needWhite = false;
|
289 |
+
} elseif ($this->seek($s) && $this->value($val)) {
|
290 |
+
$lhs = $val;
|
291 |
+
} else {
|
292 |
+
return false;
|
|
|
|
|
|
|
|
|
|
|
293 |
}
|
294 |
|
295 |
+
$out = $this->expHelper($lhs, 0, $needWhite);
|
296 |
+
return true;
|
|
|
|
|
297 |
}
|
298 |
|
299 |
+
// resursively parse infix equation with $lhs at precedence $minP
|
300 |
+
function expHelper($lhs, $minP, $needWhite = true) {
|
301 |
+
$ss = $this->seek();
|
302 |
+
// try to find a valid operator
|
303 |
+
while ($this->match(self::$operatorString.($needWhite ? '\s+' : ''), $m) && self::$precedence[$m[1]] >= $minP) {
|
304 |
+
$needWhite = true;
|
305 |
+
// get rhs
|
306 |
+
$s = $this->seek();
|
307 |
+
if ($this->literal('(') && $this->expression($exp) && $this->literal(')')) {
|
308 |
+
$needWhite = false;
|
309 |
+
$rhs = $exp;
|
310 |
+
} elseif ($this->seek($s) && $this->value($val)) {
|
311 |
+
$rhs = $val;
|
312 |
+
} else break;
|
313 |
|
314 |
+
// peek for next operator to see what to do with rhs
|
315 |
+
if ($this->peek(self::$operatorString, $next) && self::$precedence[$next[1]] > $minP) {
|
316 |
+
$rhs = $this->expHelper($rhs, self::$precedence[$next[1]]);
|
317 |
+
}
|
|
|
|
|
|
|
318 |
|
319 |
+
// don't evaluate yet if it is dynamic
|
320 |
+
if (in_array($rhs[0], self::$dtypes) || in_array($lhs[0], self::$dtypes))
|
321 |
+
$lhs = array('expression', $m[1], $lhs, $rhs);
|
322 |
+
else
|
323 |
+
$lhs = $this->evaluate($m[1], $lhs, $rhs);
|
324 |
+
|
325 |
+
$ss = $this->seek();
|
326 |
}
|
327 |
+
$this->seek($ss);
|
328 |
|
329 |
+
return $lhs;
|
330 |
}
|
331 |
|
332 |
+
// consume a list of values for a property
|
333 |
+
function propertyValue(&$value) {
|
334 |
+
$values = array();
|
335 |
+
|
336 |
+
$s = null;
|
337 |
+
while ($this->expressionList($v)) {
|
338 |
+
$values[] = $v;
|
339 |
+
$s = $this->seek();
|
340 |
+
if (!$this->literal(',')) break;
|
341 |
+
}
|
342 |
|
343 |
+
if ($s) $this->seek($s);
|
|
|
|
|
344 |
|
345 |
+
if (count($values) == 0) return false;
|
346 |
|
347 |
+
$value = $this->compressList($values, ', ');
|
348 |
+
return true;
|
349 |
}
|
350 |
|
351 |
+
// a single value
|
352 |
+
function value(&$value) {
|
353 |
+
// try a unit
|
354 |
+
if ($this->unit($value)) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
|
356 |
+
// see if there is a negation
|
357 |
+
$s = $this->seek();
|
358 |
+
if ($this->literal('-', false) && $this->variable($vname)) {
|
359 |
+
$value = array('negative', array('variable', $this->vPrefix.$vname));
|
360 |
+
return true;
|
361 |
+
} else {
|
362 |
+
$this->seek($s);
|
363 |
+
}
|
364 |
|
365 |
+
// accessor
|
366 |
+
// must be done before color
|
367 |
+
// this needs negation too
|
368 |
+
if ($this->accessor($a)) {
|
369 |
+
$tmp = $this->getEnv($a[0]);
|
370 |
+
if ($tmp && isset($tmp[$a[1]]))
|
371 |
+
$value = end($tmp[$a[1]]);
|
372 |
+
return true;
|
373 |
}
|
374 |
|
375 |
+
// color
|
376 |
+
if ($this->color($value)) return true;
|
|
|
|
|
377 |
|
378 |
+
// css function
|
379 |
+
// must be done after color
|
380 |
+
if ($this->func($value)) return true;
|
381 |
|
382 |
+
// string
|
383 |
+
if ($this->string($tmp, $d)) {
|
384 |
+
$value = array('string', $d.$tmp.$d);
|
385 |
+
return true;
|
386 |
+
}
|
387 |
|
388 |
+
// try a keyword
|
389 |
+
if ($this->keyword($word)) {
|
390 |
+
$value = array('keyword', $word);
|
391 |
+
return true;
|
392 |
+
}
|
393 |
|
394 |
+
// try a variable
|
395 |
+
if ($this->variable($vname)) {
|
396 |
+
$value = array('variable', $this->vPrefix.$vname);
|
397 |
+
return true;
|
398 |
}
|
399 |
|
400 |
+
return false;
|
401 |
}
|
402 |
|
403 |
+
// an import statement
|
404 |
+
function import(&$url, &$media) {
|
405 |
+
$s = $this->seek();
|
406 |
+
if (!$this->literal('@import')) return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
|
408 |
+
// @import "something.css" media;
|
409 |
+
// @import url("something.css") media;
|
410 |
+
// @import url(something.css) media;
|
411 |
|
412 |
+
if ($this->literal('url(')) $parens = true; else $parens = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
413 |
|
414 |
+
if (!$this->string($url)) {
|
415 |
+
if ($parens && $this->to(')', $url)) {
|
416 |
+
$parens = false; // got em
|
417 |
+
} else {
|
418 |
+
$this->seek($s);
|
419 |
+
return false;
|
420 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
421 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
|
423 |
+
if ($parens && !$this->literal(')')) {
|
424 |
+
$this->seek($s);
|
425 |
+
return false;
|
426 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
427 |
|
428 |
+
// now the rest is media
|
429 |
+
return $this->to(';', $media, false, true);
|
430 |
+
}
|
431 |
|
432 |
+
// a scoped value accessor
|
433 |
+
// .hello > @scope1 > @scope2['value'];
|
434 |
+
function accessor(&$var) {
|
435 |
+
$s = $this->seek();
|
436 |
|
437 |
+
if (!$this->tags($scope, true, '>') || !$this->literal('[')) {
|
438 |
+
$this->seek($s);
|
439 |
+
return false;
|
440 |
+
}
|
441 |
|
442 |
+
// either it is a variable or a property
|
443 |
+
// why is a property wrapped in quotes, who knows!
|
444 |
+
if ($this->variable($name)) {
|
445 |
+
$name = $this->vPrefix.$name;
|
446 |
+
} elseif($this->literal("'") && $this->keyword($name) && $this->literal("'")) {
|
447 |
+
// .. $this->count is messed up if we wanted to test another access type
|
448 |
+
} else {
|
449 |
+
$this->seek($s);
|
450 |
+
return false;
|
451 |
+
}
|
452 |
|
453 |
+
if (!$this->literal(']')) {
|
454 |
+
$this->seek($s);
|
455 |
+
return false;
|
456 |
+
}
|
|
|
457 |
|
458 |
+
$var = array($scope, $name);
|
459 |
+
return true;
|
460 |
+
}
|
461 |
|
462 |
+
// a string
|
463 |
+
function string(&$string, &$d = null) {
|
464 |
+
$s = $this->seek();
|
465 |
+
if ($this->literal('"', false)) {
|
466 |
+
$delim = '"';
|
467 |
+
} else if($this->literal("'", false)) {
|
468 |
+
$delim = "'";
|
469 |
+
} else {
|
470 |
+
return false;
|
471 |
+
}
|
472 |
|
473 |
+
if (!$this->to($delim, $string)) {
|
474 |
+
$this->seek($s);
|
475 |
+
return false;
|
476 |
+
}
|
477 |
+
|
478 |
+
$d = $delim;
|
479 |
+
return true;
|
480 |
+
}
|
481 |
|
482 |
+
// a numerical unit
|
483 |
+
function unit(&$unit, $allowed = null) {
|
484 |
+
$simpleCase = $allowed == null;
|
485 |
+
if (!$allowed) $allowed = self::$units;
|
486 |
|
487 |
+
if ($this->match('(-?[0-9]*(\.)?[0-9]+)('.implode('|', $allowed).')?', $m, !$simpleCase)) {
|
488 |
+
if (!isset($m[3])) $m[3] = 'number';
|
489 |
+
$unit = array($m[3], $m[1]);
|
490 |
|
491 |
+
// check for size/height font unit.. should this even be here?
|
492 |
+
if ($simpleCase) {
|
493 |
+
$s = $this->seek();
|
494 |
+
if ($this->literal('/', false) && $this->unit($right, self::$units)) {
|
495 |
+
$unit = array('keyword', $this->compileValue($unit).'/'.$this->compileValue($right));
|
496 |
+
} else {
|
497 |
+
// get rid of whitespace
|
498 |
+
$this->seek($s);
|
499 |
+
$this->match('', $_);
|
500 |
+
}
|
501 |
+
}
|
502 |
|
503 |
+
return true;
|
|
|
504 |
}
|
505 |
|
506 |
+
return false;
|
|
|
|
|
|
|
|
|
507 |
}
|
508 |
|
509 |
+
// a # color
|
510 |
+
function color(&$out) {
|
|
|
|
|
511 |
$color = array('color');
|
512 |
+
|
513 |
+
if ($this->match('(#([0-9a-f]{6})|#([0-9a-f]{3}))', $m)) {
|
514 |
if (isset($m[3])) {
|
515 |
$num = $m[3];
|
516 |
$width = 16;
|
524 |
$t = $num % $width;
|
525 |
$num /= $width;
|
526 |
|
|
|
527 |
$color[$i] = $t * (256/$width) + $t * floor(16/$width);
|
528 |
+
}
|
529 |
+
|
530 |
+
$out = $color;
|
531 |
+
return true;
|
532 |
+
}
|
533 |
|
534 |
+
return false;
|
535 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
536 |
|
537 |
+
// consume a list of property values delimited by ; and wrapped in ()
|
538 |
+
function argumentValues(&$args, $delim = ';') {
|
539 |
+
$s = $this->seek();
|
540 |
+
if (!$this->literal('(')) return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
541 |
|
542 |
+
$values = array();
|
543 |
+
while ($this->propertyValue($value)) {
|
544 |
+
$values[] = $value;
|
545 |
+
if (!$this->literal($delim)) break;
|
546 |
+
}
|
547 |
|
548 |
+
if (!$this->literal(')')) {
|
549 |
+
$this->seek($s);
|
550 |
+
return false;
|
551 |
+
}
|
552 |
+
|
553 |
+
$args = $values;
|
554 |
+
return true;
|
555 |
+
}
|
556 |
+
|
557 |
+
// consume an argument definition list surrounded by (), each argument is a variable name with optional value
|
558 |
+
function argumentDef(&$args, $delim = ';') {
|
559 |
+
$s = $this->seek();
|
560 |
+
if (!$this->literal('(')) return false;
|
561 |
|
562 |
+
$values = array();
|
563 |
+
while ($this->variable($vname)) {
|
564 |
+
$arg = array($vname);
|
565 |
+
if ($this->assign() && $this->propertyValue($value)) {
|
566 |
+
$arg[] = $value;
|
567 |
+
// let the : slide if there is no value
|
568 |
}
|
569 |
+
|
570 |
+
$values[] = $arg;
|
571 |
+
if (!$this->literal($delim)) break;
|
572 |
+
}
|
573 |
+
|
574 |
+
if (!$this->literal(')')) {
|
575 |
+
$this->seek($s);
|
576 |
+
return false;
|
577 |
}
|
578 |
|
579 |
+
$args = $values;
|
580 |
+
return true;
|
581 |
}
|
582 |
|
583 |
+
// consume a list of tags
|
584 |
+
// this accepts a hanging delimiter
|
585 |
+
function tags(&$tags, $simple = false, $delim = ',') {
|
586 |
+
$tags = array();
|
587 |
+
while ($this->tag($tt, $simple)) {
|
588 |
+
$tags[] = $tt;
|
589 |
+
if (!$this->literal($delim)) break;
|
590 |
+
}
|
591 |
+
if (count($tags) == 0) return false;
|
592 |
+
|
593 |
+
return true;
|
594 |
}
|
595 |
|
596 |
+
// a single tag
|
597 |
+
function tag(&$tag, $simple = false) {
|
598 |
+
if ($simple)
|
599 |
+
$chars = '^,:;{}\][>\(\) ';
|
600 |
+
else
|
601 |
+
$chars = '^,;{}[';
|
602 |
+
|
603 |
+
$tag = '';
|
604 |
+
while ($this->match('(['.$chars.'0-9]['.$chars.']*)', $m)) {
|
605 |
+
$tag.= $m[1];
|
606 |
+
if ($simple) break;
|
607 |
+
|
608 |
+
$s = $this->seek();
|
609 |
+
if ($this->literal('[') && $this->to(']', $c, true) && $this->literal(']')) {
|
610 |
+
$tag .= '['.$c.'] ';
|
611 |
+
} else {
|
612 |
+
$this->seek($s);
|
613 |
+
break;
|
614 |
}
|
615 |
}
|
616 |
+
$tag = trim($tag);
|
617 |
+
if ($tag == '') return false;
|
618 |
|
619 |
+
return true;
|
620 |
+
}
|
621 |
|
622 |
+
// a css function
|
623 |
+
function func(&$func) {
|
624 |
+
$s = $this->seek();
|
625 |
|
626 |
+
if ($this->match('([\w\-_][\w\-_:\.]*)', $m) && $this->literal('(')) {
|
627 |
+
$fname = $m[1];
|
628 |
+
if ($fname == 'url') {
|
629 |
+
$this->to(')', $content, true);
|
630 |
+
$args = array('string', $content);
|
631 |
+
} else {
|
632 |
+
$args = array();
|
633 |
+
while (true) {
|
634 |
+
$ss = $this->seek();
|
635 |
+
if ($this->keyword($name) && $this->literal('=') && $this->expressionList($value)) {
|
636 |
+
$args[] = array('list', '=', array(array('keyword', $name), $value));
|
637 |
+
} else {
|
638 |
+
$this->seek($ss);
|
639 |
+
if ($this->expressionList($value)) {
|
640 |
+
$args[] = $value;
|
641 |
+
}
|
642 |
+
}
|
643 |
+
|
644 |
+
if (!$this->literal(',')) break;
|
645 |
+
}
|
646 |
+
$args = array('list', ',', $args);
|
647 |
+
}
|
648 |
|
649 |
+
if ($this->literal(')')) {
|
650 |
+
$func = array('function', $fname, $args);
|
651 |
+
return true;
|
652 |
+
}
|
653 |
+
}
|
654 |
|
655 |
+
$this->seek($s);
|
656 |
+
return false;
|
657 |
}
|
658 |
|
659 |
+
// consume a less variable
|
660 |
+
function variable(&$name) {
|
661 |
+
$s = $this->seek();
|
662 |
+
if ($this->literal($this->vPrefix, false) && $this->keyword($name)) {
|
663 |
+
return true;
|
664 |
}
|
665 |
+
return false;
|
|
|
|
|
666 |
}
|
667 |
|
668 |
+
// consume an assignment operator
|
669 |
+
function assign() {
|
670 |
+
return $this->literal(':') || $this->literal('=');
|
671 |
+
}
|
|
|
672 |
|
673 |
+
// consume a keyword
|
674 |
+
function keyword(&$word) {
|
675 |
+
if ($this->match('([\w_\-\*!"][\w\-_"]*)', $m)) {
|
676 |
+
$word = $m[1];
|
677 |
+
return true;
|
678 |
+
}
|
679 |
+
return false;
|
680 |
+
}
|
681 |
|
682 |
+
// consume an end of statement delimiter
|
683 |
+
function end() {
|
684 |
+
if ($this->literal(';'))
|
685 |
+
return true;
|
686 |
+
elseif ($this->count == strlen($this->buffer) || $this->buffer{$this->count} == '}') {
|
687 |
+
// if there is end of file or a closing block next then we don't need a ;
|
688 |
+
return true;
|
689 |
+
}
|
690 |
+
return false;
|
691 |
}
|
692 |
|
693 |
+
function compressList($items, $delim) {
|
694 |
+
if (count($items) == 1) return $items[0];
|
695 |
+
else return array('list', $delim, $items);
|
696 |
+
}
|
697 |
|
698 |
+
function compileBlock($rtags, $env) {
|
|
|
|
|
|
|
|
|
699 |
// don't render functions
|
700 |
+
// todo: this shouldn't need to happen because multiplyTags prunes them, verify
|
701 |
+
/*
|
702 |
foreach ($rtags as $i => $tag) {
|
703 |
if (preg_match('/( |^)%/', $tag))
|
704 |
unset($rtags[$i]);
|
705 |
}
|
706 |
+
*/
|
707 |
if (empty($rtags)) return '';
|
708 |
|
709 |
$props = 0;
|
710 |
+
// print all the visible properties
|
711 |
ob_start();
|
712 |
foreach ($env as $name => $value) {
|
713 |
// todo: change this, poor hack
|
714 |
// make a better name storage system!!! (value types are fine)
|
715 |
// but.. don't render special properties (blocks, vars, metadata)
|
716 |
+
if (isset($value[0]) && $name{0} != $this->vPrefix && $name != '__args') {
|
717 |
echo $this->compileProperty($name, $value, 1)."\n";
|
718 |
$props++;
|
719 |
}
|
720 |
}
|
721 |
$list = ob_get_clean();
|
722 |
|
723 |
+
if ($props == 0) return '';
|
724 |
|
725 |
// do some formatting
|
726 |
if ($props == 1) $list = ' '.trim($list).' ';
|
727 |
return implode(", ", $rtags).' {'.($props > 1 ? "\n" : '').
|
728 |
$list."}\n";
|
729 |
+
|
730 |
}
|
731 |
|
732 |
+
function compileProperty($name, $value, $level = 0) {
|
733 |
+
// output all repeated properties
|
|
|
734 |
foreach ($value as $v)
|
735 |
$props[] = str_repeat(' ', $level).
|
736 |
$name.':'.$this->compileValue($v).';';
|
738 |
return implode("\n", $props);
|
739 |
}
|
740 |
|
741 |
+
function compileValue($value) {
|
742 |
+
switch($value[0]) {
|
|
|
743 |
case 'list':
|
744 |
+
// [1] - delimiter
|
745 |
+
// [2] - array of values
|
746 |
return implode($value[1], array_map(array($this, 'compileValue'), $value[2]));
|
747 |
+
case 'keyword':
|
748 |
+
// [1] - the keyword
|
749 |
+
case 'number':
|
750 |
+
// [1] - the number
|
751 |
+
return $value[1];
|
752 |
case 'expression':
|
753 |
+
// [1] - operator
|
754 |
+
// [2] - value of left hand side
|
755 |
+
// [3] - value of right
|
756 |
return $this->compileValue($this->evaluate($value[1], $value[2], $value[3]));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
757 |
case 'string':
|
758 |
+
// [1] - contents of string (includes quotes)
|
759 |
+
|
760 |
+
// search for inline variables to replace
|
761 |
$replace = array();
|
762 |
if (preg_match_all('/{(@[\w-_][0-9\w-_]*)}/', $value[1], $m)) {
|
763 |
foreach($m[1] as $name) {
|
765 |
$replace[$name] = $this->compileValue(array('variable', $name));
|
766 |
}
|
767 |
}
|
768 |
+
foreach ($replace as $var=>$val) {
|
769 |
+
// strip quotes
|
770 |
+
if (preg_match('/^(["\']).*?(\1)$/', $val)) {
|
771 |
+
$val = substr($val, 1, -1);
|
772 |
+
}
|
773 |
+
$value[1] = str_replace('{'.$var.'}', $val, $value[1]);
|
774 |
+
}
|
775 |
|
776 |
return $value[1];
|
|
|
777 |
case 'color':
|
778 |
+
// [1] - red component (either number for a %)
|
779 |
+
// [2] - green component
|
780 |
+
// [3] - blue component
|
781 |
+
// [4] - optional alpha component
|
782 |
+
if (count($value) == 5) { // rgba
|
783 |
+
return 'rgba('.$value[1].','.$value[2].','.$value[3].','.$value[4].')';
|
784 |
+
}
|
785 |
|
786 |
+
$out = '#';
|
787 |
+
foreach (range(1,3) as $i)
|
788 |
+
$out .= ($value[$i] < 16 ? '0' : '').dechex($value[$i]);
|
789 |
+
return $out;
|
790 |
+
case 'variable':
|
791 |
+
// [1] - the name of the variable including @
|
792 |
+
$tmp = $this->compileValue(
|
793 |
+
$this->getVal($value[1], $this->pushName($value[1]))
|
794 |
+
);
|
795 |
+
$this->popName();
|
796 |
|
797 |
+
return $tmp;
|
798 |
+
case 'negative':
|
799 |
+
// [1] - some value that needs to become negative
|
800 |
+
return $this->compileValue($this->reduce($value));
|
801 |
+
case 'function':
|
802 |
+
// [1] - function name
|
803 |
+
// [2] - some value representing arguments
|
804 |
+
|
805 |
+
// see if there is a library function for this func
|
806 |
+
$f = array($this, 'lib_'.$value[1]);
|
807 |
+
if (is_callable($f)) {
|
808 |
+
return call_user_func($f, $value[2]);
|
809 |
+
}
|
810 |
|
811 |
+
return $value[1].'('.$this->compileValue($value[2]).')';
|
812 |
+
|
813 |
+
default: // assumed to be unit
|
814 |
return $value[1].$value[0];
|
815 |
}
|
816 |
}
|
817 |
|
818 |
+
function lib_quote($arg) {
|
819 |
+
return '"'.$this->compileValue($arg).'"';
|
820 |
+
}
|
821 |
|
822 |
+
function lib_unquote($arg) {
|
823 |
+
$out = $this->compileValue($arg);
|
824 |
+
if ($this->quoted($out)) $out = substr($out, 1, -1);
|
|
|
|
|
|
|
|
|
|
|
|
|
825 |
return $out;
|
826 |
}
|
827 |
|
828 |
+
// is a string surrounded in quotes? returns the quoting char if true
|
829 |
+
function quoted($s) {
|
830 |
+
if (preg_match('/^("|\').*?\1$/', $s, $m))
|
831 |
+
return $m[1];
|
832 |
+
else return false;
|
833 |
+
}
|
834 |
|
835 |
+
// convert rgb, rgba into color type suitable for math
|
836 |
+
// todo: add hsl
|
837 |
+
function funcToColor($func) {
|
838 |
+
$fname = $func[1];
|
839 |
+
if (!preg_match('/^(rgb|rgba)$/', $fname)) return false;
|
840 |
+
if ($func[2][0] != 'list') return false; // need a list of arguments
|
841 |
+
|
842 |
+
$components = array();
|
843 |
+
$i = 1;
|
844 |
+
foreach ($func[2][2] as $c) {
|
845 |
+
$c = $this->reduce($c);
|
846 |
+
if ($i < 4) {
|
847 |
+
if ($c[0] == '%') $components[] = 255 * ($c[1] / 100);
|
848 |
+
else $components[] = floatval($c[1]);
|
849 |
+
} elseif ($i == 4) {
|
850 |
+
if ($c[0] == '%') $components[] = 1.0 * ($c[1] / 100);
|
851 |
+
else $components[] = floatval($c[1]);
|
852 |
+
} else break;
|
853 |
+
|
854 |
+
$i++;
|
855 |
+
}
|
856 |
+
while (count($components) < 3) $components[] = 0;
|
857 |
|
858 |
+
array_unshift($components, 'color');
|
859 |
+
return $this->fixColor($components);
|
860 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
861 |
|
862 |
+
// reduce a delayed type to its final value
|
863 |
+
// dereference variables and solve equations
|
864 |
+
function reduce($var, $defaultValue = array('number', 0)) {
|
865 |
+
$pushed = 0; // number of variable names pushed
|
866 |
|
867 |
+
while (in_array($var[0], self::$dtypes)) {
|
868 |
+
if ($var[0] == 'expression') {
|
869 |
+
$var = $this->evaluate($var[1], $var[2], $var[3]);
|
870 |
+
} else if ($var[0] == 'variable') {
|
871 |
+
$var = $this->getVal($var[1], $this->pushName($var[1]), $defaultValue);
|
|
|
872 |
$pushed++;
|
873 |
+
} else if ($var[0] == 'function') {
|
874 |
+
$color = $this->funcToColor($var);
|
875 |
+
if ($color) $var = $color;
|
876 |
+
break; // no where to go after a function
|
877 |
+
} else if ($var[0] == 'negative') {
|
878 |
+
$value = $this->reduce($var[1]);
|
879 |
+
if (is_numeric($value[1])) {
|
880 |
+
$value[1] = -1*$value[1];
|
881 |
+
}
|
882 |
+
$var = $value;
|
883 |
}
|
884 |
}
|
885 |
+
|
886 |
while ($pushed != 0) { $this->popName(); $pushed--; }
|
887 |
+
return $var;
|
888 |
+
}
|
889 |
|
890 |
+
// evaluate an expression
|
891 |
+
function evaluate($op, $left, $right) {
|
892 |
+
$left = $this->reduce($left);
|
893 |
+
$right = $this->reduce($right);
|
894 |
+
|
895 |
+
if ($left[0] == 'color' && $right[0] == 'color') {
|
896 |
+
$out = $this->op_color_color($op, $left, $right);
|
897 |
+
return $out;
|
898 |
}
|
899 |
|
900 |
+
if ($left[0] == 'color') {
|
901 |
+
return $this->op_color_number($op, $left, $right);
|
902 |
}
|
903 |
|
904 |
+
if ($right[0] == 'color') {
|
905 |
+
return $this->op_number_color($op, $left, $right);
|
906 |
}
|
907 |
|
908 |
+
// concatenate strings
|
909 |
+
if ($op == '+' && $left[0] == 'string') {
|
910 |
+
$append = $this->compileValue($right);
|
911 |
+
if ($this->quoted($append)) $append = substr($append, 1, -1);
|
912 |
|
913 |
+
$lhs = $this->compileValue($left);
|
914 |
+
if ($q = $this->quoted($lhs)) $lhs = substr($lhs, 1, -1);
|
915 |
+
if (!$q) $q = '';
|
916 |
|
917 |
+
return array('string', $q.$lhs.$append.$q);
|
918 |
+
}
|
|
|
919 |
|
920 |
+
if ($left[0] == 'keyword' || $right[0] == 'keyword' ||
|
921 |
+
$left[0] == 'string' || $right[0] == 'string')
|
922 |
+
{
|
923 |
+
// look for negative op
|
924 |
+
if ($op == '-') $right[1] = '-'.$right[1];
|
925 |
+
return array('keyword', $this->compileValue($left) .' '. $this->compileValue($right));
|
926 |
+
}
|
927 |
+
|
928 |
+
// default to number operation
|
929 |
+
return $this->op_number_number($op, $left, $right);
|
930 |
+
}
|
931 |
|
932 |
+
// make sure a color's components don't go out of bounds
|
933 |
+
function fixColor($c) {
|
934 |
+
foreach (range(1, 3) as $i) {
|
935 |
+
if ($c[$i] < 0) $c[$i] = 0;
|
936 |
+
if ($c[$i] > 255) $c[$i] = 255;
|
937 |
+
$c[$i] = floor($c[$i]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
938 |
}
|
939 |
|
940 |
+
return $c;
|
941 |
}
|
942 |
|
943 |
+
function op_number_color($op, $lft, $rgt) {
|
|
|
944 |
if ($op == '+' || $op = '*') {
|
945 |
return $this->op_color_number($op, $rgt, $lft);
|
946 |
}
|
947 |
}
|
948 |
|
949 |
+
function op_color_number($op, $lft, $rgt) {
|
|
|
950 |
if ($rgt[0] == '%') $rgt[1] /= 100;
|
951 |
|
952 |
+
return $this->op_color_color($op, $lft,
|
953 |
+
array_fill(1, count($lft) - 1, $rgt[1]));
|
954 |
}
|
955 |
|
956 |
+
function op_color_color($op, $left, $right) {
|
957 |
+
$out = array('color');
|
958 |
+
$max = count($left) > count($right) ? count($left) : count($right);
|
959 |
+
foreach (range(1, $max - 1) as $i) {
|
960 |
+
$lval = isset($left[$i]) ? $left[$i] : 0;
|
961 |
+
$rval = isset($right[$i]) ? $right[$i] : 0;
|
962 |
+
switch ($op) {
|
963 |
+
case '+':
|
964 |
+
$out[] = $lval + $rval;
|
965 |
+
break;
|
966 |
+
case '-':
|
967 |
+
$out[] = $lval - $rval;
|
968 |
+
break;
|
969 |
+
case '*':
|
970 |
+
$out[] = $lval * $rval;
|
971 |
+
break;
|
972 |
+
case '%':
|
973 |
+
$out[] = $lval % $rval;
|
974 |
+
break;
|
975 |
+
case '/':
|
976 |
+
if ($rval == 0) throw new exception("evaluate error: can't divide by zero");
|
977 |
+
$out[] = $lval / $rval;
|
978 |
+
break;
|
979 |
+
default:
|
980 |
+
throw new exception('evaluate error: color op number failed on op '.$op);
|
981 |
+
}
|
982 |
+
}
|
983 |
+
return $this->fixColor($out);
|
984 |
+
}
|
985 |
+
|
986 |
+
// operator on two numbers
|
987 |
+
function op_number_number($op, $left, $right) {
|
988 |
+
if ($right[0] == '%') $right[1] /= 100;
|
989 |
|
990 |
+
// figure out type
|
991 |
+
if ($right[0] == 'number' || $right[0] == '%') $type = $left[0];
|
992 |
+
else $type = $right[0];
|
993 |
+
|
994 |
+
$value = 0;
|
995 |
+
switch($op) {
|
996 |
case '+':
|
997 |
+
$value = $left[1] + $right[1];
|
998 |
+
break;
|
|
|
|
|
999 |
case '*':
|
1000 |
+
$value = $left[1] * $right[1];
|
1001 |
+
break;
|
|
|
|
|
1002 |
case '-':
|
1003 |
+
$value = $left[1] - $right[1];
|
1004 |
+
break;
|
1005 |
+
case '%':
|
1006 |
+
$value = $left[1] % $right[1];
|
1007 |
+
break;
|
1008 |
+
case '/':
|
1009 |
+
if ($right[1] == 0) throw new exception('parse error: divide by zero');
|
1010 |
+
$value = $left[1] / $right[1];
|
|
|
|
|
1011 |
break;
|
1012 |
default:
|
1013 |
+
throw new exception('parse error: unknown number operator: '.$op);
|
1014 |
}
|
1015 |
+
|
1016 |
+
return array($type, $value);
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
|
1020 |
+
/* environment functions */
|
1021 |
+
|
1022 |
+
// push name on expand stack, and return its
|
1023 |
+
// count before being pushed
|
1024 |
+
function pushName($name) {
|
1025 |
+
$count = array_count_values($this->expandStack);
|
1026 |
+
$count = isset($count[$name]) ? $count[$name] : 0;
|
1027 |
+
|
1028 |
+
$this->expandStack[] = $name;
|
1029 |
+
|
1030 |
+
return $count;
|
1031 |
+
}
|
1032 |
+
|
1033 |
+
// pop name off expand stack and return it
|
1034 |
+
function popName() {
|
1035 |
+
return array_pop($this->expandStack);
|
1036 |
+
}
|
1037 |
+
|
1038 |
+
// push a new environment
|
1039 |
+
function push() {
|
1040 |
+
$this->level++;
|
1041 |
+
$this->env[] = array();
|
1042 |
}
|
1043 |
|
1044 |
+
// pop environment off the stack
|
1045 |
+
function pop() {
|
1046 |
+
if ($this->level == 1)
|
1047 |
+
throw new exception('parse error: unexpected end of block');
|
1048 |
|
1049 |
+
$this->level--;
|
1050 |
+
return array_pop($this->env);
|
1051 |
+
}
|
1052 |
+
|
1053 |
+
// set something in the current env
|
1054 |
+
function set($name, $value) {
|
1055 |
+
$this->env[count($this->env) - 1][$name] = $value;
|
1056 |
+
}
|
1057 |
|
1058 |
+
// append to array in the current env
|
1059 |
+
function append($name, $value) {
|
1060 |
+
$this->env[count($this->env) - 1][$name][] = $value;
|
1061 |
+
}
|
1062 |
+
|
1063 |
+
// put on the front of the value
|
1064 |
+
function prepend($name, $value) {
|
1065 |
+
if (isset($this->env[count($this->env) - 1][$name]))
|
1066 |
+
array_unshift($this->env[count($this->env) - 1][$name], $value);
|
1067 |
+
else $this->append($name, $value);
|
1068 |
+
}
|
1069 |
+
|
1070 |
+
// get the highest occurrence of value
|
1071 |
+
function get($name, $env = null) {
|
1072 |
if (empty($env)) $env = $this->env;
|
1073 |
|
1074 |
for ($i = count($env) - 1; $i >= 0; $i--)
|
1077 |
return null;
|
1078 |
}
|
1079 |
|
|
|
1080 |
// get the most recent value of a variable
|
1081 |
// return default if it isn't found
|
1082 |
// $skip is number of vars to skip
|
1083 |
+
function getVal($name, $skip = 0, $default = array('keyword', '')) {
|
|
|
1084 |
$val = $this->get($name);
|
1085 |
if ($val == null) return $default;
|
1086 |
|
1104 |
return end($val);
|
1105 |
}
|
1106 |
|
1107 |
+
// get the environment described by path, an array of env names
|
1108 |
+
function getEnv($path) {
|
1109 |
+
if (!is_array($path)) $path = array($path);
|
1110 |
+
|
1111 |
+
// move @ tags out of variable namespace
|
1112 |
+
foreach($path as &$tag)
|
1113 |
+
if ($tag{0} == $this->vPrefix) $tag[0] = $this->mPrefix;
|
1114 |
+
|
1115 |
+
$env = $this->get(array_shift($path));
|
1116 |
+
while ($sub = array_shift($path)) {
|
1117 |
+
if (isset($env[$sub])) // todo add a type check for environment
|
1118 |
+
$env = $env[$sub];
|
1119 |
+
else {
|
1120 |
+
$env = null;
|
1121 |
+
break;
|
1122 |
+
}
|
1123 |
+
}
|
1124 |
+
return $env;
|
1125 |
+
}
|
1126 |
+
|
1127 |
// merge a block into the current env
|
1128 |
+
function merge($name, $value) {
|
|
|
1129 |
// if the current block isn't there then just set
|
1130 |
$top =& $this->env[count($this->env) - 1];
|
1131 |
if (!isset($top[$name])) return $this->set($name, $value);
|
1138 |
}
|
1139 |
}
|
1140 |
|
1141 |
+
function literal($what, $eatWhitespace = true) {
|
1142 |
+
// this is here mainly prevent notice from { } string accessor
|
1143 |
+
if ($this->count >= strlen($this->buffer)) return false;
|
|
|
|
|
1144 |
|
1145 |
+
// shortcut on single letter
|
1146 |
+
if (!$eatWhitespace and strlen($what) == 1) {
|
1147 |
+
if ($this->buffer{$this->count} == $what) {
|
1148 |
+
$this->count++;
|
1149 |
+
return true;
|
1150 |
+
}
|
1151 |
+
else return false;
|
1152 |
+
}
|
1153 |
+
|
1154 |
+
return $this->match($this->preg_quote($what), $m, $eatWhitespace);
|
1155 |
}
|
1156 |
|
1157 |
+
function preg_quote($what) {
|
1158 |
+
return preg_quote($what, '/');
|
|
|
|
|
|
|
|
|
1159 |
}
|
1160 |
|
1161 |
+
// advance counter to next occurrence of $what
|
1162 |
+
// $until - don't include $what in advance
|
1163 |
+
function to($what, &$out, $until = false, $allowNewline = false) {
|
1164 |
+
$validChars = $allowNewline ? "[^\n]" : '.';
|
1165 |
+
if (!$this->match('('.$validChars.'*?)'.$this->preg_quote($what), $m, !$until)) return false;
|
1166 |
+
if ($until) $this->count -= strlen($what); // give back $what
|
1167 |
+
$out = $m[1];
|
1168 |
+
return true;
|
1169 |
+
}
|
1170 |
+
|
1171 |
+
// try to match something on head of buffer
|
1172 |
+
function match($regex, &$out, $eatWhitespace = true) {
|
1173 |
+
$r = '/'.$regex.($eatWhitespace ? '\s*' : '').'/Ais';
|
1174 |
+
if (preg_match($r, $this->buffer, $out, null, $this->count)) {
|
1175 |
+
$this->count += strlen($out[0]);
|
1176 |
+
return true;
|
1177 |
+
}
|
1178 |
+
return false;
|
1179 |
}
|
1180 |
|
|
|
|
|
|
|
|
|
|
|
1181 |
|
1182 |
+
// match something without consuming it
|
1183 |
+
function peek($regex, &$out = null) {
|
1184 |
+
$r = '/'.$regex.'/Ais';
|
1185 |
+
$result = preg_match($r, $this->buffer, $out, null, $this->count);
|
1186 |
+
|
1187 |
+
return $result;
|
1188 |
}
|
1189 |
|
1190 |
+
// seek to a spot in the buffer or return where we are on no argument
|
1191 |
+
function seek($where = null) {
|
1192 |
+
if ($where === null) return $this->count;
|
1193 |
+
else $this->count = $where;
|
1194 |
+
return true;
|
1195 |
+
}
|
1196 |
|
1197 |
+
// parse and compile buffer
|
1198 |
+
function parse($str = null) {
|
1199 |
+
if ($str) $this->buffer = $str;
|
1200 |
|
1201 |
+
$this->env = array();
|
1202 |
+
$this->expandStack = array();
|
1203 |
+
$this->count = 0;
|
1204 |
+
$this->line = 1;
|
|
|
1205 |
|
1206 |
+
$this->buffer = $this->removeComments($this->buffer);
|
1207 |
+
$this->push(); // set up global scope
|
1208 |
+
$this->set('__tags', array('')); // equivalent to 1 in tag multiplication
|
1209 |
+
|
1210 |
+
// trim whitespace on head
|
1211 |
+
if (preg_match('/^\s+/', $this->buffer, $m)) {
|
1212 |
+
$this->line += substr_count($m[0], "\n");
|
1213 |
+
$this->buffer = ltrim($this->buffer);
|
1214 |
+
}
|
1215 |
+
|
1216 |
+
$out = '';
|
1217 |
+
while (false !== ($compiled = $this->chunk())) {
|
1218 |
+
if (is_string($compiled)) $out .= $compiled;
|
1219 |
+
}
|
1220 |
+
|
1221 |
+
if ($this->count != strlen($this->buffer)) $this->throwParseError();
|
1222 |
+
|
1223 |
+
if (count($this->env) > 1)
|
1224 |
+
throw new exception('parse error: unclosed block');
|
1225 |
+
|
1226 |
+
// print_r($this->env);
|
1227 |
+
return $out;
|
1228 |
}
|
1229 |
|
1230 |
+
function throwParseError($msg = 'parse error') {
|
1231 |
+
$line = $this->line + substr_count(substr($this->buffer, 0, $this->count), "\n");
|
1232 |
+
if ($this->peek("(.*?)\n", $m))
|
1233 |
+
throw new exception($msg.': failed at `'.$m[1].'` line: '.$line);
|
1234 |
}
|
1235 |
|
1236 |
+
function __construct($fname = null) {
|
1237 |
+
if (!self::$operatorString) {
|
1238 |
+
self::$operatorString =
|
1239 |
+
'('.implode('|', array_map(array($this, 'preg_quote'), array_keys(self::$precedence))).')';
|
1240 |
+
}
|
1241 |
+
|
1242 |
+
if ($fname) {
|
1243 |
+
if (!is_file($fname)) {
|
1244 |
+
throw new Exception('load error: failed to find '.$fname);
|
1245 |
+
}
|
1246 |
+
$pi = pathinfo($fname);
|
1247 |
+
|
1248 |
+
$this->fileName = $fname;
|
1249 |
+
$this->importDir = $pi['dirname'].'/';
|
1250 |
+
$this->buffer = file_get_contents($fname);
|
1251 |
+
}
|
1252 |
+
}
|
1253 |
|
1254 |
// remove comments from $text
|
1255 |
// todo: make it work for all functions, not just url
|
1256 |
+
// todo: make it not mess up line counter with block comments
|
1257 |
+
function removeComments($text) {
|
1258 |
$out = '';
|
1259 |
|
1260 |
+
while (!empty($text) &&
|
1261 |
preg_match('/^(.*?)("|\'|\/\/|\/\*|url\(|$)/is', $text, $m))
|
1262 |
{
|
1263 |
if (!trim($text)) break;
|
1266 |
$text = substr($text, strlen($m[0]));
|
1267 |
|
1268 |
switch ($m[2]) {
|
1269 |
+
case 'url(':
|
1270 |
preg_match('/^(.*?)(\)|$)/is', $text, $inner);
|
1271 |
$text = substr($text, strlen($inner[0]));
|
1272 |
$out .= $m[2].$inner[1].$inner[2];
|
1289 |
}
|
1290 |
}
|
1291 |
|
|
|
1292 |
return $out;
|
1293 |
}
|
1294 |
|
1295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1296 |
// compile to $in to $out if $in is newer than $out
|
1297 |
// returns true when it compiles, false otherwise
|
1298 |
+
public static function ccompile($in, $out) {
|
|
|
1299 |
if (!is_file($out) || filemtime($in) > filemtime($out)) {
|
1300 |
$less = new lessc($in);
|
1301 |
file_put_contents($out, $less->parse());
|
1304 |
|
1305 |
return false;
|
1306 |
}
|
1307 |
+
|
1308 |
}
|
1309 |
|
1310 |
|
1311 |
+
|
1312 |
?>
|
lib/vendor/lessphp/plessc
CHANGED
@@ -25,7 +25,7 @@ function process($data, $import = null) {
|
|
25 |
global $fa;
|
26 |
|
27 |
$l = new lessc();
|
28 |
-
if ($import) $l->
|
29 |
try {
|
30 |
echo $l->parse($data);
|
31 |
exit(0);
|
@@ -118,13 +118,20 @@ if (has("w")) {
|
|
118 |
}
|
119 |
|
120 |
if (!$fname = array_shift($argv)) {
|
121 |
-
echo "Usage: ".$exe." input-file
|
122 |
exit(1);
|
123 |
}
|
124 |
|
125 |
try {
|
126 |
$l = new lessc($fname);
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
} catch (exception $ex) {
|
129 |
err($fa.$ex->getMessage());
|
130 |
exit(1);
|
25 |
global $fa;
|
26 |
|
27 |
$l = new lessc();
|
28 |
+
if ($import) $l->importDir = $import;
|
29 |
try {
|
30 |
echo $l->parse($data);
|
31 |
exit(0);
|
118 |
}
|
119 |
|
120 |
if (!$fname = array_shift($argv)) {
|
121 |
+
echo "Usage: ".$exe." input-file [output-file]\n";
|
122 |
exit(1);
|
123 |
}
|
124 |
|
125 |
try {
|
126 |
$l = new lessc($fname);
|
127 |
+
$out = $l->parse();
|
128 |
+
|
129 |
+
if (!$fout = array_shift($argv)) {
|
130 |
+
echo $out;
|
131 |
+
} else {
|
132 |
+
file_put_contents($fout, $out);
|
133 |
+
}
|
134 |
+
|
135 |
} catch (exception $ex) {
|
136 |
err($fa.$ex->getMessage());
|
137 |
exit(1);
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: dev, theme, themes, toolkit, plugin-toolkit, less, lesscss, lessc, lessphp, productivity, style, stylesheet, api
|
5 |
Requires at least: 2.8
|
6 |
Tested up to: 2.8.x
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
Implementation of LESS (Leaner CSS) in order to make themes development easier.
|
10 |
|
@@ -30,7 +30,7 @@ Seriously.
|
|
30 |
The sole requirement is to use WordPress API and LESS convention: the `.less` extension.
|
31 |
|
32 |
**Minimal Requirements**: PHP 5.1.2 and WordPress 2.8.
|
33 |
-
**Relies on**: [LESSPHP 0.
|
34 |
|
35 |
*Notice*: in case you'd like to drop the usage of this plugin, it's safe to do it. You will just need to convert back your stylesheets to CSS.
|
36 |
|
@@ -47,7 +47,17 @@ The sole requirement is to use WordPress API and LESS convention: the `.less` ex
|
|
47 |
1. Activate it through your WordPress plugins administration page
|
48 |
|
49 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
= Version 1.1 =
|
|
|
51 |
* added `bootstrap-for-theme.php` to let themers bundle the plugin in their own themes
|
52 |
* added `WPLessPlugin::registerHooks` methods to ease hooks activation
|
53 |
* theme bootstrap will only load if the plugin is not alread activated
|
4 |
Tags: dev, theme, themes, toolkit, plugin-toolkit, less, lesscss, lessc, lessphp, productivity, style, stylesheet, api
|
5 |
Requires at least: 2.8
|
6 |
Tested up to: 2.8.x
|
7 |
+
Stable tag: 1.2
|
8 |
|
9 |
Implementation of LESS (Leaner CSS) in order to make themes development easier.
|
10 |
|
30 |
The sole requirement is to use WordPress API and LESS convention: the `.less` extension.
|
31 |
|
32 |
**Minimal Requirements**: PHP 5.1.2 and WordPress 2.8.
|
33 |
+
**Relies on**: [LESSPHP 0.2.0](http://leafo.net/lessphp/), [plugin-toolkit](http://wordpress.org/extend/plugins/plugin-toolkit/).
|
34 |
|
35 |
*Notice*: in case you'd like to drop the usage of this plugin, it's safe to do it. You will just need to convert back your stylesheets to CSS.
|
36 |
|
47 |
1. Activate it through your WordPress plugins administration page
|
48 |
|
49 |
== Changelog ==
|
50 |
+
= Version 1.2 =
|
51 |
+
|
52 |
+
* added 2 new filters working on freshly transformed CSS
|
53 |
+
* added a HTML helper to LESSify directly from templates, without queuying with `wp_enqueue_stylesheet` (can't really recommend this usage)
|
54 |
+
* added timestamp calculation so as you can be HTTP cache-control compliant
|
55 |
+
* documented plugin hooks and filters
|
56 |
+
* hooked a filter to update relative paths to deal `uri` and cached file location
|
57 |
+
* lessphp: updated to version 0.2.0
|
58 |
+
|
59 |
= Version 1.1 =
|
60 |
+
|
61 |
* added `bootstrap-for-theme.php` to let themers bundle the plugin in their own themes
|
62 |
* added `WPLessPlugin::registerHooks` methods to ease hooks activation
|
63 |
* theme bootstrap will only load if the plugin is not alread activated
|