wproot 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +2 -0
  4. data/bin/wproot +7 -0
  5. data/lib/wproot.rb +11 -0
  6. data/lib/wproot/cli.rb +35 -0
  7. data/lib/wproot/compass.rb +15 -0
  8. data/lib/wproot/haml.rb +15 -0
  9. data/lib/wproot/version.rb +3 -0
  10. data/spec/spec_helper.rb +7 -0
  11. data/spec/wproot_spec.rb +59 -0
  12. data/vendor/HamlPHP.php +7 -0
  13. data/vendor/HamlPHP/.gitignore +6 -0
  14. data/vendor/HamlPHP/MIT-LICENSE +22 -0
  15. data/vendor/HamlPHP/README.mkd +39 -0
  16. data/vendor/HamlPHP/src/HamlPHP/CommentNode.php +92 -0
  17. data/vendor/HamlPHP/src/HamlPHP/Compiler.php +109 -0
  18. data/vendor/HamlPHP/src/HamlPHP/ContentEvaluator/ContentEvaluator.php +16 -0
  19. data/vendor/HamlPHP/src/HamlPHP/ContentEvaluator/DefaultContentEvaluator.php +22 -0
  20. data/vendor/HamlPHP/src/HamlPHP/DoctypeNode.php +47 -0
  21. data/vendor/HamlPHP/src/HamlPHP/Element.php +618 -0
  22. data/vendor/HamlPHP/src/HamlPHP/ElementNode.php +222 -0
  23. data/vendor/HamlPHP/src/HamlPHP/Filter/CssFilter.php +31 -0
  24. data/vendor/HamlPHP/src/HamlPHP/Filter/Filter.php +18 -0
  25. data/vendor/HamlPHP/src/HamlPHP/Filter/FilterContainer.php +34 -0
  26. data/vendor/HamlPHP/src/HamlPHP/Filter/JavascriptFilter.php +29 -0
  27. data/vendor/HamlPHP/src/HamlPHP/Filter/PhpFilter.php +24 -0
  28. data/vendor/HamlPHP/src/HamlPHP/Filter/PlainFilter.php +46 -0
  29. data/vendor/HamlPHP/src/HamlPHP/FilterNode.php +29 -0
  30. data/vendor/HamlPHP/src/HamlPHP/HamlNode.php +75 -0
  31. data/vendor/HamlPHP/src/HamlPHP/HamlPHP.php +191 -0
  32. data/vendor/HamlPHP/src/HamlPHP/Helpers.php +136 -0
  33. data/vendor/HamlPHP/src/HamlPHP/Interpolation.php +71 -0
  34. data/vendor/HamlPHP/src/HamlPHP/NodeFactory.php +80 -0
  35. data/vendor/HamlPHP/src/HamlPHP/RootNode.php +133 -0
  36. data/vendor/HamlPHP/src/HamlPHP/Storage/DontEvaluateStorage.php +68 -0
  37. data/vendor/HamlPHP/src/HamlPHP/Storage/FileStorage.php +74 -0
  38. data/vendor/HamlPHP/src/HamlPHP/Storage/Storage.php +24 -0
  39. data/vendor/HamlPHP/src/HamlPHP/TagNode.php +125 -0
  40. data/vendor/HamlPHP/src/HamlPHP/Util/BaseException.php +340 -0
  41. data/vendor/HamlPHP/src/HamlPHP/Util/BaseObject.php +94 -0
  42. data/vendor/HamlPHP/src/HamlPHP/Util/StringScanner.php +989 -0
  43. data/wproot.gemspec +21 -0
  44. metadata +126 -0
@@ -0,0 +1,222 @@
1
+ <?php
2
+
3
+ require_once 'RootNode.php';
4
+ require_once 'HamlNode.php';
5
+ require_once 'Element.php';
6
+
7
+ class ElementNode extends HamlNode
8
+ {
9
+ private $_phpVariable;
10
+
11
+ /**
12
+ * @var Element
13
+ */
14
+ private $_el;
15
+
16
+ public function __construct($line, $compiler)
17
+ {
18
+ parent::__construct($line);
19
+ $this->_phpVariable = false;
20
+ $this->_el = new Element($this->getHaml(), $compiler);
21
+ $this->_phpVariable = $this->_el->isPhpVariable();
22
+ }
23
+
24
+ public function render()
25
+ {
26
+ return $this->renderHtml($this->_el);
27
+ }
28
+
29
+ private function renderHtml(Element $element)
30
+ {
31
+ $output = '';
32
+
33
+ if ($this->getIndentationLevel() > 0)
34
+ {
35
+ $output .= $this->getSpaces() . '<' . $element->getTag();
36
+ }
37
+ else
38
+ {
39
+ $output .= '<' . $element->getTag();
40
+ }
41
+
42
+ if ($element->useAttsHelper())
43
+ {
44
+ $output .= ' <?php atts(array(';
45
+ if (($atts = $element->getAttributes()) != null)
46
+ {
47
+ if (isset($atts['id'])) {
48
+ $output .= "'id' => " . $this->_renderArrayValue($atts['id'], '_', 'php').', ';
49
+ unset($atts['id']);
50
+ }
51
+
52
+ if (isset($atts['class'])) {
53
+ $output .= "'class' => " . $this->_renderArrayValue($atts['class'], ' ', 'php').', ';
54
+ unset($atts['class']);
55
+ }
56
+
57
+ foreach ($atts as $name => $att)
58
+ {
59
+ $output .= "";
60
+ switch ($att['t'])
61
+ {
62
+ case 'str':
63
+ $output .= "'$name' => {$att['v']}, ";
64
+ continue;
65
+ case 'php':
66
+ if (is_array($att['v']))
67
+ $output .= "'$name' => array(" . join(',', $att['v']) . ')';
68
+ else
69
+ $output .= "'$name' => {$att['v']}, ";
70
+
71
+ continue;
72
+ case 'static':
73
+ $output .= "'$name' => '$name', ";
74
+ continue;
75
+ case 'function':
76
+ $output .= "{$att['v']}, ";
77
+ continue;
78
+ }
79
+ }
80
+ }
81
+
82
+ $output = rtrim($output, ', ');
83
+ $output .= ')); ?>';
84
+ }
85
+ else
86
+ {
87
+ if (($atts = $element->getAttributes()) !== null)
88
+ {
89
+ if (isset($atts['id'])) {
90
+ $output .= ' id="'.$this->_renderArrayValue($atts['id'], '_', 'txt').'"';
91
+ unset($atts['id']);
92
+ }
93
+
94
+ if (isset($atts['class'])) {
95
+ $output .= ' class="'.$this->_renderArrayValue($atts['class'], ' ', 'txt').'"';
96
+ unset($atts['class']);
97
+ }
98
+
99
+ foreach ($atts as $name => $att)
100
+ {
101
+ switch ($att['t'])
102
+ {
103
+ case 'str':
104
+ $output .= " {$name}={$att['v']}";
105
+ continue;
106
+ case 'php':
107
+ $output .= " $name=<?php {$att['v']}; ?>";
108
+
109
+ continue;
110
+ case 'static':
111
+ $output .= " $name=\"$name\"";
112
+ continue;
113
+ }
114
+ }
115
+ }
116
+ }
117
+
118
+ $content = $this->renderTagContent($element->getInlineContent());
119
+
120
+ $interpolation = new Interpolation($output);
121
+ $output = $interpolation->render();
122
+
123
+ // render inline content
124
+ $output .= '>' . $content . '</' . $element->getTag() . '>';
125
+ return $output . "\n";
126
+ }
127
+
128
+ /**
129
+ * Joins the string $parts together using $separator but format the return according to context.
130
+ * This method concatenates all the parts using $separtor as glue. If the context is 'txt'
131
+ * and at least one part is php, the returned string will be encapsuled inside <?php ... ?>
132
+ * If the context is 'php' the string returned will be a valid php code.
133
+ * @code
134
+ * _renderArrayValue(array(
135
+ * array('t' => 'str', 'v' => 'a',
136
+ * array('t' => 'str', 'v' => 'b')); # -> a_b
137
+ *
138
+ * _renderArrayValue(array(
139
+ * array('t' => 'str', 'v' => 'a',
140
+ * array('t' => 'str', 'v' => 'b'), 'php'); # -> 'a_b'
141
+ *
142
+ * _renderArrayValue(array(
143
+ * array('t' => 'str', 'v' => 'a',
144
+ * array('t' => 'php', 'v' => '$b')); # -> <?php echo 'a_'.$b; ?>
145
+ *
146
+ * _renderArrayValue(array(
147
+ * array('t' => 'str', 'v' => 'a',
148
+ * array('t' => 'php', 'v' => '$b'), 'php'); # -> 'a_'.$b
149
+ * @endcode
150
+ *
151
+ * @param $arr_parts The components of the id
152
+ * @param $context The context into which the value will be inserted. Can be 'txt' (default) or 'php'
153
+ */
154
+ private function _renderArrayValue($parts, $separator = ' ', $context = 'txt')
155
+ {
156
+ $hasPhp = false;
157
+ $values = array();
158
+
159
+ foreach ($parts as $p)
160
+ {
161
+ if ($p['t'] == 'php')
162
+ {
163
+ $hasPhp = true;
164
+ $values[] = $p['v'];
165
+ }
166
+ else
167
+ {
168
+ $values[] = "'{$p['v']}'";
169
+ }
170
+ }
171
+
172
+ if (!$hasPhp)
173
+ {
174
+ $quote = '';
175
+ if ('php' == $context)
176
+ $quote = "'";
177
+
178
+ $value = '';
179
+ foreach($parts as $p)
180
+ $value .= "$separator{$p['v']}";
181
+
182
+ return $quote . trim($value, $separator) . $quote;
183
+ }
184
+ else
185
+ {
186
+ $value = join(".", $values);
187
+ $value = str_replace("'.'", $separator, $value);
188
+ $value = str_replace(".'", ".'$separator", $value);
189
+ $value = str_replace("'.", "$separator'.", $value);
190
+
191
+ if('txt' == $context)
192
+ return '<?php echo '.$value.'; ?>';
193
+
194
+ return $value;
195
+ }
196
+ }
197
+
198
+ private function renderTagContent($content)
199
+ {
200
+ if ($this->hasChildren())
201
+ {
202
+ $content = "\n" . $this->renderChildren() . $this->getSpaces();
203
+ }
204
+
205
+ if ($content === null)
206
+ {
207
+ $content = '';
208
+ }
209
+
210
+ if ($this->_phpVariable)
211
+ {
212
+ $content = "<?php echo " . $content . " ?>";
213
+ }
214
+ else
215
+ {
216
+ $interpolation = new Interpolation($content);
217
+ $content = $interpolation->render();
218
+ }
219
+
220
+ return $content;
221
+ }
222
+ }
@@ -0,0 +1,31 @@
1
+ <?php
2
+
3
+ require_once 'Filter.php';
4
+
5
+ class CssFilter implements Filter
6
+ {
7
+ public function getIdentifier()
8
+ {
9
+ return 'css';
10
+ }
11
+
12
+ public function filter(HamlNode $node)
13
+ {
14
+ if (null === $node) {
15
+ throw new Exception("CssFilter: node is null.");
16
+ }
17
+
18
+ $plainFilter = new PlainFilter();
19
+
20
+ $output = $node->getSpaces() . "<style type=\"text/css\">\n";
21
+
22
+ $oldLevel = $node->getIndentationLevel();
23
+ $node->setIndentationLevel($oldLevel + 2);
24
+ $output .= $plainFilter->filter($node);
25
+ $node->setIndentationLevel($oldLevel);
26
+
27
+ $output .= $node->getSpaces() . "</style>";
28
+
29
+ return $output . "\n";
30
+ }
31
+ }
@@ -0,0 +1,18 @@
1
+ <?php
2
+
3
+ interface Filter
4
+ {
5
+ /**
6
+ * Returns an identifier of this filter.
7
+ *
8
+ * @return string
9
+ */
10
+ public function getIdentifier();
11
+
12
+ /**
13
+ * Filters given node.
14
+ *
15
+ * @param HamlNode object
16
+ */
17
+ public function filter(HamlNode $node);
18
+ }
@@ -0,0 +1,34 @@
1
+ <?php
2
+
3
+ require_once 'Filter.php';
4
+
5
+ class FilterContainer
6
+ {
7
+ private $_filters = array();
8
+
9
+ public function __construct($filters = array())
10
+ {
11
+ foreach ($filters as $filter) {
12
+ $this->addFilter($filter);
13
+ }
14
+ }
15
+
16
+ public function addFilter(Filter $filter)
17
+ {
18
+ $this->_filters[$filter->getIdentifier()] = $filter;
19
+ }
20
+
21
+ public function getFilters()
22
+ {
23
+ return $this->_filters;
24
+ }
25
+
26
+ public function getFilter($identifier)
27
+ {
28
+ if (isset($this->_filters[$identifier])) {
29
+ return $this->_filters[$identifier];
30
+ }
31
+
32
+ return null;
33
+ }
34
+ }
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ class JavascriptFilter implements Filter
4
+ {
5
+ public function getIdentifier()
6
+ {
7
+ return 'javascript';
8
+ }
9
+
10
+ public function filter(HamlNode $node)
11
+ {
12
+ if ($node === null) {
13
+ throw new Exception('Javascript filter: node is null');
14
+ }
15
+
16
+ $plainFilter = new PlainFilter();
17
+
18
+ $output = $node->getSpaces() . "<script type=\"text/javascript\">\n";
19
+
20
+ $oldLevel = $node->getIndentationLevel();
21
+ $node->setIndentationLevel($oldLevel + 2);
22
+ $output .= $plainFilter->filter($node);
23
+ $node->setIndentationLevel($oldLevel);
24
+
25
+ $output .= $node->getSpaces() . "</script>";
26
+
27
+ return $output . "\n";
28
+ }
29
+ }
@@ -0,0 +1,24 @@
1
+ <?php
2
+
3
+ class PhpFilter implements Filter
4
+ {
5
+ public function getIdentifier()
6
+ {
7
+ return 'php';
8
+ }
9
+
10
+ public function filter(HamlNode $node)
11
+ {
12
+ if ($node === null) {
13
+ throw new Exception('PHP filter: node is null');
14
+ }
15
+
16
+ $plainFilter = new PlainFilter();
17
+
18
+ $output = $node->getSpaces() . "<?php\n";
19
+ $output .= $plainFilter->filter($node);
20
+ $output .= $node->getSpaces() . "?>";
21
+
22
+ return $output . "\n";
23
+ }
24
+ }
@@ -0,0 +1,46 @@
1
+ <?php
2
+
3
+ require_once 'Filter.php';
4
+
5
+ class PlainFilter implements Filter
6
+ {
7
+ public function getIdentifier()
8
+ {
9
+ return 'plain';
10
+ }
11
+
12
+ public function filter(HamlNode $node)
13
+ {
14
+ if (null === $node) {
15
+ throw new Exception("PlainFilter: node is null.");
16
+ }
17
+
18
+ $children = $node->getChildren();
19
+ $output = '';
20
+
21
+ foreach ($children as $childNode) {
22
+ $output .= $this->renderChildrenHaml($childNode);
23
+ }
24
+
25
+ return $output;
26
+ }
27
+
28
+ protected function renderChildrenHaml(HamlNode $node)
29
+ {
30
+ $parent = $node->getParent();
31
+ $haml = $parent !== null
32
+ ? $parent->getSpaces() . $node->getHaml() : $node->getRawHaml();
33
+
34
+ $output = $haml . "\n";
35
+
36
+ if ($node->hasChildren()) {
37
+ $children = $node->getChildren();
38
+
39
+ for ($i = 0, $count = count($children); $i < $count; ++$i) {
40
+ $output .= $this->renderChildrenHaml($children[$i]);
41
+ }
42
+ }
43
+
44
+ return $output;
45
+ }
46
+ }
@@ -0,0 +1,29 @@
1
+ <?php
2
+
3
+ class FilterNode extends HamlNode
4
+ {
5
+ private $_filterContainer = null;
6
+
7
+ public function __construct($line, FilterContainer $container = null)
8
+ {
9
+ parent::__construct($line);
10
+ $this->_filterContainer = $container;
11
+ }
12
+
13
+ public function render()
14
+ {
15
+ if (null === $this->_filterContainer) {
16
+ return '';
17
+ }
18
+
19
+ $identifier = str_replace(':', '', $this->getHaml());
20
+ $filter = $this->_filterContainer->getFilter($identifier);
21
+
22
+ if (null === $filter) {
23
+ throw new Exception(sprintf("Unknown filter '%s'.", $identifier));
24
+ }
25
+
26
+ $interpolation = new Interpolation($filter->filter($this));
27
+ return $interpolation->render();
28
+ }
29
+ }
@@ -0,0 +1,75 @@
1
+ <?php
2
+
3
+ class HamlNode extends RootNode
4
+ {
5
+ private $_rawHaml;
6
+ private $_haml;
7
+ private $_spaces;
8
+
9
+ public function __construct($line)
10
+ {
11
+ parent::__construct();
12
+ $this->_rawHaml = $line;
13
+ $this->_haml = trim($line);
14
+ $this->setIndentationLevel(strlen($line) - strlen(ltrim($line)));
15
+ }
16
+
17
+ public function getSpaces()
18
+ {
19
+ return $this->_spaces;
20
+ }
21
+
22
+ public function setIndentationLevel($level)
23
+ {
24
+ $oldLevel = $this->getIndentationLevel();
25
+ parent::setIndentationLevel($level);
26
+ $this->_spaces = $this->createSpaces();
27
+
28
+ if ($this->hasChildren()) {
29
+ $children = $this->getChildren();
30
+
31
+ for ($i = 0, $len = count($children); $i < $len; $i++) {
32
+ $childNode = $children[$i];
33
+ $currentLevel = $this->getIndentationLevel();
34
+ $childLevel = $childNode->getIndentationLevel();
35
+ $oldDiff = $childLevel - $oldLevel;
36
+ $newLevel = $currentLevel + $oldDiff;
37
+ $childNode->setIndentationLevel($newLevel);
38
+ }
39
+ }
40
+ }
41
+
42
+ public function getRawHaml()
43
+ {
44
+ return $this->_rawHaml;
45
+ }
46
+
47
+ public function getHaml()
48
+ {
49
+ return $this->_haml;
50
+ }
51
+
52
+ private function createSpaces()
53
+ {
54
+ $spaces = '';
55
+
56
+ for ($i = 0; $i < $this->getIndentationLevel(); ++$i) {
57
+ $spaces .= ' ';
58
+ }
59
+
60
+ return $spaces;
61
+ }
62
+
63
+ public function render()
64
+ {
65
+ $output = $this->_spaces . $this->_haml . "\n";
66
+ $interpolation = new Interpolation($output);
67
+ $output = $interpolation->render();
68
+
69
+ if ($this->hasChildren()) {
70
+ $output = $output . $this->renderChildren();
71
+ }
72
+
73
+ return $output;
74
+ }
75
+ }