@@ -81,13 +81,16 @@ discard block |
||
81 | 81 | */ |
82 | 82 | function __construct($baseModel, $setup = NULL) { |
83 | 83 | self::$me = $this; |
84 | - if(!$setup) |
|
85 | - $setup = new Setup(); |
|
84 | + if(!$setup) { |
|
85 | + $setup = new Setup(); |
|
86 | + } |
|
86 | 87 | $this->parse = new Parse(); |
87 | - if(!$setup instanceOf Setup) |
|
88 | - throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
|
89 | - if(!$baseModel instanceOf Model) |
|
90 | - throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
|
88 | + if(!$setup instanceOf Setup) { |
|
89 | + throw new Exception\Unsupported("Unsupported Setup Helper was passed, it must extends hamleSetup"); |
|
90 | + } |
|
91 | + if(!$baseModel instanceOf Model) { |
|
92 | + throw new Exception\Unsupported("Unsupported Model(".get_class($baseModel).") Type was passed, it must implement hamleModel"); |
|
93 | + } |
|
91 | 94 | $this->setup = $setup; |
92 | 95 | $this->baseModel = $baseModel; |
93 | 96 | $this->initSnipFiles(); |
@@ -97,7 +100,9 @@ discard block |
||
97 | 100 | if($this->snipMod == 0) { |
98 | 101 | $this->snipFiles = $this->setup->snippetFiles(); |
99 | 102 | foreach($this->snipFiles as $f) { |
100 | - if (!file_exists($f)) throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
|
103 | + if (!file_exists($f)) { |
|
104 | + throw new Exception\NotFound("Unable to find Snippet File ($f)"); |
|
105 | + } |
|
101 | 106 | $this->snipFiles = max($this->snipFiles, filemtime($f)); |
102 | 107 | } |
103 | 108 | } |
@@ -111,8 +116,9 @@ discard block |
||
111 | 116 | */ |
112 | 117 | function load($hamleFile, \Closure $parseFunc = null) { |
113 | 118 | $template = $this->setup->templatePath($hamleFile); |
114 | - if(!file_exists($template)) |
|
115 | - throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
|
119 | + if(!file_exists($template)) { |
|
120 | + throw new Exception\NotFound("Unable to find HAMLE Template ($template)"); |
|
121 | + } |
|
116 | 122 | $this->cacheFile = $this->setup->cachePath( |
117 | 123 | str_replace("/","-",$hamleFile).".php"); |
118 | 124 | $this->setup->debugLog("Set cache file path to ({$this->cacheFile})"); |
@@ -122,8 +128,9 @@ discard block |
||
122 | 128 | if($cacheDirty) { |
123 | 129 | $this->setup->debugLog("Parsing File ($template to {$this->cacheFile})"); |
124 | 130 | $this->parse($parseFunc?"":file_get_contents($template), $parseFunc); |
125 | - } else |
|
126 | - $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
|
131 | + } else { |
|
132 | + $this->setup->debugLog("Using Cached file ({$this->cacheFile})"); |
|
133 | + } |
|
127 | 134 | return $this; |
128 | 135 | } |
129 | 136 | /** |
@@ -135,24 +142,29 @@ discard block |
||
135 | 142 | * @throws Exception\ParseError if unable to write to the cache file |
136 | 143 | */ |
137 | 144 | function parse($hamleCode, \Closure $parseFunc = null) { |
138 | - if(!$this->cacheFile) |
|
139 | - $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
|
140 | - if($parseFunc) |
|
141 | - $parseFunc($this->parse); |
|
142 | - else |
|
143 | - $this->parse->str($hamleCode); |
|
145 | + if(!$this->cacheFile) { |
|
146 | + $this->cacheFile = $this->setup->cachePath("string.hamle.php"); |
|
147 | + } |
|
148 | + if($parseFunc) { |
|
149 | + $parseFunc($this->parse); |
|
150 | + } else { |
|
151 | + $this->parse->str($hamleCode); |
|
152 | + } |
|
144 | 153 | $this->setup->debugLog("Loading Snippet Files"); |
145 | - foreach($this->snipFiles as $snip) |
|
146 | - $this->parse->parseSnip(file_get_contents($snip)); |
|
154 | + foreach($this->snipFiles as $snip) { |
|
155 | + $this->parse->parseSnip(file_get_contents($snip)); |
|
156 | + } |
|
147 | 157 | $this->setup->debugLog("Applying Snippet Files"); |
148 | 158 | $this->parse->applySnip(); |
149 | 159 | $this->setup->debugLog("Executing Parse Filters"); |
150 | - foreach($this->setup->getFilters() as $filter) |
|
151 | - $this->parse->parseFilter($filter); |
|
160 | + foreach($this->setup->getFilters() as $filter) { |
|
161 | + $this->parse->parseFilter($filter); |
|
162 | + } |
|
152 | 163 | $this->setup->debugLog("Updating Cache File ({$this->cacheFile})"); |
153 | - if(FALSE === file_put_contents($this->cacheFile, $this->parse->output($this->setup->getMinify()))) |
|
154 | - throw new Exception\ParseError( |
|
164 | + if(FALSE === file_put_contents($this->cacheFile, $this->parse->output($this->setup->getMinify()))) { |
|
165 | + throw new Exception\ParseError( |
|
155 | 166 | "Unable to write to cache file ({$this->cacheFile})"); |
167 | + } |
|
156 | 168 | } |
157 | 169 | |
158 | 170 | /** |
@@ -163,8 +175,9 @@ discard block |
||
163 | 175 | $md5 = md5($hamleString); |
164 | 176 | $stringId = substr($md5,0,12).substr($md5,24,8); |
165 | 177 | $this->cacheFile = $this->setup->cachePath("string.$stringId.hamle.php"); |
166 | - if(!is_file($this->cacheFile)) |
|
167 | - $this->parse($hamleString); |
|
178 | + if(!is_file($this->cacheFile)) { |
|
179 | + $this->parse($hamleString); |
|
180 | + } |
|
168 | 181 | } |
169 | 182 | |
170 | 183 | function getCacheFileName() { |
@@ -183,9 +196,13 @@ discard block |
||
183 | 196 | $baseModel = $this->baseModel; |
184 | 197 | $this->baseModel = null; |
185 | 198 | $currentModel = $baseModel == Scope::getTopScope(); |
186 | - if(!$currentModel && $baseModel) Scope::add($baseModel); |
|
199 | + if(!$currentModel && $baseModel) { |
|
200 | + Scope::add($baseModel); |
|
201 | + } |
|
187 | 202 | require $this->cacheFile; |
188 | - if(!$currentModel && $baseModel) Scope::done(); |
|
203 | + if(!$currentModel && $baseModel) { |
|
204 | + Scope::done(); |
|
205 | + } |
|
189 | 206 | $this->baseModel = $baseModel; |
190 | 207 | $out = ob_get_contents(); |
191 | 208 | ob_end_clean(); |
@@ -202,8 +219,9 @@ discard block |
||
202 | 219 | * @return int The line number being passed by the parser |
203 | 220 | */ |
204 | 221 | static function getLineNo() { |
205 | - if(!isset(self::$me)) |
|
206 | - return 0; |
|
222 | + if(!isset(self::$me)) { |
|
223 | + return 0; |
|
224 | + } |
|
207 | 225 | return self::$me->parse->getLineNo(); |
208 | 226 | } |
209 | 227 |
@@ -73,14 +73,16 @@ discard block |
||
73 | 73 | $scopeName = $m[1]; |
74 | 74 | $lookup = substr($this->var, 0, strlen($this->var) - strlen($m[0])); |
75 | 75 | $hsv = new H\Text(trim($lookup), H\Text::TOKEN_CONTROL); |
76 | - } else |
|
77 | - $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
76 | + } else { |
|
77 | + $hsv = new H\Text($this->var, H\Text::TOKEN_CONTROL); |
|
78 | + } |
|
78 | 79 | switch ($this->type) { |
79 | 80 | case "each": |
80 | - if ($this->var) |
|
81 | - $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
82 | - else |
|
83 | - $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
81 | + if ($this->var) { |
|
82 | + $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
83 | + } else { |
|
84 | + $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
|
85 | + } |
|
84 | 86 | $out .= "Hamle\\Scope::add({$this->o}); "; |
85 | 87 | break; |
86 | 88 | case "if": |
@@ -88,9 +90,9 @@ discard block |
||
88 | 90 | $out .= "if(" . $hsvcomp->toPHP() . ") {"; |
89 | 91 | break; |
90 | 92 | case "with": |
91 | - if ($scopeName) |
|
92 | - $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
93 | - else { |
|
93 | + if ($scopeName) { |
|
94 | + $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
95 | + } else { |
|
94 | 96 | $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . |
95 | 97 | "{$this->o}->valid()) {\n"; |
96 | 98 | $out .= "Hamle\\Scope::add({$this->o});\n;"; |
@@ -101,10 +103,11 @@ discard block |
||
101 | 103 | break; |
102 | 104 | case "include": |
103 | 105 | $file = $hsv->toHTML(); |
104 | - if($file[0] == "#") |
|
105 | - $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
106 | - else |
|
107 | - $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
106 | + if($file[0] == "#") { |
|
107 | + $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
|
108 | + } else { |
|
109 | + $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
110 | + } |
|
108 | 111 | break; |
109 | 112 | } |
110 | 113 | return $out . "\n?>"; |
@@ -123,8 +126,9 @@ discard block |
||
123 | 126 | case "each"; |
124 | 127 | $out .= 'Hamle\\Scope::done(); '; |
125 | 128 | $out .= '}'; |
126 | - if (!$this->var) |
|
127 | - $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
129 | + if (!$this->var) { |
|
130 | + $out .= "Hamle\\Scope::get()->rewind();\n"; |
|
131 | + } |
|
128 | 132 | break; |
129 | 133 | case "if": |
130 | 134 | case "else": |
@@ -140,7 +144,9 @@ discard block |
||
140 | 144 | return ""; |
141 | 145 | break; |
142 | 146 | } |
143 | - if ($this->else) $out .= "else{"; |
|
147 | + if ($this->else) { |
|
148 | + $out .= "else{"; |
|
149 | + } |
|
144 | 150 | return $out . "\n?>"; |
145 | 151 | } |
146 | 152 | |
@@ -148,9 +154,12 @@ discard block |
||
148 | 154 | $ind = $minify ? '' : str_pad('', $indent); |
149 | 155 | $oneliner = (!(count($this->content) > 1 || $this->tags)); |
150 | 156 | $out = $this->renderStTag(); |
151 | - if ($this->content) $out .= $this->renderContent($ind, $oneliner || $minify); |
|
152 | - foreach ($this->tags as $tag) |
|
153 | - $out .= $tag->render($indent, $minify); |
|
157 | + if ($this->content) { |
|
158 | + $out .= $this->renderContent($ind, $oneliner || $minify); |
|
159 | + } |
|
160 | + foreach ($this->tags as $tag) { |
|
161 | + $out .= $tag->render($indent, $minify); |
|
162 | + } |
|
154 | 163 | $out .= $this->renderEnTag(); |
155 | 164 | return $out; |
156 | 165 | } |
@@ -109,22 +109,25 @@ discard block |
||
109 | 109 | $revSnip = array(); |
110 | 110 | /** @var Tag[] $roots */ |
111 | 111 | $roots = array(); |
112 | - foreach ($this->root as $snip) |
|
113 | - if ($snip instanceOf Tag\Snippet) { |
|
112 | + foreach ($this->root as $snip) { |
|
113 | + if ($snip instanceOf Tag\Snippet) { |
|
114 | 114 | if ($snip->getType() == "append") { |
115 | - array_unshift($revSnip, $snip); |
|
115 | + array_unshift($revSnip, $snip); |
|
116 | + } |
|
116 | 117 | } else { |
117 | 118 | $fwdSnip[] = $snip; |
118 | 119 | } |
119 | 120 | } else { |
120 | 121 | $roots[] = $snip; |
121 | 122 | } |
122 | - foreach ($fwdSnip as $snip) |
|
123 | - foreach ($roots as $root) |
|
124 | - $snip->apply($root); |
|
125 | - foreach ($revSnip as $snip) |
|
126 | - foreach ($roots as $root) |
|
127 | - $snip->apply($root); |
|
123 | + foreach ($fwdSnip as $snip) { |
|
124 | + foreach ($roots as $root) |
|
125 | + $snip->apply($root); |
|
126 | + } |
|
127 | + foreach ($revSnip as $snip) { |
|
128 | + foreach ($roots as $root) |
|
129 | + $snip->apply($root); |
|
130 | + } |
|
128 | 131 | $this->root = $roots; |
129 | 132 | } |
130 | 133 | |
@@ -144,9 +147,11 @@ discard block |
||
144 | 147 | $heir = array(); |
145 | 148 | while ($this->lineNo < $this->lineCount) { |
146 | 149 | $line = $this->lines[$this->lineNo]; |
147 | - if (trim($line)) if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
150 | + if (trim($line)) { |
|
151 | + if (preg_match(self::REGEX_PARSE_LINE, $line, $m)) { |
|
148 | 152 | if (FALSE !== strpos($m[1], "\t")) |
149 | - throw new ParseError("Tabs are not supported in templates at this time"); |
|
153 | + throw new ParseError("Tabs are not supported in templates at this time"); |
|
154 | + } |
|
150 | 155 | $indent = strlen($m[1]); |
151 | 156 | $tag = isset($m[2]) ? $tag = $m[2] : ""; |
152 | 157 | $classid = isset($m[3]) ? $m[3] : ""; |
@@ -158,13 +163,13 @@ discard block |
||
158 | 163 | unset($m[0]); |
159 | 164 | switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) { |
160 | 165 | case "|": //Control Tag |
161 | - if ($code == "|snippet") |
|
162 | - $hTag = new Tag\Snippet($text); |
|
163 | - elseif ($code == "|form") |
|
164 | - $hTag = new Tag\Form($text); |
|
165 | - elseif ($code == "|formhint") |
|
166 | - $hTag = new Tag\FormHint($text); |
|
167 | - elseif ($code == "|else") { |
|
166 | + if ($code == "|snippet") { |
|
167 | + $hTag = new Tag\Snippet($text); |
|
168 | + } elseif ($code == "|form") { |
|
169 | + $hTag = new Tag\Form($text); |
|
170 | + } elseif ($code == "|formhint") { |
|
171 | + $hTag = new Tag\FormHint($text); |
|
172 | + } elseif ($code == "|else") { |
|
168 | 173 | $hTag = new Tag\Control(substr($code, 1), $heir[$i - 1]); |
169 | 174 | $hTag->setVar($text); |
170 | 175 | } else { |
@@ -175,8 +180,9 @@ discard block |
||
175 | 180 | case ":": //Filter Tag |
176 | 181 | $hTag = new Tag\Filter(substr($code, 1)); |
177 | 182 | $hTag->addContent($text, Text::TOKEN_CODE); |
178 | - foreach ($this->consumeBlock($indent) as $l) |
|
179 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
183 | + foreach ($this->consumeBlock($indent) as $l) { |
|
184 | + $hTag->addContent($l, Text::TOKEN_CODE); |
|
185 | + } |
|
180 | 186 | break; |
181 | 187 | case "_": //String Tag |
182 | 188 | case "__": //Unescape String Tag |
@@ -187,8 +193,9 @@ discard block |
||
187 | 193 | case "//": // Non Printed Comment |
188 | 194 | $hTag = new Tag\Comment($textcode); |
189 | 195 | $hTag->addContent($text); |
190 | - foreach ($this->consumeBlock($indent) as $l) |
|
191 | - $hTag->addContent($l, Text::TOKEN_CODE); |
|
196 | + foreach ($this->consumeBlock($indent) as $l) { |
|
197 | + $hTag->addContent($l, Text::TOKEN_CODE); |
|
198 | + } |
|
192 | 199 | break; |
193 | 200 | default: |
194 | 201 | $attr = array(); |
@@ -201,25 +208,34 @@ discard block |
||
201 | 208 | } |
202 | 209 | $class = array(); $id = ""; $ref = ""; |
203 | 210 | preg_match_all('/[#\.!][a-zA-Z0-9\-\_]+/m', $classid, $cid); |
204 | - if (isset($cid[0])) foreach ($cid[0] as $s) { |
|
205 | - if ($s[0] == "#") $id = substr($s, 1); |
|
206 | - if ($s[0] == ".") $class[] = substr($s, 1); |
|
207 | - if ($s[0] == "!") $ref = substr($s, 1); |
|
211 | + if (isset($cid[0])) { |
|
212 | + foreach ($cid[0] as $s) { |
|
213 | + if ($s[0] == "#") $id = substr($s, 1); |
|
214 | + } |
|
215 | + if ($s[0] == ".") { |
|
216 | + $class[] = substr($s, 1); |
|
217 | + } |
|
218 | + if ($s[0] == "!") { |
|
219 | + $ref = substr($s, 1); |
|
220 | + } |
|
208 | 221 | } |
209 | - if($ref) |
|
210 | - $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
211 | - else |
|
212 | - $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
222 | + if($ref) { |
|
223 | + $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
|
224 | + } else { |
|
225 | + $hTag = new Tag\Html($tag, $class, $attr, $id); |
|
226 | + } |
|
213 | 227 | $hTag->addContent($text); |
214 | 228 | break; |
215 | 229 | } |
216 | 230 | $heir[$i] = $hTag; |
217 | - if ($i > 0) |
|
218 | - $heir[$i - 1]->addChild($hTag); |
|
219 | - else |
|
220 | - $this->root[] = $hTag; |
|
221 | - } else |
|
222 | - throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
231 | + if ($i > 0) { |
|
232 | + $heir[$i - 1]->addChild($hTag); |
|
233 | + } else { |
|
234 | + $this->root[] = $hTag; |
|
235 | + } |
|
236 | + } else { |
|
237 | + throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
238 | + } |
|
223 | 239 | $this->lineNo++; |
224 | 240 | } |
225 | 241 | } |
@@ -235,8 +251,9 @@ discard block |
||
235 | 251 | |
236 | 252 | function output($minify = false) { |
237 | 253 | $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
238 | - foreach ($this->root as $tag) |
|
239 | - $out .= $tag->render(0, $minify); |
|
254 | + foreach ($this->root as $tag) { |
|
255 | + $out .= $tag->render(0, $minify); |
|
256 | + } |
|
240 | 257 | return $out; |
241 | 258 | |
242 | 259 | } |
@@ -248,15 +265,18 @@ discard block |
||
248 | 265 | (!trim($this->lines[$this->lineNo + 1]) || |
249 | 266 | preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
250 | 267 | $this->lines[$this->lineNo + 1], $m))) { |
251 | - if (trim($this->lines[$this->lineNo + 1])) |
|
252 | - $out[] = $m[2]; |
|
268 | + if (trim($this->lines[$this->lineNo + 1])) { |
|
269 | + $out[] = $m[2]; |
|
270 | + } |
|
253 | 271 | $this->lineNo++; |
254 | 272 | } |
255 | 273 | return $out; |
256 | 274 | } |
257 | 275 | |
258 | 276 | function indentLevel($indent) { |
259 | - if (!isset($this->indents)) $this->indents = array(); |
|
277 | + if (!isset($this->indents)) { |
|
278 | + $this->indents = array(); |
|
279 | + } |
|
260 | 280 | if (!count($this->indents)) { |
261 | 281 | $this->indents = array(0 => $indent); |
262 | 282 | // Key = indent level, Value = Depth in spaces |
@@ -76,9 +76,10 @@ discard block |
||
76 | 76 | } |
77 | 77 | array_shift($path); |
78 | 78 | } |
79 | - foreach ($this->tags as $tag) |
|
80 | - if ($found = $tag->find($path)) |
|
81 | - $list = array_merge($list, $found); |
|
79 | + foreach ($this->tags as $tag) { |
|
80 | + if ($found = $tag->find($path)) |
|
81 | + $list = array_merge($list, $found); |
|
82 | + } |
|
82 | 83 | return $list; |
83 | 84 | } |
84 | 85 | |
@@ -90,7 +91,9 @@ discard block |
||
90 | 91 | */ |
91 | 92 | function replace($path, Tag $newTag) { |
92 | 93 | if ($this->compare($path[0])) { |
93 | - if (count($path) == 1) return $newTag; |
|
94 | + if (count($path) == 1) { |
|
95 | + return $newTag; |
|
96 | + } |
|
94 | 97 | array_shift($path); |
95 | 98 | } |
96 | 99 | foreach ($this->tags as $k => $tag) { |
@@ -103,21 +106,25 @@ discard block |
||
103 | 106 | } |
104 | 107 | |
105 | 108 | function addSnipContent($contentTag, &$tagArray = array(), $key = 0) { |
106 | - foreach ($this->tags as $k => $tag) |
|
107 | - $tag->addSnipContent($contentTag, $this->tags, $k); |
|
109 | + foreach ($this->tags as $k => $tag) { |
|
110 | + $tag->addSnipContent($contentTag, $this->tags, $k); |
|
111 | + } |
|
108 | 112 | } |
109 | 113 | |
110 | 114 | function compare($tic) { |
111 | - if (isset($tic['type']) && $this->type != $tic['type']) |
|
112 | - return false; |
|
115 | + if (isset($tic['type']) && $this->type != $tic['type']) { |
|
116 | + return false; |
|
117 | + } |
|
113 | 118 | if (isset($tic['id']) && |
114 | 119 | !(isset($this->opt['id']) && $tic['id'] == $this->opt['id']) |
115 | - ) |
|
116 | - return false; |
|
120 | + ) { |
|
121 | + return false; |
|
122 | + } |
|
117 | 123 | if (isset($tic['class']) && !(isset($this->opt['class']) |
118 | 124 | && !array_diff($tic['class'], $this->opt['class'])) |
119 | - ) |
|
120 | - return false; |
|
125 | + ) { |
|
126 | + return false; |
|
127 | + } |
|
121 | 128 | return true; |
122 | 129 | } |
123 | 130 | |
@@ -127,10 +134,11 @@ discard block |
||
127 | 134 | * @param string $mode Mode to add child [append|prepend] |
128 | 135 | */ |
129 | 136 | function addChild(Tag $tag, $mode = "append") { |
130 | - if ($mode == "prepend") |
|
131 | - array_unshift($this->tags, $tag); |
|
132 | - else |
|
133 | - $this->tags[] = $tag; |
|
137 | + if ($mode == "prepend") { |
|
138 | + array_unshift($this->tags, $tag); |
|
139 | + } else { |
|
140 | + $this->tags[] = $tag; |
|
141 | + } |
|
134 | 142 | } |
135 | 143 | |
136 | 144 | /** |
@@ -144,9 +152,12 @@ discard block |
||
144 | 152 | $ind = $minify ? '' : str_pad('', $indent); |
145 | 153 | $oneliner = (!(count($this->content) > 1 || $this->tags)); |
146 | 154 | $out = $ind . $this->renderStTag() . ($oneliner || $minify ? '' : "\n"); |
147 | - if ($this->content) $out .= $this->renderContent($ind, $oneliner || $minify); |
|
148 | - foreach ($this->tags as $tag) |
|
149 | - $out .= $tag->render($indent + self::INDENT_SIZE, $minify); |
|
155 | + if ($this->content) { |
|
156 | + $out .= $this->renderContent($ind, $oneliner || $minify); |
|
157 | + } |
|
158 | + foreach ($this->tags as $tag) { |
|
159 | + $out .= $tag->render($indent + self::INDENT_SIZE, $minify); |
|
160 | + } |
|
150 | 161 | $out .= ($minify || $oneliner ? '' : $ind) . $this->renderEnTag() . ($minify ? '' : "\n"); |
151 | 162 | return $out; |
152 | 163 | } |
@@ -160,8 +171,9 @@ discard block |
||
160 | 171 | */ |
161 | 172 | function renderContent($pad = "", $oneliner = false) { |
162 | 173 | $out = ""; |
163 | - foreach ($this->content as $c) |
|
164 | - $out .= ($oneliner ? '' : $pad) . $c . ($oneliner ? '' : "\n"); |
|
174 | + foreach ($this->content as $c) { |
|
175 | + $out .= ($oneliner ? '' : $pad) . $c . ($oneliner ? '' : "\n"); |
|
176 | + } |
|
165 | 177 | return $out; |
166 | 178 | } |
167 | 179 |