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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/bin/wproot +7 -0
- data/lib/wproot.rb +11 -0
- data/lib/wproot/cli.rb +35 -0
- data/lib/wproot/compass.rb +15 -0
- data/lib/wproot/haml.rb +15 -0
- data/lib/wproot/version.rb +3 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/wproot_spec.rb +59 -0
- data/vendor/HamlPHP.php +7 -0
- data/vendor/HamlPHP/.gitignore +6 -0
- data/vendor/HamlPHP/MIT-LICENSE +22 -0
- data/vendor/HamlPHP/README.mkd +39 -0
- data/vendor/HamlPHP/src/HamlPHP/CommentNode.php +92 -0
- data/vendor/HamlPHP/src/HamlPHP/Compiler.php +109 -0
- data/vendor/HamlPHP/src/HamlPHP/ContentEvaluator/ContentEvaluator.php +16 -0
- data/vendor/HamlPHP/src/HamlPHP/ContentEvaluator/DefaultContentEvaluator.php +22 -0
- data/vendor/HamlPHP/src/HamlPHP/DoctypeNode.php +47 -0
- data/vendor/HamlPHP/src/HamlPHP/Element.php +618 -0
- data/vendor/HamlPHP/src/HamlPHP/ElementNode.php +222 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/CssFilter.php +31 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/Filter.php +18 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/FilterContainer.php +34 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/JavascriptFilter.php +29 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/PhpFilter.php +24 -0
- data/vendor/HamlPHP/src/HamlPHP/Filter/PlainFilter.php +46 -0
- data/vendor/HamlPHP/src/HamlPHP/FilterNode.php +29 -0
- data/vendor/HamlPHP/src/HamlPHP/HamlNode.php +75 -0
- data/vendor/HamlPHP/src/HamlPHP/HamlPHP.php +191 -0
- data/vendor/HamlPHP/src/HamlPHP/Helpers.php +136 -0
- data/vendor/HamlPHP/src/HamlPHP/Interpolation.php +71 -0
- data/vendor/HamlPHP/src/HamlPHP/NodeFactory.php +80 -0
- data/vendor/HamlPHP/src/HamlPHP/RootNode.php +133 -0
- data/vendor/HamlPHP/src/HamlPHP/Storage/DontEvaluateStorage.php +68 -0
- data/vendor/HamlPHP/src/HamlPHP/Storage/FileStorage.php +74 -0
- data/vendor/HamlPHP/src/HamlPHP/Storage/Storage.php +24 -0
- data/vendor/HamlPHP/src/HamlPHP/TagNode.php +125 -0
- data/vendor/HamlPHP/src/HamlPHP/Util/BaseException.php +340 -0
- data/vendor/HamlPHP/src/HamlPHP/Util/BaseObject.php +94 -0
- data/vendor/HamlPHP/src/HamlPHP/Util/StringScanner.php +989 -0
- data/wproot.gemspec +21 -0
- metadata +126 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/bin/wproot
ADDED
data/lib/wproot.rb
ADDED
data/lib/wproot/cli.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module WPRoot
|
2
|
+
class CLI
|
3
|
+
def initialize(argv)
|
4
|
+
case argv.shift
|
5
|
+
when 'watch'
|
6
|
+
watch File.expand_path('.')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def watch(directory)
|
11
|
+
puts "Watching #{directory}"
|
12
|
+
FSSM.monitor directory do
|
13
|
+
compile = lambda do |base, relative|
|
14
|
+
path = File.join(base, relative)
|
15
|
+
dir = File.dirname(path)
|
16
|
+
if File.extname(relative) == '.haml'
|
17
|
+
new_path = File.join(dir, File.basename(path, '.haml'))
|
18
|
+
File.open(new_path, 'w') do |f|
|
19
|
+
f.write(Haml.new(File.read(path)).compile)
|
20
|
+
puts ">>> Compiled #{path} to #{new_path}"
|
21
|
+
end
|
22
|
+
elsif File.extname(relative) == '.sass'
|
23
|
+
new_path = File.join(dir, File.basename(path, '.sass'))
|
24
|
+
File.open(new_path, 'w') do |f|
|
25
|
+
f.write(Compass.new(File.read(path)).compile)
|
26
|
+
puts ">>> Compiled #{path} to #{new_path}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
update &compile
|
31
|
+
create &compile
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/wproot/haml.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module WPRoot
|
2
|
+
class Haml
|
3
|
+
def initialize(content)
|
4
|
+
@content = content
|
5
|
+
end
|
6
|
+
|
7
|
+
def compile
|
8
|
+
IO.popen(['php', File.expand_path('../../../vendor/HamlPHP.php', __FILE__)], 'w+') do |io|
|
9
|
+
io.write(@content)
|
10
|
+
io.close_write
|
11
|
+
io.read
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/wproot_spec.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WPRoot do
|
4
|
+
it "should have a version" do
|
5
|
+
WPRoot::VERSION.should be_a(String)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should evaluate haml code" do
|
9
|
+
haml = WPRoot::Haml.new <<HAML
|
10
|
+
!!! 5
|
11
|
+
%html
|
12
|
+
%body
|
13
|
+
%header
|
14
|
+
#content
|
15
|
+
%p= 0
|
16
|
+
%ul
|
17
|
+
%li
|
18
|
+
- f($x)
|
19
|
+
%footer 1
|
20
|
+
HAML
|
21
|
+
|
22
|
+
haml.compile.should eq(<<HTML
|
23
|
+
<!DOCTYPE html>
|
24
|
+
<html>
|
25
|
+
<body>
|
26
|
+
<header></header>
|
27
|
+
<div id="content">
|
28
|
+
<p><?php echo 0 ?></p>
|
29
|
+
<ul>
|
30
|
+
<li>
|
31
|
+
<?php f($x) ?>
|
32
|
+
</li>
|
33
|
+
</ul>
|
34
|
+
</div>
|
35
|
+
<footer>1</footer>
|
36
|
+
</body>
|
37
|
+
</html>
|
38
|
+
HTML
|
39
|
+
)
|
40
|
+
end
|
41
|
+
it "should evaluate compass/sass code" do
|
42
|
+
compass = WPRoot::Compass.new <<SASS
|
43
|
+
import css3
|
44
|
+
body
|
45
|
+
section
|
46
|
+
background: darken(white, 100%)
|
47
|
+
&:hover
|
48
|
+
background: linear-gradient(white, black)
|
49
|
+
SASS
|
50
|
+
|
51
|
+
compass.compile.should eq(<<CSS
|
52
|
+
body section {
|
53
|
+
background: black; }
|
54
|
+
body section:hover {
|
55
|
+
background: linear-gradient(#ffffff, #000000); }
|
56
|
+
CSS
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
data/vendor/HamlPHP.php
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
require_once 'HamlPHP/src/HamlPHP/HamlPHP.php';
|
4
|
+
require_once 'HamlPHP/src/HamlPHP/Storage/DontEvaluateStorage.php';
|
5
|
+
|
6
|
+
$compiler = new Compiler(new HamlPHP(new DontEvaluateStorage(dirname(__FILE__ . '/tmp/'))));
|
7
|
+
echo $compiler->parseString(stream_get_contents(STDIN));
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010 Simo Niemelä
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# HamlPHP
|
2
|
+
|
3
|
+
Yet another Haml to HTML converter written in PHP.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
PHP 5.2 or newer.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
index.haml
|
12
|
+
|
13
|
+
!!! 5
|
14
|
+
%html
|
15
|
+
%body
|
16
|
+
#container
|
17
|
+
%ul.navigation
|
18
|
+
%li Etusivu
|
19
|
+
%li Tuotteet
|
20
|
+
|
21
|
+
%h2 Tuotteet
|
22
|
+
%ul.products
|
23
|
+
%li= 1 * 6
|
24
|
+
- for ($i = 0; $i < 10; $i++)
|
25
|
+
%li= $i + 3
|
26
|
+
|
27
|
+
In your index.php
|
28
|
+
|
29
|
+
<?php
|
30
|
+
|
31
|
+
require_once 'src/HamlPHP/HamlPHP.php';
|
32
|
+
require_once 'src/HamlPHP/Storage/FileStorage.php';
|
33
|
+
|
34
|
+
// Make sure that a directory _tmp_ exists in your application and it is writable.
|
35
|
+
$parser = new HamlPHP(new FileStorage(dirname(__FILE__) . '/tmp/'));
|
36
|
+
|
37
|
+
$content = $parser->parseFile('index.haml');
|
38
|
+
|
39
|
+
echo $content;
|
@@ -0,0 +1,92 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
class CommentNode extends HamlNode
|
4
|
+
{
|
5
|
+
const HTML_COMMENT = '/';
|
6
|
+
const HAML_COMMENT = '-#';
|
7
|
+
const CONDITIONAL_COMMENT = "/\/\[([^\\]]+)\]/";
|
8
|
+
const HTML_COMMENT_TYPE = 1;
|
9
|
+
const HAML_COMMENT_TYPE = 2;
|
10
|
+
const CONDITIONAL_COMMENT_TYPE = 3;
|
11
|
+
|
12
|
+
private $_commentType = null;
|
13
|
+
private $_conditionalMatches = array();
|
14
|
+
|
15
|
+
public function __construct($line)
|
16
|
+
{
|
17
|
+
parent::__construct($line);
|
18
|
+
$this->identifyCommentType();
|
19
|
+
}
|
20
|
+
|
21
|
+
private function identifyCommentType()
|
22
|
+
{
|
23
|
+
$haml = $this->getHaml();
|
24
|
+
|
25
|
+
if (preg_match(
|
26
|
+
CommentNode::CONDITIONAL_COMMENT, $haml, $this->_conditionalMatches)) {
|
27
|
+
$this->_commentType = CommentNode::CONDITIONAL_COMMENT_TYPE;
|
28
|
+
|
29
|
+
} else if (substr($haml, 0, 1) === CommentNode::HTML_COMMENT) {
|
30
|
+
$this->_commentType = CommentNode::HTML_COMMENT_TYPE;
|
31
|
+
|
32
|
+
} else if (substr($haml, 0, 2) === CommentNode::HAML_COMMENT) {
|
33
|
+
$this->_commentType = CommentNode::HAML_COMMENT_TYPE;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
public function render()
|
38
|
+
{
|
39
|
+
$output = "";
|
40
|
+
|
41
|
+
switch ($this->_commentType) {
|
42
|
+
case CommentNode::HTML_COMMENT_TYPE:
|
43
|
+
$output = $this->renderHtmlComment() . "\n";
|
44
|
+
break;
|
45
|
+
case CommentNode::HAML_COMMENT_TYPE:
|
46
|
+
$output = $this->renderHamlComment() . "\n";
|
47
|
+
break;
|
48
|
+
case CommentNode::CONDITIONAL_COMMENT_TYPE:
|
49
|
+
$output = $this->renderConditionalComment() . "\n";
|
50
|
+
break;
|
51
|
+
default:
|
52
|
+
throw new Exception("Invalid comment type: " . $this->getHaml());
|
53
|
+
}
|
54
|
+
|
55
|
+
$interpolation = new Interpolation($output);
|
56
|
+
return $interpolation->render();
|
57
|
+
}
|
58
|
+
|
59
|
+
private function renderHtmlComment()
|
60
|
+
{
|
61
|
+
$output = $this->getSpaces() . "<!--";
|
62
|
+
$output .= $this->renderHtmlCommentBody();
|
63
|
+
$output .= "-->";
|
64
|
+
|
65
|
+
return $output;
|
66
|
+
}
|
67
|
+
|
68
|
+
private function renderHtmlCommentBody()
|
69
|
+
{
|
70
|
+
if ($this->hasChildren()) {
|
71
|
+
return "\n" . $this->renderChildren() . $this->getSpaces();
|
72
|
+
} else {
|
73
|
+
return substr($this->getHaml(), 1) . " ";
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
private function renderConditionalComment()
|
78
|
+
{
|
79
|
+
$output =
|
80
|
+
$this->getSpaces() . "<!--[" . $this->_conditionalMatches[1] . "]>";
|
81
|
+
|
82
|
+
$output .= $this->renderHtmlCommentBody();
|
83
|
+
$output .= "<![endif]-->";
|
84
|
+
|
85
|
+
return $output;
|
86
|
+
}
|
87
|
+
|
88
|
+
private function renderHamlComment()
|
89
|
+
{
|
90
|
+
return '';
|
91
|
+
}
|
92
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
require_once 'NodeFactory.php';
|
4
|
+
require_once 'RootNode.php';
|
5
|
+
|
6
|
+
require_once 'Filter/FilterContainer.php';
|
7
|
+
require_once 'Filter/CssFilter.php';
|
8
|
+
require_once 'Filter/PlainFilter.php';
|
9
|
+
require_once 'Filter/JavascriptFilter.php';
|
10
|
+
require_once 'Filter/PhpFilter.php';
|
11
|
+
|
12
|
+
class Compiler
|
13
|
+
{
|
14
|
+
private $_hamlphp = null;
|
15
|
+
private $_lines;
|
16
|
+
private $_currLine;
|
17
|
+
|
18
|
+
public function __construct(HamlPHP $hamlphp)
|
19
|
+
{
|
20
|
+
$this->setHamlPhp($hamlphp);
|
21
|
+
}
|
22
|
+
|
23
|
+
public function setHamlPhp(HamlPHP $hamlphp)
|
24
|
+
{
|
25
|
+
$this->_hamlphp = $hamlphp;
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Compiles haml from a file.
|
30
|
+
*
|
31
|
+
* @param string $fileName
|
32
|
+
*/
|
33
|
+
public function parseFile($fileName)
|
34
|
+
{
|
35
|
+
return $this->parseString(file_get_contents($fileName));
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Compiles haml from a string.
|
40
|
+
*
|
41
|
+
* @param string $rawString
|
42
|
+
*/
|
43
|
+
public function parseString($rawString)
|
44
|
+
{
|
45
|
+
$lines = explode("\n", trim((string) $rawString));
|
46
|
+
return $this->parseLines($lines);
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Compiles haml from an array of lines.
|
51
|
+
*
|
52
|
+
* @param array $rawLines
|
53
|
+
*/
|
54
|
+
public function parseLines(array $rawLines = array())
|
55
|
+
{
|
56
|
+
$this->_currLine = 0;
|
57
|
+
$this->_lines = $this->removeEmptyLines($rawLines);
|
58
|
+
$rootNode = new RootNode();
|
59
|
+
$rootNode->setCompiler($this);
|
60
|
+
$rootNode->setLineNumber(0);
|
61
|
+
$nodeFactory = $this->_hamlphp->getNodeFactory();
|
62
|
+
|
63
|
+
for ($len = count($this->_lines); $this->_currLine < $len; ++$this->_currLine) {
|
64
|
+
$rootNode->addNode($nodeFactory->createNode(
|
65
|
+
$this->_lines[$this->_currLine], $this->_currLine, $this));
|
66
|
+
}
|
67
|
+
|
68
|
+
return $rootNode->render();
|
69
|
+
}
|
70
|
+
|
71
|
+
public function getLines()
|
72
|
+
{
|
73
|
+
return $this->_lines;
|
74
|
+
}
|
75
|
+
|
76
|
+
public function getLine($index)
|
77
|
+
{
|
78
|
+
if (isset($this->_lines[$index])) {
|
79
|
+
return $this->_lines[$index];
|
80
|
+
}
|
81
|
+
|
82
|
+
return null;
|
83
|
+
}
|
84
|
+
|
85
|
+
public function getNextLine() {
|
86
|
+
$index = ++$this->_currLine;
|
87
|
+
|
88
|
+
if (isset($this->_lines[$index])) {
|
89
|
+
return $this->_lines[$index];
|
90
|
+
}
|
91
|
+
|
92
|
+
return null;
|
93
|
+
}
|
94
|
+
|
95
|
+
private function removeEmptyLines(array $rawLines)
|
96
|
+
{
|
97
|
+
$codeLines = array();
|
98
|
+
|
99
|
+
for ($i = 0, $len = count($rawLines); $i < $len; ++$i) {
|
100
|
+
$line = $rawLines[$i];
|
101
|
+
|
102
|
+
if (trim($line) != '') {
|
103
|
+
$codeLines[] = $line;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
return $codeLines;
|
108
|
+
}
|
109
|
+
}
|