Skip to content
Browse files

Added import syntax, and made better example

  • Loading branch information...
1 parent 49de603 commit 6dc3f8560b419823de6b3c61949a86a327fadfe3 Stuart Loxton committed
Showing with 40 additions and 30 deletions.
  1. +6 −0 example.php
  2. +9 −30 php-saas.php
  3. +23 −0 styles/example.psaas
  4. +2 −0 styles/example2.psaas
View
6 example.php
@@ -0,0 +1,6 @@
+<?php
+require('php-saas.php');
+$examplePHPSaas = file_get_contents('styles/example.psaas');
+$phpSaas = new PHPSaas($examplePHPSaas);
+echo $phpSaas->body;
+?>
View
39 php-saas.php
@@ -1,34 +1,11 @@
<?php
-$examplePMMSE = <<<EOD
-@var forecolor = #ff0000;
-@var backcolor = #00ff00;
-@mixin alert
- border: 1px solid @backcolor
- height: 100%
-
-@mixin clear
- content: ''
-
-body
- color: @forecolor
- background: @backcolor
-
- div
- margin: 0
-
-#test
- =alert
- =clear
- color: @forecolor
-EOD;
-
-class PMMSE {
+class PHPSaas {
var $vars = array();
var $selectors = array();
- function PMMSE ($css = '') {
+ function PHPSaas ($css = '') {
$this->body = $css;
$this->extractVars();
$this->setVars();
@@ -37,6 +14,11 @@ function PMMSE ($css = '') {
}
function extractVars() {
+ preg_match_all('/@import \'([^\']+)\'/', $this->body, $matches);
+ foreach($matches[0] as $key => $line) {
+ $this->body = str_replace($line, file_get_contents($matches[1][0].'.psaas'), $this->body);
+ }
+
preg_match_all('/@var ([a-z]+) = ([^;]+);/', $this->body, $matches);
foreach($matches[1] as $key => $var) {
$this->vars[$var] = $matches[2][$key];
@@ -84,10 +66,7 @@ function runIndentationLoop() {
}
function optimise() {
- // $this->body = trim(preg_replace('/\}([^a-z]*)/', '} ', $this->body));
+ $this->body = trim(preg_replace('/\}([^a-z]*)/', '} ', $this->body));
}
-}
-
-$pmmse = new PMMSE($examplePMMSE);
-echo $pmmse->body;
+}
View
23 styles/example.psaas
@@ -0,0 +1,23 @@
+@var forecolor = #ff0000;
+@var backcolor = #00ff00;
+
+@mixin alert
+ border: 1px solid @backcolor
+ height: 100%
+
+@mixin clear
+ content: ''
+
+body
+ color: @forecolor
+ background: @backcolor
+
+ div
+ margin: 0
+
+#test
+ =alert
+ =clear
+ color: @forecolor
+
+@import 'styles/example2'
View
2 styles/example2.psaas
@@ -0,0 +1,2 @@
+#test2
+ =alert

0 comments on commit 6dc3f85

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