-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f678e9
commit a619a92
Showing
8 changed files
with
527 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
# it.hce.microframework.core | ||
### a lightweight framework designed for prototyping | ||
|
||
> a lightweight framework designed for prototyping | ||
## Install | ||
|
||
* `php composer.phar create-project hce/microframework projectName` | ||
|
||
or | ||
|
||
* `composer.phar create-project hce/microframework projectName` | ||
|
||
then | ||
|
||
* `cd projectName` | ||
* `npm install` | ||
* Point your webserver to `projectName/public` folder | ||
* Set `public/css` and `public/js` as writable folders (create them if necessary) | ||
* Set `cache` as writable folder | ||
|
||
## Documentation | ||
Please refer to [it.hce.microframework](https://github.com/HCESrl/it.hce.microframework) repository documentation. | ||
|
||
Please refer to [it.hce.microframework](https://github.com/HCESrl/it.hce.microframework) repository documentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace it\hce\microframework\core\factories; | ||
|
||
|
||
use CSSJanus; | ||
use it\hce\microframework\core\exceptions\MicroFrameworkException; | ||
use it\hce\microframework\core\helpers\PathHelper; | ||
use Leafo\ScssPhp\Compiler; | ||
use MatthiasMullie\Minify\CSS; | ||
|
||
class FallbackSassFactory | ||
{ | ||
const mainScssPath = 'css/main.scss'; | ||
const mainRtlScssPath = 'css/main.rtl.scss'; | ||
const scssPath = 'css/'; | ||
|
||
private $compiler; | ||
private $main; | ||
private $mainRtl; | ||
private $minifier; | ||
private $compiledCss; | ||
|
||
/** | ||
* SassFactory constructor. | ||
* @param bool $rtl | ||
* @throws MicroFrameworkException | ||
*/ | ||
public function __construct($rtl = false) | ||
{ | ||
// load the compiler | ||
$this->compiler = new Compiler(); | ||
|
||
//load the minifier | ||
$this->minifier = new CSS(); | ||
|
||
// set rtl | ||
$this->rtl = $rtl; | ||
|
||
if ($this->rtl) { | ||
// load main.rtl.scss | ||
if (!file_exists(PathHelper::getResourcesPath(self::mainRtlScssPath))) { | ||
throw new MicroFrameworkException('main.rtl.scss not found'); | ||
} | ||
|
||
$this->mainRtl = file_get_contents(PathHelper::getResourcesPath(self::mainRtlScssPath)); | ||
} | ||
// load main.scss | ||
if (!file_exists(PathHelper::getResourcesPath(self::mainScssPath))) { | ||
throw new MicroFrameworkException('main.scss not found'); | ||
} | ||
|
||
$this->main = file_get_contents(PathHelper::getResourcesPath(self::mainScssPath)); | ||
} | ||
|
||
/** | ||
* Collects the needed files | ||
*/ | ||
public function collect() | ||
{ | ||
$this->compiler->setImportPaths(PathHelper::getResourcesPath(self::scssPath)); | ||
} | ||
|
||
/** | ||
* Compiles SCSS | ||
* @return string the compiled css | ||
*/ | ||
public function compile() | ||
{ | ||
$compiledSass = $this->compiler->compile($this->main); | ||
|
||
if ($this->rtl) { | ||
$compiledSass = $this->rightToLeft($compiledSass); | ||
$rtlSass = $this->compiler->compile($this->mainRtl); | ||
$compiledSass = $compiledSass . $rtlSass; | ||
} | ||
|
||
// minify the result | ||
return $this->compiledCss = $this->minify($compiledSass); | ||
} | ||
|
||
private function rightToLeft($compiledSass) | ||
{ | ||
return CSSJanus::transform($compiledSass); | ||
} | ||
|
||
private function minify($compiledSass) | ||
{ | ||
$this->minifier->add($compiledSass); | ||
return $this->minifier->minify(); | ||
} | ||
|
||
/** | ||
* Writes the loaded SCSS in a given css file (overwrite) | ||
* @param $file | ||
* @throws MicroFrameworkException | ||
*/ | ||
public function write($file) | ||
{ | ||
if ((!file_exists($file) && is_writable(dirname($file))) || is_writable($file)) { | ||
file_put_contents($file, $this->compiledCss); | ||
} else { | ||
if((!file_exists($file) && !is_writable(dirname($file))) ){ | ||
throw new MicroFrameworkException($file . ' does not exist and directory is not writable'); | ||
} else if(!is_writable($file)){ | ||
throw new MicroFrameworkException($file . ' is not writable'); | ||
} else { | ||
throw new MicroFrameworkException("Unknown error trying to write $file "); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters