| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * SCSSPHP |
| 4 | 4 | * |
| 5 | - * @copyright 2012-2018 Leaf Corcoran | |
| 5 | + * @copyright 2012-2015 Leaf Corcoran | |
| 6 | 6 | * |
| 7 | 7 | * @license http://opensource.org/licenses/MIT MIT |
| 8 | 8 | * |
| 9 | 9 | * @link http://leafo.github.io/scssphp |
| @@ -11,12 +11,11 @@ | ||
| 11 | 11 | |
| 12 | 12 | namespace Leafo\ScssPhp; |
| 13 | 13 | |
| 14 | 14 | use Leafo\ScssPhp\Formatter\OutputBlock; |
| 15 | -use Leafo\ScssPhp\SourceMap\SourceMapGenerator; | |
| 16 | 15 | |
| 17 | 16 | /** |
| 18 | - * Base formatter | |
| 17 | + * SCSS base formatter | |
| 19 | 18 | * |
| 20 | 19 | * @author Leaf Corcoran <[email protected]> |
| 21 | 20 | */ |
| 22 | 21 | abstract class Formatter |
| @@ -56,33 +55,8 @@ | ||
| 56 | 55 | */ |
| 57 | 56 | public $assignSeparator; |
| 58 | 57 | |
| 59 | 58 | /** |
| 60 | - * @var boolean | |
| 61 | - */ | |
| 62 | - public $keepSemicolons; | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * @var \Leafo\ScssPhp\Formatter\OutputBlock | |
| 66 | - */ | |
| 67 | - protected $currentBlock; | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * @var integer | |
| 71 | - */ | |
| 72 | - protected $currentLine; | |
| 73 | - | |
| 74 | - /** | |
| 75 | - * @var integer | |
| 76 | - */ | |
| 77 | - protected $currentColumn; | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * @var \Leafo\ScssPhp\SourceMap\SourceMapGenerator | |
| 81 | - */ | |
| 82 | - protected $sourceMapGenerator; | |
| 83 | - | |
| 84 | - /** | |
| 85 | 59 | * Initialize formatter |
| 86 | 60 | * |
| 87 | 61 | * @api |
| 88 | 62 | */ |
| @@ -121,17 +95,8 @@ | ||
| 121 | 95 | * @param array $lines |
| 122 | 96 | */ |
| 123 | 97 | public function stripSemicolon(&$lines) |
| 124 | 98 | { |
| 125 | - if ($this->keepSemicolons) { | |
| 126 | - return; | |
| 127 | - } | |
| 128 | - | |
| 129 | - if (($count = count($lines)) | |
| 130 | - && substr($lines[$count - 1], -1) === ';' | |
| 131 | - ) { | |
| 132 | - $lines[$count - 1] = substr($lines[$count - 1], 0, -1); | |
| 133 | - } | |
| 134 | 99 | } |
| 135 | 100 | |
| 136 | 101 | /** |
| 137 | 102 | * Output lines inside a block |
| @@ -143,12 +108,12 @@ | ||
| 143 | 108 | $inner = $this->indentStr(); |
| 144 | 109 | |
| 145 | 110 | $glue = $this->break . $inner; |
| 146 | 111 | |
| 147 | - $this->write($inner . implode($glue, $block->lines)); | |
| 112 | + echo $inner . implode($glue, $block->lines); | |
| 148 | 113 | |
| 149 | 114 | if (! empty($block->children)) { |
| 150 | - $this->write($this->break); | |
| 115 | + echo $this->break; | |
| 151 | 116 | } |
| 152 | 117 | } |
| 153 | 118 | |
| 154 | 119 | /** |
| @@ -159,11 +124,11 @@ | ||
| 159 | 124 | protected function blockSelectors(OutputBlock $block) |
| 160 | 125 | { |
| 161 | 126 | $inner = $this->indentStr(); |
| 162 | 127 | |
| 163 | - $this->write($inner | |
| 128 | + echo $inner | |
| 164 | 129 | . implode($this->tagSeparator, $block->selectors) |
| 165 | - . $this->open . $this->break); | |
| 130 | + . $this->open . $this->break; | |
| 166 | 131 | } |
| 167 | 132 | |
| 168 | 133 | /** |
| 169 | 134 | * Output block children |
| @@ -187,10 +152,8 @@ | ||
| 187 | 152 | if (empty($block->lines) && empty($block->children)) { |
| 188 | 153 | return; |
| 189 | 154 | } |
| 190 | 155 | |
| 191 | - $this->currentBlock = $block; | |
| 192 | - | |
| 193 | 156 | $pre = $this->indentStr(); |
| 194 | 157 | |
| 195 | 158 | if (! empty($block->selectors)) { |
| 196 | 159 | $this->blockSelectors($block); |
| @@ -209,12 +172,12 @@ | ||
| 209 | 172 | if (! empty($block->selectors)) { |
| 210 | 173 | $this->indentLevel--; |
| 211 | 174 | |
| 212 | 175 | if (empty($block->children)) { |
| 213 | - $this->write($this->break); | |
| 176 | + echo $this->break; | |
| 214 | 177 | } |
| 215 | 178 | |
| 216 | - $this->write($pre . $this->close . $this->break); | |
| 179 | + echo $pre . $this->close . $this->break; | |
| 217 | 180 | } |
| 218 | 181 | } |
| 219 | 182 | |
| 220 | 183 | /** |
| @@ -221,23 +184,14 @@ | ||
| 221 | 184 | * Entry point to formatting a block |
| 222 | 185 | * |
| 223 | 186 | * @api |
| 224 | 187 | * |
| 225 | - * @param \Leafo\ScssPhp\Formatter\OutputBlock $block An abstract syntax tree | |
| 226 | - * @param \Leafo\ScssPhp\SourceMap\SourceMapGenerator|null $sourceMapGenerator Optional source map generator | |
| 188 | + * @param \Leafo\ScssPhp\Formatter\OutputBlock $block An abstract syntax tree | |
| 227 | 189 | * |
| 228 | 190 | * @return string |
| 229 | 191 | */ |
| 230 | - public function format(OutputBlock $block, SourceMapGenerator $sourceMapGenerator = null) | |
| 192 | + public function format(OutputBlock $block) | |
| 231 | 193 | { |
| 232 | - $this->sourceMapGenerator = null; | |
| 233 | - | |
| 234 | - if ($sourceMapGenerator) { | |
| 235 | - $this->currentLine = 1; | |
| 236 | - $this->currentColumn = 0; | |
| 237 | - $this->sourceMapGenerator = $sourceMapGenerator; | |
| 238 | - } | |
| 239 | - | |
| 240 | 194 | ob_start(); |
| 241 | 195 | |
| 242 | 196 | $this->block($block); |
| 243 | 197 | |
| @@ -243,32 +197,6 @@ | ||
| 243 | 197 | |
| 244 | 198 | $out = ob_get_clean(); |
| 245 | 199 | |
| 246 | 200 | return $out; |
| 247 | - } | |
| 248 | - | |
| 249 | - /** | |
| 250 | - * @param string $str | |
| 251 | - */ | |
| 252 | - protected function write($str) | |
| 253 | - { | |
| 254 | - if ($this->sourceMapGenerator) { | |
| 255 | - $this->sourceMapGenerator->addMapping( | |
| 256 | - $this->currentLine, | |
| 257 | - $this->currentColumn, | |
| 258 | - $this->currentBlock->sourceLine, | |
| 259 | - $this->currentBlock->sourceColumn - 1, //columns from parser are off by one | |
| 260 | - $this->currentBlock->sourceName | |
| 261 | - ); | |
| 262 | - | |
| 263 | - $lines = explode("\n", $str); | |
| 264 | - $lineCount = count($lines); | |
| 265 | - $this->currentLine += $lineCount-1; | |
| 266 | - | |
| 267 | - $lastLine = array_pop($lines); | |
| 268 | - | |
| 269 | - $this->currentColumn = ($lineCount === 1 ? $this->currentColumn : 0) + strlen($lastLine); | |
| 270 | - } | |
| 271 | - | |
| 272 | - echo $str; | |
| 273 | 201 | } |
| 274 | 202 | } |