[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Parser output with source map 5 * 6 * @package Less 7 * @subpackage Output 8 */ 9 class Less_Output_Mapped extends Less_Output { 10 11 /** 12 * The source map generator 13 * 14 * @var Less_SourceMap_Generator 15 */ 16 protected $generator; 17 18 /** 19 * Current line 20 * 21 * @var integer 22 */ 23 protected $lineNumber = 0; 24 25 /** 26 * Current column 27 * 28 * @var integer 29 */ 30 protected $column = 0; 31 32 /** 33 * Array of contents map (file and its content) 34 * 35 * @var array 36 */ 37 protected $contentsMap = array(); 38 39 /** 40 * Constructor 41 * 42 * @param array $contentsMap Array of filename to contents map 43 * @param Less_SourceMap_Generator $generator 44 */ 45 public function __construct(array $contentsMap, $generator){ 46 $this->contentsMap = $contentsMap; 47 $this->generator = $generator; 48 } 49 50 /** 51 * Adds a chunk to the stack 52 * The $index for less.php may be different from less.js since less.php does not chunkify inputs 53 * 54 * @param string $chunk 55 * @param string $fileInfo 56 * @param integer $index 57 * @param mixed $mapLines 58 */ 59 public function add($chunk, $fileInfo = null, $index = 0, $mapLines = null){ 60 61 //ignore adding empty strings 62 if( $chunk === '' ){ 63 return; 64 } 65 66 67 $sourceLines = array(); 68 $sourceColumns = ' '; 69 70 71 if( $fileInfo ){ 72 73 $url = $fileInfo['currentUri']; 74 75 if( isset($this->contentsMap[$url]) ){ 76 $inputSource = substr($this->contentsMap[$url], 0, $index); 77 $sourceLines = explode("\n", $inputSource); 78 $sourceColumns = end($sourceLines); 79 }else{ 80 throw new Exception('Filename '.$url.' not in contentsMap'); 81 } 82 83 } 84 85 $lines = explode("\n", $chunk); 86 $columns = end($lines); 87 88 if($fileInfo){ 89 90 if(!$mapLines){ 91 $this->generator->addMapping( 92 $this->lineNumber + 1, // generated_line 93 $this->column, // generated_column 94 count($sourceLines), // original_line 95 strlen($sourceColumns), // original_column 96 $fileInfo 97 ); 98 }else{ 99 for($i = 0, $count = count($lines); $i < $count; $i++){ 100 $this->generator->addMapping( 101 $this->lineNumber + $i + 1, // generated_line 102 $i === 0 ? $this->column : 0, // generated_column 103 count($sourceLines) + $i, // original_line 104 $i === 0 ? strlen($sourceColumns) : 0, // original_column 105 $fileInfo 106 ); 107 } 108 } 109 } 110 111 if(count($lines) === 1){ 112 $this->column += strlen($columns); 113 }else{ 114 $this->lineNumber += count($lines) - 1; 115 $this->column = strlen($columns); 116 } 117 118 // add only chunk 119 parent::add($chunk); 120 } 121 122 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |