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,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wproot.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path('../lib', __FILE__))
4
+
5
+ require 'wproot'
6
+
7
+ WPRoot::CLI.new(ARGV)
@@ -0,0 +1,11 @@
1
+ require 'open3'
2
+ require 'fssm'
3
+
4
+ require "wproot/cli"
5
+ require "wproot/compass"
6
+ require "wproot/haml"
7
+ require "wproot/version"
8
+
9
+ module WPRoot
10
+ # Your code goes here...
11
+ end
@@ -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
@@ -0,0 +1,15 @@
1
+ module WPRoot
2
+ class Compass
3
+ def initialize(content)
4
+ @content = content
5
+ end
6
+
7
+ def compile
8
+ IO.popen('sass --compass -s', 'w+') do |io|
9
+ io.write(@content)
10
+ io.close_write
11
+ io.read
12
+ end
13
+ end
14
+ end
15
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ module WPRoot
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'wproot'
4
+
5
+ RSpec.configure do |config|
6
+
7
+ end
@@ -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
@@ -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,6 @@
1
+ .buildpath
2
+ .project
3
+ .settings
4
+ tmp/*
5
+ index.haml
6
+ test.php
@@ -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
+ }