html5-starter 0.1.3b
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +3 -0
- data/README.md +135 -0
- data/VERSION +1 -0
- data/lib/app/helpers/html5_boilerplate_helper.rb +47 -0
- data/lib/html5-boilerplate.rb +6 -0
- data/stylesheets/_html5-boilerplate.scss +15 -0
- data/stylesheets/html5-boilerplate/_fonts.scss +36 -0
- data/stylesheets/html5-boilerplate/_handheld.scss +8 -0
- data/stylesheets/html5-boilerplate/_helpers.scss +25 -0
- data/stylesheets/html5-boilerplate/_print.scss +20 -0
- data/stylesheets/html5-boilerplate/_reset.scss +50 -0
- data/stylesheets/html5-boilerplate/_styles.scss +100 -0
- data/templates/project/_flashes.html.haml +4 -0
- data/templates/project/_footer.html.haml +2 -0
- data/templates/project/_head.html.haml +32 -0
- data/templates/project/_header.html.haml +1 -0
- data/templates/project/_javascripts.html.haml +38 -0
- data/templates/project/_stylesheets.html.haml +8 -0
- data/templates/project/application.html.haml +15 -0
- data/templates/project/files/404.html +22 -0
- data/templates/project/files/apple-touch-icon.png +0 -0
- data/templates/project/files/build/build.xml +636 -0
- data/templates/project/files/build/buildinfo.properties +5 -0
- data/templates/project/files/build/config/build.properties +3 -0
- data/templates/project/files/build/config/default.properties +79 -0
- data/templates/project/files/build/config/project.properties +49 -0
- data/templates/project/files/build/createproject.sh +73 -0
- data/templates/project/files/build/tools/ant-contrib-1.0b3.jar +0 -0
- data/templates/project/files/build/tools/css-compressor/CSSCompression.php +465 -0
- data/templates/project/files/build/tools/css-compressor/changelog.txt +22 -0
- data/templates/project/files/build/tools/css-compressor/cli.php +101 -0
- data/templates/project/files/build/tools/css-compressor/helpers/hex2short-colors.json +39 -0
- data/templates/project/files/build/tools/css-compressor/helpers/hex2short-safe.json +16 -0
- data/templates/project/files/build/tools/css-compressor/helpers/long2hex-colors.json +127 -0
- data/templates/project/files/build/tools/css-compressor/lib/Cleanup.php +218 -0
- data/templates/project/files/build/tools/css-compressor/lib/Color.php +199 -0
- data/templates/project/files/build/tools/css-compressor/lib/Combine.php +191 -0
- data/templates/project/files/build/tools/css-compressor/lib/Combine/Aural.php +109 -0
- data/templates/project/files/build/tools/css-compressor/lib/Combine/Background.php +107 -0
- data/templates/project/files/build/tools/css-compressor/lib/Combine/Border.php +98 -0
- data/templates/project/files/build/tools/css-compressor/lib/Combine/BorderOutline.php +109 -0
- data/templates/project/files/build/tools/css-compressor/lib/Combine/BorderRadius.php +262 -0
- data/templates/project/files/build/tools/css-compressor/lib/Combine/Font.php +125 -0
- data/templates/project/files/build/tools/css-compressor/lib/Combine/List.php +104 -0
- data/templates/project/files/build/tools/css-compressor/lib/Combine/MarginPadding.php +190 -0
- data/templates/project/files/build/tools/css-compressor/lib/Compress.php +212 -0
- data/templates/project/files/build/tools/css-compressor/lib/Control.php +236 -0
- data/templates/project/files/build/tools/css-compressor/lib/Exception.php +32 -0
- data/templates/project/files/build/tools/css-compressor/lib/Format.php +187 -0
- data/templates/project/files/build/tools/css-compressor/lib/Individuals.php +307 -0
- data/templates/project/files/build/tools/css-compressor/lib/Numeric.php +103 -0
- data/templates/project/files/build/tools/css-compressor/lib/Option.php +133 -0
- data/templates/project/files/build/tools/css-compressor/lib/Organize.php +149 -0
- data/templates/project/files/build/tools/css-compressor/lib/Selectors.php +245 -0
- data/templates/project/files/build/tools/css-compressor/lib/Setup.php +292 -0
- data/templates/project/files/build/tools/css-compressor/lib/Trim.php +213 -0
- data/templates/project/files/build/tools/css-compressor/license.txt +21 -0
- data/templates/project/files/build/tools/htmlcompressor-0.9.8.jar +0 -0
- data/templates/project/files/build/tools/jpegtran.exe +0 -0
- data/templates/project/files/build/tools/optipng-0.6.4-exe/LICENSE.txt +21 -0
- data/templates/project/files/build/tools/optipng-0.6.4-exe/optipng.exe +0 -0
- data/templates/project/files/build/tools/yuicompressor-2.4.2.jar +0 -0
- data/templates/project/files/crossdomain.xml +25 -0
- data/templates/project/files/favicon.ico +0 -0
- data/templates/project/files/gitignore.txt +32 -0
- data/templates/project/files/gitignore_placeholder.txt +2 -0
- data/templates/project/files/google.yml +22 -0
- data/templates/project/files/htaccess +415 -0
- data/templates/project/files/humans.txt +43 -0
- data/templates/project/files/lighttpd.conf +149 -0
- data/templates/project/files/mime.types +80 -0
- data/templates/project/files/nginx.conf +108 -0
- data/templates/project/files/robots.txt +5 -0
- data/templates/project/files/web.config +207 -0
- data/templates/project/handheld.scss +8 -0
- data/templates/project/index.html +81 -0
- data/templates/project/javascripts/libs/dd_belatedpng.js +13 -0
- data/templates/project/javascripts/libs/jquery-1.4.4.js +7179 -0
- data/templates/project/javascripts/libs/jquery-1.4.4.min.js +167 -0
- data/templates/project/javascripts/libs/modernizr-1.6.min.js +30 -0
- data/templates/project/javascripts/plugins.js +13 -0
- data/templates/project/javascripts/rails.js +156 -0
- data/templates/project/javascripts/script.js +26 -0
- data/templates/project/manifest.rb +101 -0
- data/templates/project/partials/_base.scss +23 -0
- data/templates/project/style.scss +70 -0
- metadata +171 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* CSS Compressor [VERSION]
|
4
|
+
* [DATE]
|
5
|
+
* Corey Hart @ http://www.codenothing.com
|
6
|
+
*/
|
7
|
+
|
8
|
+
Class CSSCompression_Combine_Font
|
9
|
+
{
|
10
|
+
/**
|
11
|
+
* Combine Patterns
|
12
|
+
*
|
13
|
+
* @class Control: Compression Controller
|
14
|
+
* @class Combine: Combine Controller
|
15
|
+
* @param (regex) rfont: Font matching
|
16
|
+
* @param (array) groupings: Set of font combinationals
|
17
|
+
*/
|
18
|
+
private $Control;
|
19
|
+
private $Combine;
|
20
|
+
private $rfont = "/(^|(?<!\\\);)(font|line)-(style|variant|weight|size|height|family):(.*?)((?<!\\\);|$)/";
|
21
|
+
private $groupings = array(
|
22
|
+
array( 'font-style', 'font-variant', 'font-weight', 'size/height', 'font-family' ),
|
23
|
+
array( 'font-style', 'font-variant', 'font-weight', 'font-size', 'font-family' ),
|
24
|
+
array( 'font-style', 'font-variant', 'size/height', 'font-family' ),
|
25
|
+
array( 'font-style', 'font-variant', 'font-size', 'font-family' ),
|
26
|
+
array( 'font-style', 'font-weight', 'size/height', 'font-family' ),
|
27
|
+
array( 'font-style', 'font-weight', 'font-size', 'font-family' ),
|
28
|
+
array( 'font-variant', 'font-weight', 'size/height', 'font-family' ),
|
29
|
+
array( 'font-variant', 'font-weight', 'font-size', 'font-family' ),
|
30
|
+
array( 'font-weight', 'size/height', 'font-family' ),
|
31
|
+
array( 'font-weight', 'font-size', 'font-family' ),
|
32
|
+
array( 'font-variant', 'size/height', 'font-family' ),
|
33
|
+
array( 'font-variant', 'font-size', 'font-family' ),
|
34
|
+
array( 'font-style', 'size/height', 'font-family' ),
|
35
|
+
array( 'font-style', 'font-size', 'font-family' ),
|
36
|
+
array( 'size/height', 'font-family' ),
|
37
|
+
array( 'font-size', 'font-family' ),
|
38
|
+
);
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Stash a reference to the controller & combiner
|
42
|
+
*
|
43
|
+
* @param (class) control: CSSCompression Controller
|
44
|
+
* @param (class) combine: CSSCompression Combiner
|
45
|
+
*/
|
46
|
+
public function __construct( CSSCompression_Control $control, CSSCompression_Combine $combine ) {
|
47
|
+
$this->Control = $control;
|
48
|
+
$this->Combine = $combine;
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Combines multiple font-definitions into single definition
|
53
|
+
*
|
54
|
+
* @param (string) val: Rule Set
|
55
|
+
*/
|
56
|
+
public function combine( $val ) {
|
57
|
+
$storage = $this->storage( $val );
|
58
|
+
|
59
|
+
// Loop through each property check and see if they can be replaced
|
60
|
+
foreach ( $this->groupings as $props ) {
|
61
|
+
if ( $replace = $this->Combine->searchDefinitions( 'font', $storage, $props ) ) {
|
62
|
+
break;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
// If replacement string found, run it on all declarations
|
67
|
+
if ( $replace ) {
|
68
|
+
$pos = 0;
|
69
|
+
while ( preg_match( $this->rfont, $val, $match, PREG_OFFSET_CAPTURE, $pos ) ) {
|
70
|
+
if ( ! isset( $storage['line-height'] ) && stripos( $match[ 0 ][ 0 ], 'line-height') === 0 ) {
|
71
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $match[ 0 ][ 0 ] ) - 1;
|
72
|
+
continue;
|
73
|
+
}
|
74
|
+
$colon = strlen( $match[ 1 ][ 0 ] );
|
75
|
+
$val = substr_replace( $val, $replace, $match[ 0 ][ 1 ] + $colon, strlen( $match[ 0 ][ 0 ] ) - $colon );
|
76
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $replace ) - $colon - 1;
|
77
|
+
$replace = '';
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
// Return converted val
|
82
|
+
return $val;
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Builds a storage object for iteration
|
87
|
+
*
|
88
|
+
* @param (string) val: Rule Set
|
89
|
+
*/
|
90
|
+
private function storage( $val ) {
|
91
|
+
$storage = array();
|
92
|
+
|
93
|
+
// Find all possible occurences and build the replacement
|
94
|
+
$pos = 0;
|
95
|
+
while ( preg_match( $this->rfont, $val, $match, PREG_OFFSET_CAPTURE, $pos ) ) {
|
96
|
+
$storage[ $match[ 2 ][ 0 ] . '-' . $match[ 3 ][ 0 ] ] = $match[ 4 ][ 0 ];
|
97
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $match[ 0 ][ 0 ] ) - 1;
|
98
|
+
}
|
99
|
+
|
100
|
+
// Combine font-size & line-height if possible
|
101
|
+
if ( isset( $storage['font-size'] ) && isset( $storage['line-height'] ) ) {
|
102
|
+
$storage['size/height'] = $storage['font-size'] . '/' . $storage['line-height'];
|
103
|
+
unset( $storage['font-size'], $storage['line-height'] );
|
104
|
+
}
|
105
|
+
|
106
|
+
return $storage;
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Access to private methods for testing
|
111
|
+
*
|
112
|
+
* @param (string) method: Method to be called
|
113
|
+
* @param (array) args: Array of paramters to be passed in
|
114
|
+
*/
|
115
|
+
public function access( $method, $args ) {
|
116
|
+
if ( method_exists( $this, $method ) ) {
|
117
|
+
return call_user_func_array( array( $this, $method ), $args );
|
118
|
+
}
|
119
|
+
else {
|
120
|
+
throw new CSSCompression_Exception( "Unknown method in Font Class - " . $method );
|
121
|
+
}
|
122
|
+
}
|
123
|
+
};
|
124
|
+
|
125
|
+
?>
|
@@ -0,0 +1,104 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* CSS Compressor [VERSION]
|
4
|
+
* [DATE]
|
5
|
+
* Corey Hart @ http://www.codenothing.com
|
6
|
+
*/
|
7
|
+
|
8
|
+
Class CSSCompression_Combine_List
|
9
|
+
{
|
10
|
+
/**
|
11
|
+
* Combine Patterns
|
12
|
+
*
|
13
|
+
* @class Control: Compression Controller
|
14
|
+
* @class Combine: Combine Controller
|
15
|
+
* @param (regex) rlist: List style matching
|
16
|
+
* @param (array) groupings: Group of list combinationals
|
17
|
+
*/
|
18
|
+
private $Control;
|
19
|
+
private $Combine;
|
20
|
+
private $rlist = "/(^|(?<!\\\);)list-style-(type|position|image):(.*?)((?<!\\\);|$)/";
|
21
|
+
private $groupings = array(
|
22
|
+
array( 'type', 'position', 'image' ),
|
23
|
+
array( 'type', 'position' ),
|
24
|
+
array( 'type', 'image' ),
|
25
|
+
array( 'position', 'image' ),
|
26
|
+
array( 'type' ),
|
27
|
+
array( 'position' ),
|
28
|
+
array( 'image' ),
|
29
|
+
);
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Stash a reference to the controller & combiner
|
33
|
+
*
|
34
|
+
* @param (class) control: CSSCompression Controller
|
35
|
+
* @param (class) combine: CSSCompression Combiner
|
36
|
+
*/
|
37
|
+
public function __construct( CSSCompression_Control $control, CSSCompression_Combine $combine ) {
|
38
|
+
$this->Control = $control;
|
39
|
+
$this->Combine = $combine;
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Combines multiple list style props into single definition
|
44
|
+
*
|
45
|
+
* @param (string) val: Rule Set
|
46
|
+
*/
|
47
|
+
public function combine( $val ) {
|
48
|
+
// If replacement string found, run it on all declarations
|
49
|
+
if ( ( $replace = $this->replace( $val ) ) !== false ) {
|
50
|
+
$pos = 0;
|
51
|
+
while ( preg_match( $this->rlist, $val, $match, PREG_OFFSET_CAPTURE, $pos ) ) {
|
52
|
+
$colon = strlen( $match[ 1 ][ 0 ] );
|
53
|
+
$val = substr_replace( $val, $replace, $match[ 0 ][ 1 ] + $colon, strlen( $match[ 0 ][ 0 ] ) - $colon );
|
54
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $replace ) - $colon - 1;
|
55
|
+
$replace = '';
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
// Return converted val
|
60
|
+
return $val;
|
61
|
+
}
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Build the replacement string for list props
|
65
|
+
*
|
66
|
+
* @param (string) val: Rule Set
|
67
|
+
*/
|
68
|
+
private function replace( $val ) {
|
69
|
+
$storage = array();
|
70
|
+
$pos = 0;
|
71
|
+
|
72
|
+
// Find all possible occurences and build the replacement
|
73
|
+
while ( preg_match( $this->rlist, $val, $match, PREG_OFFSET_CAPTURE, $pos ) ) {
|
74
|
+
$storage[ $match[ 2 ][ 0 ] ] = $match[ 3 ][ 0 ];
|
75
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $match[ 0 ][ 0 ] ) - 1;
|
76
|
+
}
|
77
|
+
|
78
|
+
// Run background checks and get replacement str
|
79
|
+
foreach ( $this->groupings as $props ) {
|
80
|
+
if ( $replace = $this->Combine->searchDefinitions( 'list-style', $storage, $props ) ) {
|
81
|
+
return $replace;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
return false;
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Access to private methods for testing
|
90
|
+
*
|
91
|
+
* @param (string) method: Method to be called
|
92
|
+
* @param (array) args: Array of paramters to be passed in
|
93
|
+
*/
|
94
|
+
public function access( $method, $args ) {
|
95
|
+
if ( method_exists( $this, $method ) ) {
|
96
|
+
return call_user_func_array( array( $this, $method ), $args );
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
throw new CSSCompression_Exception( "Unknown method in List Class - " . $method );
|
100
|
+
}
|
101
|
+
}
|
102
|
+
};
|
103
|
+
|
104
|
+
?>
|
@@ -0,0 +1,190 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* CSS Compressor [VERSION]
|
4
|
+
* [DATE]
|
5
|
+
* Corey Hart @ http://www.codenothing.com
|
6
|
+
*/
|
7
|
+
|
8
|
+
Class CSSCompression_Combine_MarginPadding
|
9
|
+
{
|
10
|
+
/**
|
11
|
+
* Combine Patterns
|
12
|
+
*
|
13
|
+
* @class Control: Compression Controller
|
14
|
+
* @class Combine: Combine Controller
|
15
|
+
* @param (regex) rspace: Checks for space without an escape '\' character before it
|
16
|
+
* @param (regex) rmp: Margin/Padding matching
|
17
|
+
* @param (regex) rmpbase: Margin/Padding base match
|
18
|
+
*/
|
19
|
+
private $Control;
|
20
|
+
private $Combine;
|
21
|
+
private $rspace = "/(?<!\\\)\s/";
|
22
|
+
private $rmp = "/(^|(?<!\\\);)(margin|padding)-(top|right|bottom|left):(.*?)((?<!\\\);|$)/";
|
23
|
+
private $rmpbase = "/(^|(?<!\\\);)(margin|padding):(.*?)((?<!\\\);|$)/";
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Stash a reference to the controller & combiner
|
27
|
+
*
|
28
|
+
* @param (class) control: CSSCompression Controller
|
29
|
+
* @param (class) combine: CSSCompression Combiner
|
30
|
+
*/
|
31
|
+
public function __construct( CSSCompression_Control $control, CSSCompression_Combine $combine ) {
|
32
|
+
$this->Control = $control;
|
33
|
+
$this->Combine = $combine;
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Combines multiple directional properties of
|
38
|
+
* margin/padding into single definition.
|
39
|
+
*
|
40
|
+
* @param (string) val: Rule Set
|
41
|
+
*/
|
42
|
+
public function combine( $val ) {
|
43
|
+
$val = $this->expand( $val );
|
44
|
+
$storage = $this->storage( $val );
|
45
|
+
$pos = 0;
|
46
|
+
|
47
|
+
// Now rebuild the string replacing all instances of margin/padding if shorthand exists
|
48
|
+
while ( preg_match( $this->rmp, $val, $match, PREG_OFFSET_CAPTURE, $pos ) ) {
|
49
|
+
$prop = $match[ 2 ][ 0 ];
|
50
|
+
if ( isset( $storage[ $prop ] ) ) {
|
51
|
+
$colon = strlen( $match[ 1 ][ 0 ] );
|
52
|
+
$val = substr_replace( $val, $storage[ $prop ], $match[ 0 ][ 1 ] + $colon, strlen( $match[ 0 ][ 0 ] ) - $colon );
|
53
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $storage[ $prop ] ) - $colon - 1;
|
54
|
+
$storage[ $prop ] = '';
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $match[ 0 ][ 0 ] ) - 1;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
// Return converted val
|
62
|
+
return $val;
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Build the storage object for iteration
|
67
|
+
*
|
68
|
+
* @param (string) val: Rule Set
|
69
|
+
*/
|
70
|
+
private function storage( $val ) {
|
71
|
+
$storage = array();
|
72
|
+
$pos = 0;
|
73
|
+
|
74
|
+
// Find all possible occurences of margin/padding and mark their directional value
|
75
|
+
while ( preg_match( $this->rmp, $val, $match, PREG_OFFSET_CAPTURE, $pos ) ) {
|
76
|
+
if ( ! isset( $storage[ $match[ 2 ][ 0 ] ] ) ) {
|
77
|
+
$storage[ $match[ 2 ][ 0 ] ] = array( $match[ 3 ][ 0 ] => $match[ 4 ][ 0 ] );
|
78
|
+
}
|
79
|
+
|
80
|
+
// Override double written properties
|
81
|
+
$storage[ $match[ 2 ][ 0 ] ][ $match[ 3 ][ 0 ] ] = $match[ 4 ][ 0 ];
|
82
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $match[ 0 ][ 0 ] ) - 1;
|
83
|
+
}
|
84
|
+
|
85
|
+
// Go through each tag for possible combination
|
86
|
+
foreach ( $storage as $tag => $arr ) {
|
87
|
+
// Only combine if all 4 definitions are found
|
88
|
+
if ( count( $arr ) == 4 && ! $this->Combine->checkUncombinables( $arr ) ) {
|
89
|
+
// All 4 are the same
|
90
|
+
if ( $arr['top'] == $arr['bottom'] && $arr['left'] == $arr['right'] && $arr['top'] == $arr['left'] ) {
|
91
|
+
$storage[ $tag ] = "$tag:" . $arr['top'] . ';';
|
92
|
+
}
|
93
|
+
// Opposites are the same
|
94
|
+
else if ( $arr['top'] == $arr['bottom'] && $arr['left'] == $arr['right'] ) {
|
95
|
+
$storage[ $tag ] = "$tag:" . $arr['top'] . ' ' . $arr['left'] . ';';
|
96
|
+
}
|
97
|
+
// 3-point directional
|
98
|
+
else if ( $arr['right'] == $arr['left'] ) {
|
99
|
+
$storage[ $tag ] = "$tag:" . $arr['top'] . ' ' . $arr['right'] . ' ' . $arr['bottom'] . ';';
|
100
|
+
}
|
101
|
+
// none are the same, but can still use shorthand notation
|
102
|
+
else {
|
103
|
+
$storage[ $tag ] = "$tag:" . $arr['top'] . ' ' . $arr['right'] . ' ' . $arr['bottom'] . ' ' . $arr['left'] . ';';
|
104
|
+
}
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
unset( $storage[ $tag ] );
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
return $storage;
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Explodes shorthanded margin/padding properties for later combination
|
116
|
+
*
|
117
|
+
* @param (string) val: Rule set
|
118
|
+
*/
|
119
|
+
private function expand( $val ) {
|
120
|
+
$pos = 0;
|
121
|
+
while ( preg_match( $this->rmpbase, $val, $match, PREG_OFFSET_CAPTURE, $pos ) ) {
|
122
|
+
$replace = '';
|
123
|
+
$prop = $match[ 2 ][ 0 ];
|
124
|
+
$value = preg_split( $this->rspace, trim( $match[ 3 ][ 0 ] ) );
|
125
|
+
$positions = array(
|
126
|
+
'top' => 0,
|
127
|
+
'right' => 0,
|
128
|
+
'bottom' => 0,
|
129
|
+
'left' => 0
|
130
|
+
);
|
131
|
+
|
132
|
+
// Skip uncombinables
|
133
|
+
if ( $this->Combine->checkUncombinables( $value ) ) {
|
134
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $match[ 0 ][ 0 ] );
|
135
|
+
continue;
|
136
|
+
}
|
137
|
+
|
138
|
+
// Each position needs a value
|
139
|
+
switch ( count( $value ) ) {
|
140
|
+
case 1:
|
141
|
+
$positions['top'] = $positions['right'] = $positions['bottom'] = $positions['left'] = $value[ 0 ];
|
142
|
+
break;
|
143
|
+
case 2:
|
144
|
+
$positions['top'] = $positions['bottom'] = $value[ 0 ];
|
145
|
+
$positions['right'] = $positions['left'] = $value[ 1 ];
|
146
|
+
break;
|
147
|
+
case 3:
|
148
|
+
$positions['top'] = $value[ 0 ];
|
149
|
+
$positions['right'] = $positions['left'] = $value[ 1 ];
|
150
|
+
$positions['bottom'] = $value[ 2 ];
|
151
|
+
break;
|
152
|
+
case 4:
|
153
|
+
$positions['top'] = $value[ 0 ];
|
154
|
+
$positions['right'] = $value[ 1 ];
|
155
|
+
$positions['bottom'] = $value[ 2 ];
|
156
|
+
$positions['left'] = $value[ 3 ];
|
157
|
+
break;
|
158
|
+
default:
|
159
|
+
continue;
|
160
|
+
}
|
161
|
+
|
162
|
+
// Build the replacement
|
163
|
+
foreach ( $positions as $p => $v ) {
|
164
|
+
$replace .= "$prop-$p:$v;";
|
165
|
+
}
|
166
|
+
$colon = strlen( $match[ 1 ][ 0 ] );
|
167
|
+
$val = substr_replace( $val, $replace, $match[ 0 ][ 1 ] + $colon, strlen( $match[ 0 ][ 0 ] ) - $colon );
|
168
|
+
$pos = $match[ 0 ][ 1 ] + strlen( $replace ) - $colon - 1;
|
169
|
+
}
|
170
|
+
|
171
|
+
return $val;
|
172
|
+
}
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Access to private methods for testing
|
176
|
+
*
|
177
|
+
* @param (string) method: Method to be called
|
178
|
+
* @param (array) args: Array of paramters to be passed in
|
179
|
+
*/
|
180
|
+
public function access( $method, $args ) {
|
181
|
+
if ( method_exists( $this, $method ) ) {
|
182
|
+
return call_user_func_array( array( $this, $method ), $args );
|
183
|
+
}
|
184
|
+
else {
|
185
|
+
throw new CSSCompression_Exception( "Unknown method in MarginPadding Class - " . $method );
|
186
|
+
}
|
187
|
+
}
|
188
|
+
};
|
189
|
+
|
190
|
+
?>
|
@@ -0,0 +1,212 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* CSS Compressor [VERSION]
|
4
|
+
* [DATE]
|
5
|
+
* Corey Hart @ http://www.codenothing.com
|
6
|
+
*/
|
7
|
+
|
8
|
+
Class CSSCompression_Compress
|
9
|
+
{
|
10
|
+
/**
|
11
|
+
* Trim Patterns
|
12
|
+
*
|
13
|
+
* @param (array) options: Reference to options
|
14
|
+
* @param (array) stats: Reference to stats
|
15
|
+
* @param (regex) rsemicolon: Checks for semicolon without an escape '\' character before it
|
16
|
+
* @param (regex) rcolon: Checks for colon without an escape '\' character before it
|
17
|
+
* @param (regex) rspace: Checks for space without an escape '\' character before it
|
18
|
+
*/
|
19
|
+
private $options = array();
|
20
|
+
private $stats = array();
|
21
|
+
private $rsemicolon = "/(?<!\\\);/";
|
22
|
+
private $rcolon = "/(?<!\\\):/";
|
23
|
+
private $rspace = "/(?<!\\\)\s/";
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Other inner classes that get used within compression
|
27
|
+
*
|
28
|
+
* @class Control: Compression Controller
|
29
|
+
* @class Trim: Trim Instance
|
30
|
+
* @class Setup: Setup Instance
|
31
|
+
* @class Format: Formatting Instance
|
32
|
+
* @class Combine: Combine Instance
|
33
|
+
* @class Cleanup: Cleanup Instance
|
34
|
+
* @class Organize: Organize Instance
|
35
|
+
* @class Selectors: Selectors Instance
|
36
|
+
* @param (array) others: List of above classes for copying
|
37
|
+
*/
|
38
|
+
private $Control;
|
39
|
+
private $Trim;
|
40
|
+
private $Setup;
|
41
|
+
private $Format;
|
42
|
+
private $Combine;
|
43
|
+
private $Cleanup;
|
44
|
+
private $Organize;
|
45
|
+
private $Selectors;
|
46
|
+
private $others = array(
|
47
|
+
'Trim',
|
48
|
+
'Setup',
|
49
|
+
'Format',
|
50
|
+
'Combine',
|
51
|
+
'Cleanup',
|
52
|
+
'Organize',
|
53
|
+
'Selectors',
|
54
|
+
);
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Stash a reference to the controller on each instantiation
|
58
|
+
*
|
59
|
+
* @param (class) control: CSSCompression Controller
|
60
|
+
*/
|
61
|
+
public function __construct( CSSCompression_Control $control ) {
|
62
|
+
$this->Control = $control;
|
63
|
+
$this->options = &$control->Option->options;
|
64
|
+
$this->stats = &$control->stats;
|
65
|
+
|
66
|
+
foreach ( $this->others as $class ) {
|
67
|
+
$this->$class = $control->$class;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Centralized function to run css compression.
|
73
|
+
*
|
74
|
+
* @param (string) css: Stylesheet to compresss
|
75
|
+
*/
|
76
|
+
public function compress( $css ) {
|
77
|
+
$setup = $this->setup( $css );
|
78
|
+
$setup = $this->rulesets( $setup );
|
79
|
+
$css = $this->readability( $setup );
|
80
|
+
|
81
|
+
// Attach plea to top of page with unknown blocks
|
82
|
+
if ( $this->options['add-unknown'] && count( $setup['unknown'] ) ) {
|
83
|
+
$css = "/*\nThere are unknown blocks in the sheet, please please please open an issue with your sheet attached to it:\n"
|
84
|
+
. "https://github.com/codenothing/css-compressor/issues\n"
|
85
|
+
. "Thank You --\n\n"
|
86
|
+
. implode( "\n", $setup['unknown'] )
|
87
|
+
. "\n*/\n"
|
88
|
+
. $css;
|
89
|
+
}
|
90
|
+
|
91
|
+
// Mark final file size
|
92
|
+
$this->stats['after']['size'] = strlen( $css = trim( $css ) );
|
93
|
+
|
94
|
+
// Return compressed css
|
95
|
+
return $css;
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Runs css through initial setup handlers
|
100
|
+
*
|
101
|
+
* @param (string) css: Sheet to compress
|
102
|
+
*/
|
103
|
+
private function setup( $css ) {
|
104
|
+
// Initial stats
|
105
|
+
$this->stats['before']['time'] = microtime( true );
|
106
|
+
$this->stats['before']['size'] = strlen( $css );
|
107
|
+
|
108
|
+
// Initial trimming
|
109
|
+
$css = $this->Trim->trim( $css );
|
110
|
+
|
111
|
+
// Do a little tokenizing, compress each property individually
|
112
|
+
$setup = $this->Setup->setup( $css );
|
113
|
+
|
114
|
+
// Mark number of selectors pre-combine
|
115
|
+
$this->stats['before']['selectors'] = count( $setup['selectors'] );
|
116
|
+
|
117
|
+
return $setup;
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Focus compressions on each rule set
|
122
|
+
*
|
123
|
+
* @param (array) setup: Array containing selectors and rule sets
|
124
|
+
*/
|
125
|
+
private function rulesets( $setup ) {
|
126
|
+
// Do selector specific compressions
|
127
|
+
$this->Selectors->selectors( $setup['selectors'] );
|
128
|
+
|
129
|
+
// Look at each group of properties as a whole, and compress/combine similiar definitions
|
130
|
+
$this->Combine->combine( $setup['selectors'], $setup['details'] );
|
131
|
+
|
132
|
+
// If order isn't important, run comination functions before and after compressions to catch all instances
|
133
|
+
// Be sure to prune before hand for higher chance of matching
|
134
|
+
if ( $this->options['organize'] ) {
|
135
|
+
$this->Cleanup->cleanup( $setup['selectors'], $setup['details'] );
|
136
|
+
$this->Organize->organize( $setup['selectors'], $setup['details'] );
|
137
|
+
$this->Combine->combine( $setup['selectors'], $setup['details'] );
|
138
|
+
}
|
139
|
+
|
140
|
+
// Do final maintenace work, remove injected property/values
|
141
|
+
$this->Cleanup->cleanup( $setup['selectors'], $setup['details'] );
|
142
|
+
|
143
|
+
// Run final counters before full cleanup
|
144
|
+
$this->finalCount( $setup['selectors'], $setup['details'] );
|
145
|
+
|
146
|
+
return $setup;
|
147
|
+
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Runs final counts on selectors and props
|
151
|
+
*
|
152
|
+
* @param (array) selectors: Selector rules
|
153
|
+
* @param (array) details: Rule sets
|
154
|
+
*/
|
155
|
+
private function finalCount( $selectors, $details ) {
|
156
|
+
// Selectors and props
|
157
|
+
$this->stats['after']['selectors'] = count( $selectors );
|
158
|
+
foreach ( $details as $item ) {
|
159
|
+
$props = preg_split( $this->rsemicolon, $item );
|
160
|
+
|
161
|
+
// Make sure count is true
|
162
|
+
foreach ( $props as $k => $v ) {
|
163
|
+
if ( ! isset( $v ) || $v == '' ) {
|
164
|
+
unset( $props[ $k ] );
|
165
|
+
}
|
166
|
+
}
|
167
|
+
$this->stats['after']['props'] += count( $props );
|
168
|
+
}
|
169
|
+
|
170
|
+
// Final count for stats
|
171
|
+
$this->stats['after']['time'] = microtime( true );
|
172
|
+
}
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Formats the compressed rule sets into a stylesheet
|
176
|
+
*
|
177
|
+
* @param (array) setup: Array containing selectors and rule sets
|
178
|
+
*/
|
179
|
+
private function readability( $setup ) {
|
180
|
+
// Format css to users preference
|
181
|
+
$css = $this->Format->readability( $this->options['readability'], $setup['selectors'], $setup['details'] );
|
182
|
+
|
183
|
+
// Intros
|
184
|
+
foreach ( $setup as $value ) {
|
185
|
+
if ( $value && is_string( $value ) ) {
|
186
|
+
$css = $value . $css;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
// Remove escapables
|
191
|
+
$css = $this->Cleanup->removeInjections( $css );
|
192
|
+
|
193
|
+
return $css;
|
194
|
+
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Access to private methods for testing
|
198
|
+
*
|
199
|
+
* @param (string) method: Method to be called
|
200
|
+
* @param (array) args: Array of paramters to be passed in
|
201
|
+
*/
|
202
|
+
public function access( $method, $args ) {
|
203
|
+
if ( method_exists( $this, $method ) ) {
|
204
|
+
return call_user_func_array( array( $this, $method ), $args );
|
205
|
+
}
|
206
|
+
else {
|
207
|
+
throw new CSSCompression_Exception( "Unknown method in Compress Class - " . $method );
|
208
|
+
}
|
209
|
+
}
|
210
|
+
};
|
211
|
+
|
212
|
+
?>
|