@@ -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 . ' ?>'; |
@@ -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 . ' ?>'; |
145 | 151 | } |
146 | 152 |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | */ |
48 | 48 | function __construct($tag, $parentTag = null) { |
49 | 49 | parent::__construct(); |
50 | - $this->o = "\$o" . self::$instCount++; |
|
50 | + $this->o = "\$o".self::$instCount++; |
|
51 | 51 | $this->type = strtolower($tag); |
52 | 52 | $this->var = ""; |
53 | 53 | if ($parentTag && $this->type == "else") { |
54 | - if($parentTag instanceof H\Tag) { |
|
54 | + if ($parentTag instanceof H\Tag) { |
|
55 | 55 | $elseTag = $parentTag->tags[count($parentTag->tags) - 1]; |
56 | - if($elseTag instanceof H\Tag\Control && |
|
56 | + if ($elseTag instanceof H\Tag\Control && |
|
57 | 57 | in_array($elseTag->type, array('with', 'if')) |
58 | 58 | ) { |
59 | 59 | $elseTag->else = true; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | function renderStTag() { |
70 | - $out = "<" . "?php "; |
|
70 | + $out = "<"."?php "; |
|
71 | 71 | $scopeName = ""; |
72 | 72 | if (preg_match('/ as ([a-zA-Z]+)$/', $this->var, $m)) { |
73 | 73 | $scopeName = $m[1]; |
@@ -78,20 +78,20 @@ discard block |
||
78 | 78 | switch ($this->type) { |
79 | 79 | case "each": |
80 | 80 | if ($this->var) |
81 | - $out .= "foreach(" . $hsv->toPHP() . " as {$this->o}) { \n"; |
|
81 | + $out .= "foreach(".$hsv->toPHP()." as {$this->o}) { \n"; |
|
82 | 82 | else |
83 | 83 | $out .= "foreach(Hamle\\Scope::get() as {$this->o}) { \n"; |
84 | 84 | $out .= "Hamle\\Scope::add({$this->o}); "; |
85 | 85 | break; |
86 | 86 | case "if": |
87 | 87 | $hsvcomp = new H\Text\Comparison($this->var); |
88 | - $out .= "if(" . $hsvcomp->toPHP() . ") {"; |
|
88 | + $out .= "if(".$hsvcomp->toPHP().") {"; |
|
89 | 89 | break; |
90 | 90 | case "with": |
91 | 91 | if ($scopeName) |
92 | - $out .= "Hamle\\Scope::add(" . $hsv->toPHP() . ", \"$scopeName\");\n;"; |
|
92 | + $out .= "Hamle\\Scope::add(".$hsv->toPHP().", \"$scopeName\");\n;"; |
|
93 | 93 | else { |
94 | - $out .= "if(({$this->o} = " . $hsv->toPHP() . ") && " . |
|
94 | + $out .= "if(({$this->o} = ".$hsv->toPHP().") && ". |
|
95 | 95 | "{$this->o}->valid()) {\n"; |
96 | 96 | $out .= "Hamle\\Scope::add({$this->o});\n;"; |
97 | 97 | } |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | break; |
102 | 102 | case "include": |
103 | 103 | $file = $hsv->toHTML(); |
104 | - if($file[0] == "#") |
|
104 | + if ($file[0] == "#") |
|
105 | 105 | $out .= "echo Hamle\\Run::includeFragment(".$hsv->toPHP().");"; |
106 | 106 | else |
107 | - $out .= "echo Hamle\\Run::includeFile(" . $hsv->toPHP() . ");"; |
|
107 | + $out .= "echo Hamle\\Run::includeFile(".$hsv->toPHP().");"; |
|
108 | 108 | break; |
109 | 109 | } |
110 | - return $out . ' ?>'; |
|
110 | + return $out.' ?>'; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | function renderEnTag() { |
121 | - $out = '<' . '?php '; |
|
121 | + $out = '<'.'?php '; |
|
122 | 122 | switch ($this->type) { |
123 | 123 | case "each"; |
124 | 124 | $out .= 'Hamle\\Scope::done(); '; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | break; |
142 | 142 | } |
143 | 143 | if ($this->else) $out .= "else{"; |
144 | - return $out . ' ?>'; |
|
144 | + return $out.' ?>'; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | function render($indent = 0, $doIndent = true) { |
@@ -32,7 +32,7 @@ |
||
32 | 32 | |
33 | 33 | function __construct($message = "", $code = 0, $previous = NULL) { |
34 | 34 | ///@todo Include Line number & file name within parse error exceptions |
35 | - $message .= ", on line " . Hamle\Hamle::getLineNo() . " in file ?.hamle"; |
|
35 | + $message .= ", on line ".Hamle\Hamle::getLineNo()." in file ?.hamle"; |
|
36 | 36 | parent::__construct($message, $code, $previous); |
37 | 37 | } |
38 | 38 |
@@ -42,6 +42,6 @@ |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | function isClicked() { |
45 | - return isset($_REQUEST[$this->form . "_" . $this->name]); |
|
45 | + return isset($_REQUEST[$this->form."_".$this->name]); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | \ No newline at end of file |
@@ -39,8 +39,8 @@ |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | static function filterText($s) { |
42 | - return "/*<![CDATA[*/\n" . |
|
42 | + return "/*<![CDATA[*/\n". |
|
43 | 43 | /*preg_replace(HamlParser::MATCH_INTERPOLATION, '<?php echo \1; ?>', $text)*/ |
44 | - $s . "/*]]>*/"; |
|
44 | + $s."/*]]>*/"; |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -35,10 +35,10 @@ |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | function toPHP() { |
38 | - return '$form->getField(' . Text::varToCode($this->var) . ')->getValue()'; |
|
38 | + return '$form->getField('.Text::varToCode($this->var).')->getValue()'; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | function toHTML($escape = false) { |
42 | - return '<?=' . $this->toPHP() . '?>'; |
|
42 | + return '<?='.$this->toPHP().'?>'; |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | \ No newline at end of file |
@@ -38,55 +38,55 @@ |
||
38 | 38 | protected $what; |
39 | 39 | |
40 | 40 | function __construct($s, Text $what) { |
41 | - if(preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
|
41 | + if (preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
|
42 | 42 | $this->filter = $m[1]; |
43 | 43 | $this->vars = isset($m[3]) ? explode(',', $m[3]) : []; |
44 | - foreach($this->vars as $k=>$v) |
|
45 | - $this->vars[$k] = str_replace(",",',',$v); |
|
44 | + foreach ($this->vars as $k=>$v) |
|
45 | + $this->vars[$k] = str_replace(",", ',', $v); |
|
46 | 46 | } else { |
47 | 47 | throw new ParseError("Unable to parse filter expression \"$s\""); |
48 | 48 | } |
49 | - if(!in_array($this->filter, ['itersplit', 'newlinebr', 'round', |
|
50 | - 'strtoupper', 'strtolower', 'ucfirst','replace', 'json'])) { |
|
49 | + if (!in_array($this->filter, ['itersplit', 'newlinebr', 'round', |
|
50 | + 'strtoupper', 'strtolower', 'ucfirst', 'replace', 'json'])) { |
|
51 | 51 | throw new ParseError("Unknown Filter Type \"{$this->filter}\""); |
52 | 52 | } |
53 | - if(in_array($this->filter,['itersplit','newlinebr', 'replace'])) { |
|
53 | + if (in_array($this->filter, ['itersplit', 'newlinebr', 'replace'])) { |
|
54 | 54 | $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}"; |
55 | 55 | } |
56 | 56 | $mapFilter = ['json'=>'json_encode']; |
57 | - if(isset($mapFilter[$this->filter])) |
|
57 | + if (isset($mapFilter[$this->filter])) |
|
58 | 58 | $this->filter = $mapFilter[$this->filter]; |
59 | 59 | $this->what = $what; |
60 | 60 | } |
61 | 61 | |
62 | 62 | function toHTML($escape = false) { |
63 | - if($escape) |
|
64 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
65 | - return "<?=" . $this->toPHP() . "?>"; |
|
63 | + if ($escape) |
|
64 | + return "<?=htmlspecialchars(".$this->toPHP().")?>"; |
|
65 | + return "<?=".$this->toPHP()."?>"; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function toPHP() { |
69 | - $o = [$this->what->toPHPVar()] ; |
|
70 | - foreach($this->vars as $v) |
|
69 | + $o = [$this->what->toPHPVar()]; |
|
70 | + foreach ($this->vars as $v) |
|
71 | 71 | $o[] = $this->varToCode($v); |
72 | - return "{$this->filter}(" . implode(',',$o) . ")"; |
|
72 | + return "{$this->filter}(".implode(',', $o).")"; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | static function itersplit($v, $sep = ",") { |
76 | 76 | $o = []; |
77 | - foreach(explode($sep, $v) as $k=>$i) { |
|
78 | - if($i) |
|
79 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
77 | + foreach (explode($sep, $v) as $k=>$i) { |
|
78 | + if ($i) |
|
79 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k, 'key'=>$k]; |
|
80 | 80 | } |
81 | 81 | return new WrapArray($o); |
82 | 82 | } |
83 | 83 | |
84 | 84 | static function newlinebr($v) { |
85 | - return str_replace("\n","<br />\n",$v); |
|
85 | + return str_replace("\n", "<br />\n", $v); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | static function replace($v, $src, $dst) { |
89 | - return str_replace($src,$dst,$v); |
|
89 | + return str_replace($src, $dst, $v); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | } |
93 | 93 | \ No newline at end of file |
@@ -41,8 +41,9 @@ discard block |
||
41 | 41 | if(preg_match("/^([a-z]+)(\\((.*)\\))?$/", $s, $m)) { |
42 | 42 | $this->filter = $m[1]; |
43 | 43 | $this->vars = isset($m[3]) ? explode(',', $m[3]) : []; |
44 | - foreach($this->vars as $k=>$v) |
|
45 | - $this->vars[$k] = str_replace(",",',',$v); |
|
44 | + foreach($this->vars as $k=>$v) { |
|
45 | + $this->vars[$k] = str_replace(",",',',$v); |
|
46 | + } |
|
46 | 47 | } else { |
47 | 48 | throw new ParseError("Unable to parse filter expression \"$s\""); |
48 | 49 | } |
@@ -54,29 +55,33 @@ discard block |
||
54 | 55 | $this->filter = "Seufert\\Hamle\\Text\\Filter::{$this->filter}"; |
55 | 56 | } |
56 | 57 | $mapFilter = ['json'=>'json_encode']; |
57 | - if(isset($mapFilter[$this->filter])) |
|
58 | - $this->filter = $mapFilter[$this->filter]; |
|
58 | + if(isset($mapFilter[$this->filter])) { |
|
59 | + $this->filter = $mapFilter[$this->filter]; |
|
60 | + } |
|
59 | 61 | $this->what = $what; |
60 | 62 | } |
61 | 63 | |
62 | 64 | function toHTML($escape = false) { |
63 | - if($escape) |
|
64 | - return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
65 | + if($escape) { |
|
66 | + return "<?=htmlspecialchars(" .$this->toPHP() . ")?>"; |
|
67 | + } |
|
65 | 68 | return "<?=" . $this->toPHP() . "?>"; |
66 | 69 | } |
67 | 70 | |
68 | 71 | function toPHP() { |
69 | 72 | $o = [$this->what->toPHPVar()] ; |
70 | - foreach($this->vars as $v) |
|
71 | - $o[] = $this->varToCode($v); |
|
73 | + foreach($this->vars as $v) { |
|
74 | + $o[] = $this->varToCode($v); |
|
75 | + } |
|
72 | 76 | return "{$this->filter}(" . implode(',',$o) . ")"; |
73 | 77 | } |
74 | 78 | |
75 | 79 | static function itersplit($v, $sep = ",") { |
76 | 80 | $o = []; |
77 | 81 | foreach(explode($sep, $v) as $k=>$i) { |
78 | - if($i) |
|
79 | - $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
82 | + if($i) { |
|
83 | + $o[] = ['v'=>trim($i), 'value'=>trim($i), 'k'=>$k,'key'=>$k]; |
|
84 | + } |
|
80 | 85 | } |
81 | 86 | return new WrapArray($o); |
82 | 87 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | self::$namedScopes[$name]->rewind(); |
68 | 68 | return self::$namedScopes[$name]; |
69 | 69 | } else |
70 | - if(self::$returnZeroOnNoScope) |
|
70 | + if (self::$returnZeroOnNoScope) |
|
71 | 71 | return new Model\Zero(); |
72 | 72 | throw new RunTime("Unable to find scope ($name)"); |
73 | 73 | } |
@@ -18,12 +18,14 @@ discard block |
||
18 | 18 | static $namedScopes = array(); |
19 | 19 | |
20 | 20 | static function add($model, $name = null) { |
21 | - if (!$model instanceOf Model) |
|
22 | - throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
23 | - if ($name) |
|
24 | - self::$namedScopes[$name] = $model; |
|
25 | - else |
|
26 | - self::$scopes[] = $model; |
|
21 | + if (!$model instanceOf Model) { |
|
22 | + throw new Unsupported("Unsupported Model (".get_class($model)."), Needs to implement hamleModel Interface"); |
|
23 | + } |
|
24 | + if ($name) { |
|
25 | + self::$namedScopes[$name] = $model; |
|
26 | + } else { |
|
27 | + self::$scopes[] = $model; |
|
28 | + } |
|
27 | 29 | } |
28 | 30 | |
29 | 31 | static function done() { |
@@ -41,15 +43,21 @@ discard block |
||
41 | 43 | */ |
42 | 44 | static function get($id = 0) { |
43 | 45 | if (0 == $id) { |
44 | - if ($scope = end(self::$scopes)) |
|
45 | - return $scope; |
|
46 | + if ($scope = end(self::$scopes)) { |
|
47 | + return $scope; |
|
48 | + } |
|
46 | 49 | throw new OutOfScope("Unable to find Scope ($id)"); |
47 | 50 | } |
48 | 51 | $key = $id - 1; |
49 | - if ($id < 0) $key = count(self::$scopes) + $id - 1; |
|
50 | - if ($id == 0) $key = count(self::$scopes) - 1; |
|
51 | - if (!isset(self::$scopes[$key])) |
|
52 | - throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
52 | + if ($id < 0) { |
|
53 | + $key = count(self::$scopes) + $id - 1; |
|
54 | + } |
|
55 | + if ($id == 0) { |
|
56 | + $key = count(self::$scopes) - 1; |
|
57 | + } |
|
58 | + if (!isset(self::$scopes[$key])) { |
|
59 | + throw new OutOfScope("Unable to find Scope ($id) or $key"); |
|
60 | + } |
|
53 | 61 | return self::$scopes[$key]; |
54 | 62 | } |
55 | 63 | |
@@ -67,8 +75,9 @@ discard block |
||
67 | 75 | self::$namedScopes[$name]->rewind(); |
68 | 76 | return self::$namedScopes[$name]; |
69 | 77 | } else |
70 | - if(self::$returnZeroOnNoScope) |
|
71 | - return new Model\Zero(); |
|
78 | + if(self::$returnZeroOnNoScope) { |
|
79 | + return new Model\Zero(); |
|
80 | + } |
|
72 | 81 | throw new RunTime("Unable to find scope ($name)"); |
73 | 82 | } |
74 | 83 |
@@ -42,6 +42,6 @@ |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | function isClicked() { |
45 | - return isset($_REQUEST[$this->form . "_" . $this->name]); |
|
45 | + return isset($_REQUEST[$this->form."_".$this->name]); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | \ No newline at end of file |
@@ -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() { |
237 | 253 | $out = "<?php\nuse Seufert\\Hamle;\n?>"; |
238 | - foreach ($this->root as $tag) |
|
239 | - $out .= $tag->render(); |
|
254 | + foreach ($this->root as $tag) { |
|
255 | + $out .= $tag->render(); |
|
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 |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $i = self::indentLevel($indent); |
158 | 158 | unset($m[0]); |
159 | 159 | switch (strlen($code) ? $code[0] : ($textcode ? $textcode : "")) { |
160 | - case "|": //Control Tag |
|
160 | + case "|" : //Control Tag |
|
161 | 161 | if ($code == "|snippet") |
162 | 162 | $hTag = new Tag\Snippet($text); |
163 | 163 | elseif ($code == "|form") |
@@ -192,10 +192,10 @@ discard block |
||
192 | 192 | break; |
193 | 193 | default: |
194 | 194 | $attr = array(); |
195 | - if(isset($params[0]) && $params[0] == "[") { |
|
195 | + if (isset($params[0]) && $params[0] == "[") { |
|
196 | 196 | $param = substr($params, 1, strlen($params) - 2); |
197 | - $param = str_replace('+','%2B', $param); |
|
198 | - $param = str_replace('\\&','%26', $param); |
|
197 | + $param = str_replace('+', '%2B', $param); |
|
198 | + $param = str_replace('\\&', '%26', $param); |
|
199 | 199 | // parse_str($param, $attr); |
200 | 200 | $attr = $this->parseQueryString($param); |
201 | 201 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | if ($s[0] == ".") $class[] = substr($s, 1); |
207 | 207 | if ($s[0] == "!") $ref = substr($s, 1); |
208 | 208 | } |
209 | - if($ref) |
|
209 | + if ($ref) |
|
210 | 210 | $hTag = new Tag\DynHtml($tag, $class, $attr, $id, $ref); |
211 | 211 | else |
212 | 212 | $hTag = new Tag\Html($tag, $class, $attr, $id); |
@@ -219,16 +219,16 @@ discard block |
||
219 | 219 | else |
220 | 220 | $this->root[] = $hTag; |
221 | 221 | } else |
222 | - throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/" . preg_last_error()); |
|
222 | + throw new ParseError("Unable to parse line {$this->lineNo}\n\"$line\"/".preg_last_error()); |
|
223 | 223 | $this->lineNo++; |
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
227 | 227 | function parseQueryString($qs) { |
228 | 228 | $out = []; |
229 | - foreach(explode('&',$qs) as $s) { |
|
230 | - $kv = explode('=',$s,2); |
|
231 | - $out[urldecode($kv[0])] = isset($kv[1])?urldecode($kv[1]):null; |
|
229 | + foreach (explode('&', $qs) as $s) { |
|
230 | + $kv = explode('=', $s, 2); |
|
231 | + $out[urldecode($kv[0])] = isset($kv[1]) ?urldecode($kv[1]) : null; |
|
232 | 232 | } |
233 | 233 | return $out; |
234 | 234 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | $m = array(); |
247 | 247 | while ($this->lineNo + 1 < $this->lineCount && |
248 | 248 | (!trim($this->lines[$this->lineNo + 1]) || |
249 | - preg_match('/^(\s){' . $indent . '}((\s)+[^\s].*)$/', |
|
249 | + preg_match('/^(\s){'.$indent.'}((\s)+[^\s].*)$/', |
|
250 | 250 | $this->lines[$this->lineNo + 1], $m))) { |
251 | 251 | if (trim($this->lines[$this->lineNo + 1])) |
252 | 252 | $out[] = $m[2]; |