CSSList
8 months ago
Comment
3 years ago
Parsing
2 years ago
Property
2 years ago
Rule
2 years ago
RuleSet
8 months ago
Value
2 years ago
OutputFormat.php
2 years ago
OutputFormatter.php
2 years ago
Parser.php
8 months ago
Renderable.php
4 years ago
Settings.php
4 years ago
index.php
3 years ago
OutputFormat.php
131 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Sabberworm\CSS; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class OutputFormat |
| 5 | { |
| 6 | public $sStringQuotingType = '"'; |
| 7 | public $bRGBHashNotation = \true; |
| 8 | public $bSemicolonAfterLastRule = \true; |
| 9 | public $sSpaceAfterRuleName = ' '; |
| 10 | public $sSpaceBeforeRules = ''; |
| 11 | public $sSpaceAfterRules = ''; |
| 12 | public $sSpaceBetweenRules = ''; |
| 13 | public $sSpaceBeforeBlocks = ''; |
| 14 | public $sSpaceAfterBlocks = ''; |
| 15 | public $sSpaceBetweenBlocks = "\n"; |
| 16 | public $sBeforeAtRuleBlock = ''; |
| 17 | public $sAfterAtRuleBlock = ''; |
| 18 | public $sSpaceBeforeSelectorSeparator = ''; |
| 19 | public $sSpaceAfterSelectorSeparator = ' '; |
| 20 | public $sSpaceBeforeListArgumentSeparator = ''; |
| 21 | public $sSpaceAfterListArgumentSeparator = ''; |
| 22 | public $sSpaceBeforeOpeningBrace = ' '; |
| 23 | public $sBeforeDeclarationBlock = ''; |
| 24 | public $sAfterDeclarationBlockSelectors = ''; |
| 25 | public $sAfterDeclarationBlock = ''; |
| 26 | public $sIndentation = "\t"; |
| 27 | public $bIgnoreExceptions = \false; |
| 28 | public $bRenderComments = \false; |
| 29 | private $oFormatter = null; |
| 30 | private $oNextLevelFormat = null; |
| 31 | private $iIndentationLevel = 0; |
| 32 | public function __construct() |
| 33 | { |
| 34 | } |
| 35 | public function get($sName) |
| 36 | { |
| 37 | $aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i']; |
| 38 | foreach ($aVarPrefixes as $sPrefix) { |
| 39 | $sFieldName = $sPrefix . \ucfirst($sName); |
| 40 | if (isset($this->{$sFieldName})) { |
| 41 | return $this->{$sFieldName}; |
| 42 | } |
| 43 | } |
| 44 | return null; |
| 45 | } |
| 46 | public function set($aNames, $mValue) |
| 47 | { |
| 48 | $aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i']; |
| 49 | if (\is_string($aNames) && \strpos($aNames, '*') !== \false) { |
| 50 | $aNames = [\str_replace('*', 'Before', $aNames), \str_replace('*', 'Between', $aNames), \str_replace('*', 'After', $aNames)]; |
| 51 | } elseif (!\is_array($aNames)) { |
| 52 | $aNames = [$aNames]; |
| 53 | } |
| 54 | foreach ($aVarPrefixes as $sPrefix) { |
| 55 | $bDidReplace = \false; |
| 56 | foreach ($aNames as $sName) { |
| 57 | $sFieldName = $sPrefix . \ucfirst($sName); |
| 58 | if (isset($this->{$sFieldName})) { |
| 59 | $this->{$sFieldName} = $mValue; |
| 60 | $bDidReplace = \true; |
| 61 | } |
| 62 | } |
| 63 | if ($bDidReplace) { |
| 64 | return $this; |
| 65 | } |
| 66 | } |
| 67 | // Break the chain so the user knows this option is invalid |
| 68 | return \false; |
| 69 | } |
| 70 | public function __call($sMethodName, array $aArguments) |
| 71 | { |
| 72 | if (\strpos($sMethodName, 'set') === 0) { |
| 73 | return $this->set(\substr($sMethodName, 3), $aArguments[0]); |
| 74 | } elseif (\strpos($sMethodName, 'get') === 0) { |
| 75 | return $this->get(\substr($sMethodName, 3)); |
| 76 | } elseif (\method_exists(OutputFormatter::class, $sMethodName)) { |
| 77 | return \call_user_func_array([$this->getFormatter(), $sMethodName], $aArguments); |
| 78 | } else { |
| 79 | throw new \Exception('Unknown OutputFormat method called: ' . $sMethodName); |
| 80 | } |
| 81 | } |
| 82 | public function indentWithTabs($iNumber = 1) |
| 83 | { |
| 84 | return $this->setIndentation(\str_repeat("\t", $iNumber)); |
| 85 | } |
| 86 | public function indentWithSpaces($iNumber = 2) |
| 87 | { |
| 88 | return $this->setIndentation(\str_repeat(" ", $iNumber)); |
| 89 | } |
| 90 | public function nextLevel() |
| 91 | { |
| 92 | if ($this->oNextLevelFormat === null) { |
| 93 | $this->oNextLevelFormat = clone $this; |
| 94 | $this->oNextLevelFormat->iIndentationLevel++; |
| 95 | $this->oNextLevelFormat->oFormatter = null; |
| 96 | } |
| 97 | return $this->oNextLevelFormat; |
| 98 | } |
| 99 | public function beLenient() |
| 100 | { |
| 101 | $this->bIgnoreExceptions = \true; |
| 102 | } |
| 103 | public function getFormatter() |
| 104 | { |
| 105 | if ($this->oFormatter === null) { |
| 106 | $this->oFormatter = new OutputFormatter($this); |
| 107 | } |
| 108 | return $this->oFormatter; |
| 109 | } |
| 110 | public function level() |
| 111 | { |
| 112 | return $this->iIndentationLevel; |
| 113 | } |
| 114 | public static function create() |
| 115 | { |
| 116 | return new OutputFormat(); |
| 117 | } |
| 118 | public static function createCompact() |
| 119 | { |
| 120 | $format = self::create(); |
| 121 | $format->set('Space*Rules', "")->set('Space*Blocks', "")->setSpaceAfterRuleName('')->setSpaceBeforeOpeningBrace('')->setSpaceAfterSelectorSeparator('')->setRenderComments(\false); |
| 122 | return $format; |
| 123 | } |
| 124 | public static function createPretty() |
| 125 | { |
| 126 | $format = self::create(); |
| 127 | $format->set('Space*Rules', "\n")->set('Space*Blocks', "\n")->setSpaceBetweenBlocks("\n\n")->set('SpaceAfterListArgumentSeparator', ['default' => '', ',' => ' '])->setRenderComments(\true); |
| 128 | return $format; |
| 129 | } |
| 130 | } |
| 131 |