/** * Test if trimming indentations with tabs are handled properly. */ public function testLineWithTabsIsTrimmedCorrectly() { $ws = new ezcTemplateWhitespaceRemoval(); $ws->tabSize = 8; for ($i = 0; $i <= 8; ++$i) { self::assertSame("", $ws->trimIndentationLine("", $i), "Empty string trimmed at indentation {$i} should be empty."); } self::assertSame("\t", $ws->trimIndentationLine("\t", 0), "String with tab trimmed at indentation 0 should have the tab marker."); self::assertSame("", $ws->trimIndentationLine("\t", 1), "String with tab trimmed at indentation 1 should be empty."); self::assertSame("", $ws->trimIndentationLine("\t", 7), "String with tab trimmed at indentation 7 should be empty."); self::assertSame("", $ws->trimIndentationLine("\t", 8), "String with tab trimmed at indentation 8 should be empty."); self::assertSame(" \t", $ws->trimIndentationLine(" \t", 0), "String with space+tab trimmed at indentation 0 should have the space+tab marker."); self::assertSame("\t", $ws->trimIndentationLine(" \t", 1), "String with space+tab trimmed at indentation 1 should have the tab marker."); self::assertSame("", $ws->trimIndentationLine(" \t", 2), "String with space+tab trimmed at indentation 2 should be empty."); self::assertSame("", $ws->trimIndentationLine(" \t", 7), "String with space+tab trimmed at indentation 7 should be empty."); self::assertSame("", $ws->trimIndentationLine(" \t", 8), "String with space+tab trimmed at indentation 8 should be empty."); self::assertSame(" \t", $ws->trimIndentationLine(" \t", 0), "String with 7*space+tab trimmed at indentation 0 should have the 7*space+tab marker."); self::assertSame(" \t", $ws->trimIndentationLine(" \t", 1), "String with 7*space+tab trimmed at indentation 1 should have the 6*space+tab marker."); self::assertSame(" \t", $ws->trimIndentationLine(" \t", 2), "String with 7*space+tab trimmed at indentation 2 should have the 5*space+tab marker."); self::assertSame(" \t", $ws->trimIndentationLine(" \t", 3), "String with 7*space+tab trimmed at indentation 3 should have the 4*space+tab marker."); self::assertSame(" \t", $ws->trimIndentationLine(" \t", 4), "String with 7*space+tab trimmed at indentation 4 should have the 3*space+tab marker."); self::assertSame(" \t", $ws->trimIndentationLine(" \t", 5), "String with 7*space+tab trimmed at indentation 5 should have the 2*space+tab marker."); self::assertSame(" \t", $ws->trimIndentationLine(" \t", 6), "String with 7*space+tab trimmed at indentation 6 should have the 1*space+tab marker."); self::assertSame("\t", $ws->trimIndentationLine(" \t", 7), "String with 7*space+tab trimmed at indentation 7 should have the tab marker."); self::assertSame("", $ws->trimIndentationLine(" \t", 8), "String with 7*space+tab trimmed at indentation 8 should be empty."); }
/** * {@inheritdoc} * Trims away ending whitespace for all sub-blocks, the trimming of the * first text block is not done since this is a program element and not a * standard block element. */ public function trimLine(ezcTemplateWhitespaceRemoval $removal) { if (count($this->children) == 0) { return; } // Tell the removal object to trim text blocks after the current block // and after all sub-blocks. $removal->trimBlockLines($this, $this->children); }
public function trimLine(ezcTemplateWhitespaceRemoval $removal) { if (count($this->children) == 0) { return; } foreach ($this->children as $child) { if ($child instanceof ezcTemplateConditionBodyTstNode) { if (count($child->children) == 0) { continue; } // Tell the removal object to trim our first text child if ($child->children[0] instanceof ezcTemplateTextTstNode) { $removal->trimBlockLine($this, $child->children[0]); } // Tell the removal object to trim text blocks after the current block // and after all sub-blocks. $removal->trimBlockLines($this, $child->children); } } }
/** * Creates the TST tree structure from the source code. * * @return void */ public function parseIntoNodeTree() { if (!$this->source->hasCode()) { throw new ezcTemplateException(ezcTemplateSourceToTstErrorMessages::MSG_NO_SOURCE_CODE); } $sourceText = $this->source->code; $cursor = new ezcTemplateCursor($sourceText); $this->textElements = array(); $parser = new ezcTemplateProgramSourceToTstParser($this, null, null); $parser->setAllCursors($cursor); if (!$parser->parse()) { $currentParser = $parser->getFailingParser(); } // Trim starting/trailing whitespace if ($this->trimWhitespace) { $this->whitespaceRemoval->trimProgram($parser->program); } return $parser->program; }
/** * Trims away the whitespace and EOL marker from the block line. * The whitespace and EOL marker is found in the first child element * which must be a text block element. * * Note: If a sub-class of this block element class uses another variable * than $children for child elements or uses multiple lists then it * needs to re-implement this method and call * $removal->trimBlockLine() for the correct list. * * @param ezcTemplateWhitespaceRemoval $removal * The removal object which knows how to get rid of block line whitespace. */ public function trimLine(ezcTemplateWhitespaceRemoval $removal) { if (count($this->children) == 0) { return; } if ($this->children[0] instanceof ezcTemplateTextTstNode) { // Tell the removal object to trim our first text child $removal->trimBlockLine($this, $this->children[0]); } // Tell the removal object to trim text blocks after the current block // and after all sub-blocks. $removal->trimBlockLines($this, $this->children); }