Rev 37 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
37 | PointedEar | 1 | <?php |
2 | |||
3 | namespace de\pointedears\css\least; |
||
4 | |||
5 | /** |
||
38 | PointedEar | 6 | * Mix-ins for the LEAST CSS preprocessor |
37 | PointedEar | 7 | * |
8 | * @author Thomas 'PointedEars' Lahn <php@PointedEars.de> |
||
9 | */ |
||
10 | abstract class Mixins |
||
11 | { |
||
38 | PointedEar | 12 | /** @section General functions */ |
13 | |||
37 | PointedEar | 14 | /** |
38 | PointedEar | 15 | * Generates a CSS section for each keyword prefix. |
37 | PointedEar | 16 | * |
38 | PointedEar | 17 | * @param string $keyword |
18 | * Section keyword |
||
37 | PointedEar | 19 | * @param string $params |
38 | PointedEar | 20 | * Section parameters (name, medium, etc.) |
21 | * @param string $content |
||
22 | * Section content |
||
23 | * @param array[string] $prefixes |
||
24 | * Keyword prefixes |
||
37 | PointedEar | 25 | */ |
38 | PointedEar | 26 | public static function prefix_section ($keyword, $params, |
27 | $content, array $prefixes) |
||
37 | PointedEar | 28 | { |
29 | ob_start(); |
||
30 | foreach ($prefixes as $prefix) |
||
31 | { |
||
38 | PointedEar | 32 | echo "@{$prefix}{$keyword} {$params} {\n {$content}\n}\n"; |
37 | PointedEar | 33 | } |
34 | ob_end_flush(); |
||
35 | } |
||
38 | PointedEar | 36 | |
37 | PointedEar | 37 | /** |
38 | * Generates a CSS property declaration whose value is a |
||
38 | PointedEar | 39 | * function call, for each function name prefix. |
37 | PointedEar | 40 | * |
41 | * @param string $property |
||
42 | * Property to be declared |
||
38 | PointedEar | 43 | * @param string $function |
44 | * CSS function to be called |
||
45 | * @param string $args |
||
46 | * Arguments to the function |
||
47 | * @param array[string] $prefixes |
||
48 | * Function name prefixes |
||
37 | PointedEar | 49 | */ |
38 | PointedEar | 50 | public static function prefix_function ($property, $function, $args, |
51 | array $prefixes) |
||
37 | PointedEar | 52 | { |
53 | ob_start(); |
||
54 | foreach ($prefixes as $prefix) |
||
55 | { |
||
38 | PointedEar | 56 | echo "{$property}: {$prefix}{$function}({$args});\n"; |
37 | PointedEar | 57 | } |
58 | ob_end_flush(); |
||
38 | PointedEar | 59 | } |
60 | |||
61 | /** |
||
62 | * Generates a CSS property declaration for each |
||
63 | * property name prefix. |
||
64 | * |
||
65 | * @param string $suffix |
||
66 | * Property name suffix |
||
67 | * @param string $value |
||
68 | * Property value |
||
69 | * @param array[string] $prefixes |
||
70 | * Property name prefixes |
||
71 | */ |
||
72 | public static function prefix_property ($property, $suffix, $value, |
||
73 | array $prefixes) |
||
74 | { |
||
75 | ob_start(); |
||
76 | foreach ($prefixes as $prefix) |
||
77 | { |
||
78 | echo "{$prefix}{$property}{$suffix}: {$value};\n"; |
||
79 | } |
||
80 | ob_end_flush(); |
||
81 | } |
||
82 | |||
83 | /** @section Gradients */ |
||
84 | |||
85 | /** |
||
86 | * Generates a CSS property declaration whose value is a |
||
87 | * <code>linear-gradient()</code> function call for |
||
88 | * each function name prefix. |
||
89 | * |
||
90 | * @param string $property |
||
91 | * Property to be declared |
||
92 | * @param string $args |
||
93 | * Arguments to the <code>linear-gradient()</code> function |
||
94 | * @param array[string] $prefixes (optional) |
||
95 | * Pass to override supported function name prefixes |
||
96 | * @see self::prefix_function() |
||
97 | */ |
||
98 | public static function linear_gradient ($property, $args, |
||
99 | array $prefixes = array('-moz-', '-o-', '-webkit-', '')) |
||
100 | { |
||
101 | self::prefix_function($property, 'linear-gradient', $args, $prefixes); |
||
37 | PointedEar | 102 | } |
38 | PointedEar | 103 | |
104 | /** |
||
105 | * Generates a CSS property declaration whose value is a |
||
106 | * <code>radial-gradient()</code> function call for each |
||
107 | * function name prefix. |
||
108 | * |
||
109 | * @param string $property |
||
110 | * Property to be declared |
||
111 | * @param string $args |
||
112 | * Arguments to the <code>radial-gradient()</code> function |
||
113 | * @param array[string] $prefixes (optional) |
||
114 | * Pass to override supported function name prefixes |
||
115 | * @see self::prefix_function() |
||
116 | */ |
||
117 | public static function radial_gradient ($property, $args, |
||
118 | array $prefixes = array('-moz-', '-webkit-')) |
||
119 | { |
||
120 | self::prefix_function($property, 'radial-gradient', $args, $prefixes); |
||
121 | } |
||
37 | PointedEar | 122 | |
123 | /** |
||
124 | * Generates a CSS <code>transition</code> property declaration |
||
38 | PointedEar | 125 | * for each property name prefix. |
37 | PointedEar | 126 | * |
127 | * @param string $suffix |
||
128 | * Property name suffix |
||
129 | * @param string $value |
||
130 | * Property value |
||
38 | PointedEar | 131 | * @param array[string] $prefixes (optional) |
37 | PointedEar | 132 | * Pass to override supported property name prefixes |
38 | PointedEar | 133 | * @see self::prefix_property() |
37 | PointedEar | 134 | */ |
135 | public static function transition ($suffix, $value, |
||
136 | array $prefixes = array('-moz-', '-webkit-', '')) |
||
137 | { |
||
38 | PointedEar | 138 | self::prefix_property('transition', $suffix, $value, $prefixes); |
37 | PointedEar | 139 | } |
140 | |||
38 | PointedEar | 141 | /** @section Animations */ |
142 | |||
37 | PointedEar | 143 | /** |
144 | * Generates a CSS <code>@keyframes</code> section for |
||
38 | PointedEar | 145 | * each keyword prefix. |
37 | PointedEar | 146 | * |
147 | * @param string $name |
||
38 | PointedEar | 148 | * Animation name as referred by an <code>animation-name</code> |
149 | * property value. |
||
37 | PointedEar | 150 | * @param string $data |
151 | * Keyframes data |
||
38 | PointedEar | 152 | * @param array[string] $prefixes (optional) |
37 | PointedEar | 153 | * Pass to override supported keyword prefixes |
38 | PointedEar | 154 | * @see self::prefix_section() |
37 | PointedEar | 155 | */ |
156 | public static function keyframes ($name, $data, |
||
157 | array $prefixes = array('-moz-', '-webkit-', '')) |
||
158 | { |
||
38 | PointedEar | 159 | self::prefix_section('keyframes', $name, $data, $prefixes); |
37 | PointedEar | 160 | } |
161 | |||
162 | /** |
||
163 | * Generates a CSS <code>animation</code> property declaration |
||
38 | PointedEar | 164 | * for each property name prefix. |
37 | PointedEar | 165 | * |
166 | * @param string $suffix |
||
38 | PointedEar | 167 | * Property name suffix, e.g. <tt>"-name"</tt> for |
168 | * <code>animation-name</code> |
||
37 | PointedEar | 169 | * @param string $value |
170 | * Property value |
||
38 | PointedEar | 171 | * @param array[string] $prefixes (optional) |
37 | PointedEar | 172 | * Pass to override supported property name prefixes |
38 | PointedEar | 173 | * @see self::prefix_property() |
37 | PointedEar | 174 | */ |
175 | public static function animation ($suffix, $value, |
||
176 | array $prefixes = array('-moz-', '-webkit-', '')) |
||
177 | { |
||
38 | PointedEar | 178 | self::prefix_property('animation', $suffix, $value, $prefixes); |
37 | PointedEar | 179 | } |
180 | } |