Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(POC, WIP) Extract Greenwich as an extension. Draft bootstrap.css variant. #17913

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
.use-civicrm-setup
/ext/*
!/ext/sequentialcreditnotes
!/ext/csslib
!/ext/flexmailer
!/ext/eventcart
!/ext/greenwich
/ext/greenwich/extern
!/ext/search
backdrop/
bower_components
Expand Down
44 changes: 44 additions & 0 deletions ext/csslib/Civi/Csslib/Options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\Csslib;

class Options {

/**
* Options list for "csslib_autoprefixer".
*
* @return array
*/
public static function autoprefixers() {
return [
'none' => ts('None'),

// PRO: Built-in, no extra dependencies.
'php-autoprefixer' => ts('PHP Autoprefixer'),

// PRO: Widely used, more actively maintained. Seems to update sourcemap while filtering.
'autoprefixer-cli' => ts('Node Autoprefixer'),
];
}

/**
* Options list for "csslib_srcmap".
*
* @return array
*/
public static function srcmaps() {
return [
'none' => ts('None'),
'inline' => ts('Inline'),
];
}

}
66 changes: 66 additions & 0 deletions ext/csslib/Civi/Csslib/ScssCompiler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
namespace Civi\Csslib;

use Padaliyajay\PHPAutoprefixer\Autoprefixer;
use ScssPhp\ScssPhp\Compiler;
use Symfony\Component\Process\Process;

class ScssCompiler {

public function compile($content, $includeDirs = []) {
$scss = new Compiler();
foreach ($includeDirs as $includeDir) {
$scss->addImportPath($includeDir);
}

switch (\Civi::settings()->get('csslib_srcmap')) {
case 'inline':
$scss->setSourceMap(Compiler::SOURCE_MAP_INLINE);
break;

case 'none':
default:
// Nothing needed.
break;
}

$content = $scss->compile($content);

switch (\Civi::settings()->get('csslib_autoprefixer')) {
case 'php-autoprefixer':
$autoprefixer = new Autoprefixer($content);
$content = $autoprefixer->compile();
break;

case 'autoprefixer-cli':
$p = new Process('autoprefixer-cli');
$p->setInput($content);
$p->setTimeout(120);
$p->run();
if ($p->isSuccessful()) {
$content = $p->getOutput();
}
else {
throw new \CRM_Core_Exception("Failed to invoke the NodeJS autoprefixer via CLI.");
}
break;

case 'none':
default:
// Nothing needed.
break;
}

return $content;
}

}
Loading