Skip to content
Browse files

new plugin: Rem

  • Loading branch information...
1 parent 7ef8787 commit 7ef47d9673f7386eb98e41e802265dc4e4b09c39 @oscarotero committed Dec 7, 2011
Showing with 107 additions and 1 deletion.
  1. +97 −0 Stylecow/Plugins/Rem.php
  2. +1 −0 demo/demo.html
  3. +2 −1 demo/stylecow.php
  4. +7 −0 demo/styles1.css
View
97 Stylecow/Plugins/Rem.php
@@ -0,0 +1,97 @@
+<?php
+/**
+* Rem plugin (version 0.1)
+* for styleCow PHP library
+*
+* 2011. Created by Oscar Otero (http://oscarotero.com / http://anavallasuiza.com)
+*/
+
+namespace Stylecow;
+
+class Rem implements Plugins_interface {
+ public $position = 4;
+
+ private $Css;
+ private $rem = 16;
+
+
+ /**
+ * public function __construct (Stylecow $Css)
+ *
+ * return none
+ */
+ public function __construct (Stylecow $Css) {
+ $this->Css = $Css;
+ }
+
+
+ /**
+ * public function transform ()
+ *
+ * return none
+ */
+ public function transform () {
+ $this->Css->code = $this->_transform($this->Css->code);
+ }
+
+
+
+ /**
+ * private function _transform (array $array_code)
+ *
+ * return none
+ */
+ private function _transform ($array_code) {
+ foreach ($array_code as $k_code => $code) {
+ if ($code['is_css'] && $code['properties'] && $code['selector'] && in_array('body', $code['selector'])) {
+ foreach ($code['properties'] as $property) {
+ if ($property['name'] === 'font-size') {
+ $this->rem = floatval($property['value'][0]) * 16;
+ }
+ }
+ }
+
+ if ($code['properties']) {
+ $new_properties = array();
+
+ foreach ($code['properties'] as $k_property => $property) {
+ if (preg_match('/([0-9]+)rem/', implode($property['value']), $match)) {
+ $new_values = array();
+
+ foreach ($property['value'] as $k_value => $value) {
+ if (strpos($value, 'rem') === false) {
+ $new_values[] = $value;
+ }
+
+ $new_value = preg_replace_callback('/([0-9]+)rem/', array($this, 'remCallback'), $value);
+
+ if ($new_value !== $value) {
+ $new_values[] = $new_value;
+ }
+ }
+
+ $new_properties[] = array('name' => $property['name'], 'value' => $new_values);
+ }
+
+ $new_properties[] = $property;
+ }
+
+ $array_code[$k_code]['properties'] = $new_properties;
+ }
+ }
+
+
+ return $array_code;
+ }
+
+
+
+ /**
+ * private function remCallback (array $matches)
+ *
+ * return none
+ */
+ private function remCallback ($matches) {
+ return ($this->rem * $matches[1]).'px';
+ }
+}
View
1 demo/demo.html
@@ -6,6 +6,7 @@
<body>
<div class="wrapper">
+ ola
<div class="menu">
<span class="color l10"></span>
<span class="color l20"></span>
View
3 demo/stylecow.php
@@ -13,7 +13,8 @@
'Matches',
'Nested_rules',
'Animate',
- 'Color'
+ 'Color',
+ 'Rem'
));
$styleCow->show();
View
7 demo/styles1.css
@@ -6,11 +6,18 @@ rgb(51, 153, 0)
hsl(100, 100%, 30%)
*/
+body {
+ font-size: 1em;
+}
.wrapper {
+ font-size: 2em;
width: 960px;
background: url(http://griddle.it/960-12-30) repeat-y;
margin: 0 auto;
}
+.wrapper div {
+ font-size: 1rem;
+}
$grid {
width: 960px;
columns: 12;

0 comments on commit 7ef47d9

Please sign in to comment.
Something went wrong with that request. Please try again.