guard-mthaml 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +34 -0
- data/lib/guard/mthaml.rb +140 -0
- data/lib/guard/mthaml/compiler/MtHaml.php +255 -0
- data/lib/guard/mthaml/templates/Guardfile +12 -0
- data/lib/guard/mthaml/version.rb +5 -0
- data/vendor/autoload.php +7 -0
- data/vendor/coffeescript/coffeescript/LICENSE +22 -0
- data/vendor/coffeescript/coffeescript/README.md +96 -0
- data/vendor/coffeescript/coffeescript/composer.json +23 -0
- data/vendor/coffeescript/coffeescript/grammar.y +309 -0
- data/vendor/coffeescript/coffeescript/make.php +115 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Compiler.php +76 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Error.php +15 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Helpers.php +116 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Init.php +96 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Lexer.php +1356 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Nodes.php +105 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Parser.php +3326 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Rewriter.php +552 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Scope.php +196 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/SyntaxError.php +9 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/Value.php +20 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Access.php +31 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Arr.php +69 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Assign.php +353 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Base.php +288 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Block.php +294 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Call.php +283 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Class.php +282 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Closure.php +49 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Code.php +203 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Comment.php +39 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Existence.php +42 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Extends.php +26 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/For.php +250 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/If.php +161 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/In.php +99 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Index.php +27 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Literal.php +96 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Obj.php +126 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Op.php +292 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Param.php +119 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Parens.php +45 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Range.php +225 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Return.php +56 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Slice.php +47 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Splat.php +100 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Switch.php +121 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Throw.php +37 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Try.php +79 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/Value.php +210 -0
- data/vendor/coffeescript/coffeescript/src/CoffeeScript/yy/While.php +112 -0
- data/vendor/coffeescript/coffeescript/tests/cases/arrays.coffee +77 -0
- data/vendor/coffeescript/coffeescript/tests/cases/assignment.coffee +352 -0
- data/vendor/coffeescript/coffeescript/tests/cases/booleans.coffee +21 -0
- data/vendor/coffeescript/coffeescript/tests/cases/classes.coffee +681 -0
- data/vendor/coffeescript/coffeescript/tests/cases/comments.coffee +207 -0
- data/vendor/coffeescript/coffeescript/tests/cases/compilation.coffee +72 -0
- data/vendor/coffeescript/coffeescript/tests/cases/comprehensions.coffee +501 -0
- data/vendor/coffeescript/coffeescript/tests/cases/control_flow.coffee +430 -0
- data/vendor/coffeescript/coffeescript/tests/cases/eval.coffee +29 -0
- data/vendor/coffeescript/coffeescript/tests/cases/exception_handling.coffee +102 -0
- data/vendor/coffeescript/coffeescript/tests/cases/formatting.coffee +146 -0
- data/vendor/coffeescript/coffeescript/tests/cases/function_invocation.coffee +552 -0
- data/vendor/coffeescript/coffeescript/tests/cases/functions.coffee +188 -0
- data/vendor/coffeescript/coffeescript/tests/cases/helpers.coffee +96 -0
- data/vendor/coffeescript/coffeescript/tests/cases/importing.coffee +18 -0
- data/vendor/coffeescript/coffeescript/tests/cases/interpolation.coffee +138 -0
- data/vendor/coffeescript/coffeescript/tests/cases/javascript_literals.coffee +10 -0
- data/vendor/coffeescript/coffeescript/tests/cases/numbers.coffee +76 -0
- data/vendor/coffeescript/coffeescript/tests/cases/objects.coffee +271 -0
- data/vendor/coffeescript/coffeescript/tests/cases/operators.coffee +277 -0
- data/vendor/coffeescript/coffeescript/tests/cases/option_parser.coffee +43 -0
- data/vendor/coffeescript/coffeescript/tests/cases/ranges.coffee +88 -0
- data/vendor/coffeescript/coffeescript/tests/cases/regexps.coffee +63 -0
- data/vendor/coffeescript/coffeescript/tests/cases/scope.coffee +43 -0
- data/vendor/coffeescript/coffeescript/tests/cases/slicing_and_splicing.coffee +143 -0
- data/vendor/coffeescript/coffeescript/tests/cases/soaks.coffee +134 -0
- data/vendor/coffeescript/coffeescript/tests/cases/strict.coffee +155 -0
- data/vendor/coffeescript/coffeescript/tests/cases/strings.coffee +107 -0
- data/vendor/coffeescript/coffeescript/tests/css/style.css +43 -0
- data/vendor/coffeescript/coffeescript/tests/index.php +119 -0
- data/vendor/coffeescript/coffeescript/tests/js/lib/coffeescript_1.1.1.js +8 -0
- data/vendor/coffeescript/coffeescript/tests/js/lib/coffeescript_1.2.0.js +8 -0
- data/vendor/coffeescript/coffeescript/tests/js/lib/coffeescript_1.3.0.js +8 -0
- data/vendor/coffeescript/coffeescript/tests/js/lib/coffeescript_1.3.1.js +8 -0
- data/vendor/coffeescript/coffeescript/tests/js/lib/diff.js +276 -0
- data/vendor/coffeescript/coffeescript/tests/js/main.js +123 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/LICENSE.txt +10 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/Lempar.php +948 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Action.php +257 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/ActionTable.php +299 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Config.php +574 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Data.php +1857 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Parser.php +851 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/PropagationLink.php +126 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Rule.php +144 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/State.php +283 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/Symbol.php +288 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/PHP/ParserGenerator/cli.php +5 -0
- data/vendor/coffeescript/coffeescript/vendor/ParserGenerator/ParserGenerator.php +811 -0
- data/vendor/composer/ClassLoader.php +383 -0
- data/vendor/composer/autoload_classmap.php +9 -0
- data/vendor/composer/autoload_namespaces.php +12 -0
- data/vendor/composer/autoload_psr4.php +10 -0
- data/vendor/composer/autoload_real.php +50 -0
- data/vendor/composer/installed.json +166 -0
- data/vendor/michelf/php-markdown/License.md +36 -0
- data/vendor/michelf/php-markdown/Michelf/Markdown.inc.php +10 -0
- data/vendor/michelf/php-markdown/Michelf/Markdown.php +3117 -0
- data/vendor/michelf/php-markdown/Michelf/MarkdownExtra.inc.php +11 -0
- data/vendor/michelf/php-markdown/Michelf/MarkdownExtra.php +38 -0
- data/vendor/michelf/php-markdown/Michelf/MarkdownInterface.inc.php +9 -0
- data/vendor/michelf/php-markdown/Michelf/MarkdownInterface.php +37 -0
- data/vendor/michelf/php-markdown/Readme.md +305 -0
- data/vendor/michelf/php-markdown/Readme.php +31 -0
- data/vendor/michelf/php-markdown/composer.json +31 -0
- data/vendor/mthaml/mthaml/CHANGELOG +48 -0
- data/vendor/mthaml/mthaml/LICENSE +44 -0
- data/vendor/mthaml/mthaml/README.markdown +262 -0
- data/vendor/mthaml/mthaml/composer.json +45 -0
- data/vendor/mthaml/mthaml/docs/Makefile +153 -0
- data/vendor/mthaml/mthaml/docs/_static/mthaml.css +30 -0
- data/vendor/mthaml/mthaml/docs/_theme/mthaml/theme.conf +4 -0
- data/vendor/mthaml/mthaml/docs/conf.py +242 -0
- data/vendor/mthaml/mthaml/docs/index.rst +18 -0
- data/vendor/mthaml/mthaml/docs/twig-syntax.rst +274 -0
- data/vendor/mthaml/mthaml/examples/README.md +5 -0
- data/vendor/mthaml/mthaml/examples/autoload.php +8 -0
- data/vendor/mthaml/mthaml/examples/example-php.haml +5 -0
- data/vendor/mthaml/mthaml/examples/example-php.php +37 -0
- data/vendor/mthaml/mthaml/examples/example-twig-noext.twig +11 -0
- data/vendor/mthaml/mthaml/examples/example-twig.haml +9 -0
- data/vendor/mthaml/mthaml/examples/example-twig.php +60 -0
- data/vendor/mthaml/mthaml/examples/example.twig.haml +8 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Autoloader.php +22 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Environment.php +178 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Escaping.php +33 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Exception.php +9 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Exception/SyntaxErrorException.php +9 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/AbstractFilter.php +43 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Cdata.php +16 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php +33 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Css.php +26 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Escaped.php +22 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/FilterInterface.php +15 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Javascript.php +26 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Less.php +27 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Less/LeafoLess.php +20 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Less/OyejorgeLess.php +23 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown.php +58 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown/CebeMarkdown.php +22 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown/Ciconia.php +21 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown/MichelfMarkdown.php +21 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Markdown/Parsedown.php +21 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Php.php +37 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Plain.php +24 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Preserve.php +19 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Scss.php +37 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Filter/Twig.php +47 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Indentation/Indentation.php +96 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Indentation/IndentationException.php +9 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Indentation/IndentationInterface.php +50 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Indentation/Undefined.php +41 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/Comment.php +71 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/Doctype.php +96 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/EscapableAbstract.php +19 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/Filter.php +51 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/Insert.php +42 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/InterpolatedString.php +73 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/NestAbstract.php +117 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/NestInterface.php +10 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/NodeAbstract.php +77 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/ObjectRefClass.php +42 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/ObjectRefId.php +42 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/Root.php +35 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/Run.php +71 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/Statement.php +45 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/Tag.php +90 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/TagAttribute.php +62 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/TagAttributeInterpolation.php +24 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/TagAttributeList.php +24 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Node/Text.php +37 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Autoclose.php +25 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Escaping.php +105 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/MergeAttrs.php +110 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Midblock.php +37 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/NodeVisitorAbstract.php +226 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/NodeVisitorInterface.php +97 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/PhpRenderer.php +288 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/Printer.php +265 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/RendererAbstract.php +581 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/NodeVisitor/TwigRenderer.php +252 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Parser.php +862 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Parser/Buffer.php +147 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Runtime.php +218 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Runtime/AttributeInterpolation.php +16 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Runtime/AttributeList.php +16 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Support/Php/Executor.php +157 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Support/Twig/Extension.php +47 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Support/Twig/Lexer.php +48 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Support/Twig/Loader.php +81 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Target/Php.php +23 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Target/TargetAbstract.php +87 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Target/TargetInterface.php +12 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/Target/Twig.php +23 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/TreeBuilder.php +100 -0
- data/vendor/mthaml/mthaml/lib/MtHaml/TreeBuilderException.php +9 -0
- data/vendor/mthaml/mthaml/phpunit.xml +25 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/EnvironmentTest.php +59 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/HamlSpecTest.php +83 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/IndentationTest.php +140 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/Node/DoctypeTest.php +51 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/Node/NodeTest.php +110 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/NodeVisitor/PhpRendererTest.php +113 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/NodeVisitor/TwigRendererTest.php +68 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/NodeVisitorsTest.php +44 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/Parser/BufferTest.php +77 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/ParserTest.php +47 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/RuntimeTest.php +356 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/Support/Php/ExecutorTest.php +83 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/Support/Twig/LoaderTest.php +65 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/TestCase.php +49 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/TestCaseTest.php +50 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/Support/Php/Executor.001.haml +1 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/attr_list_php.test +20 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/attr_list_twig.test +12 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/boolean_attr_php.test +16 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/boolean_attr_twig.test +16 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/bug28_php.test +15 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/bug28_twig.test +15 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/bug42.test +13 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/bug8_twig.test +10 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/coffeescript_filter.test +31 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/comments.test +26 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/cond_cmt.test +25 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype.test +18 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_html4.test +20 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_invalid.test +12 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_invalid_xhtml.test +12 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_php.test +18 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/doctype_xhtml.test +30 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/filters.test +51 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/insert_non_echo_php.test +11 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/insert_non_echo_twig.test +11 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/interpolation_in_html_attrs_php.test +31 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/interpolation_in_html_attrs_twig.test +31 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/less_filter_leafo.test +33 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/less_filter_oyejorge.test +49 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_filter_cebemarkdown.test +35 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_filter_ciconia.test +36 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_filter_michelf.test +34 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_filter_parsedown.test +31 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/markdown_optimization_filter_michelf.test +23 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/mergeattrs.test +18 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/nuke_inner_whitespace.test +77 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/nuke_outer_whitespace.test +122 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/object_ref_php.test +14 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/object_ref_twig.test +14 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php.test +109 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php_autoescaping.test +22 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php_autoescaping_once.test +25 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php_blocks.test +29 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/php_filters.test +42 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/scss_filter.test +32 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/strip_inline_comments_php.test +22 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/test.test +24 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/trailing_semicolon_php.test +14 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/try_catch_php.test +17 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/twig.test +112 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/twig_blocks.test +29 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/twig_filters.test +37 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/twig_whitespace.test +32 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/environment/whitespace.test +63 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/autoclose.test +30 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/escaping.test +52 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/escaping_attr_once.test +52 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/escaping_html_false.test +52 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/mergeattrs.test +26 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/midblock.test +54 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/nodevisitors/midblock_002.test +32 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attr_list.test +14 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attrs.test +42 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attrs_002.test +35 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attrs_003.test +30 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/attrs_html_linebreak.test +17 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/blocks.test +27 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/blocks_002.test +15 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/boolean_attr.test +19 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/bug28.test +15 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/bug8.test +11 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/cond_cmt.test +23 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/doctype.test +11 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/double_equal.test +7 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/empty_line_after_multiline.test +10 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_001.test +8 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_002.test +8 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_003.test +8 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_004.test +6 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_005.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_006.test +7 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_007.test +7 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_008.test +7 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_009.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_010.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_013.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_016.test +7 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_017.test +8 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_018.test +6 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_019.test +6 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/errors_020.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters.test +20 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_002.test +19 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_003.test +13 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_004.test +21 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_005.test +22 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/filters_006.test +23 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/insertflags.test +17 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/interpolation.test +36 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/interpolation_in_html_attrs.test +17 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/multiline.test +18 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/multiline_code.test +59 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/multiple_attr_kinds.test +47 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/non_rendered_comment.test +31 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ns.test +11 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/object_ref.test +22 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/object_ref_error1.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/object_ref_error2.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/quotes_in_haml.test +10 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby19_attrs.test +11 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby_attrs_comma.test +23 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby_attrs_comma_errors_001.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby_attrs_comma_errors_002.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/ruby_attrs_comma_errors_003.test +5 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/standard.test +114 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/parser/tagflags.test +39 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/runtime/php_filters.test +28 -0
- data/vendor/mthaml/mthaml/test/MtHaml/Tests/fixtures/runtime/twig_filters.test +31 -0
- data/vendor/mthaml/mthaml/test/bootstrap.php +3 -0
- metadata +398 -0
@@ -0,0 +1,288 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
namespace MtHaml\NodeVisitor;
|
4
|
+
|
5
|
+
use MtHaml\Node\Insert;
|
6
|
+
use MtHaml\Node\Run;
|
7
|
+
use MtHaml\Node\InterpolatedString;
|
8
|
+
use MtHaml\Node\Tag;
|
9
|
+
use MtHaml\Node\ObjectRefClass;
|
10
|
+
use MtHaml\Node\NodeAbstract;
|
11
|
+
use MtHaml\Node\ObjectRefId;
|
12
|
+
use MtHaml\Node\TagAttributeInterpolation;
|
13
|
+
use MtHaml\Node\TagAttributeList;
|
14
|
+
use MtHaml\Node\Filter;
|
15
|
+
|
16
|
+
class PhpRenderer extends RendererAbstract
|
17
|
+
{
|
18
|
+
protected function escapeLanguage($string, $context)
|
19
|
+
{
|
20
|
+
// If there is a '?' at the begining of the string, it could become
|
21
|
+
// a '<?' when concatenated with previous output. So we need to escape
|
22
|
+
// '?' when appearing at the begining of the string, unless we know
|
23
|
+
// that previous output doesn't end with '<'.
|
24
|
+
$re = '~(^\?|<\?)~';
|
25
|
+
|
26
|
+
// when context is empty, consider that we don't know what's before
|
27
|
+
if (0 < strlen($context)) {
|
28
|
+
$len = strlen($context);
|
29
|
+
$char = $context[$len-1];
|
30
|
+
if ('<' !== $char) {
|
31
|
+
$re = '~(<\?)~';
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
return preg_replace($re, "<?php echo '\\1'; ?>", $string);
|
36
|
+
}
|
37
|
+
|
38
|
+
protected function stringLiteral($string)
|
39
|
+
{
|
40
|
+
return var_export((string) $string, true);
|
41
|
+
}
|
42
|
+
|
43
|
+
public function enterInterpolatedString(InterpolatedString $node)
|
44
|
+
{
|
45
|
+
if (!$this->isEchoMode() && 1 < count($node->getChilds())) {
|
46
|
+
$this->raw('(');
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
public function betweenInterpolatedStringChilds(InterpolatedString $node)
|
51
|
+
{
|
52
|
+
if (!$this->isEchoMode()) {
|
53
|
+
$this->raw(' . ');
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
public function leaveInterpolatedString(InterpolatedString $node)
|
58
|
+
{
|
59
|
+
if (!$this->isEchoMode() && 1 < count($node->getChilds())) {
|
60
|
+
$this->raw(')');
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
public function enterInsert(Insert $node)
|
65
|
+
{
|
66
|
+
$content = $node->getContent();
|
67
|
+
$content = $this->trimInlineComments($content);
|
68
|
+
|
69
|
+
if ($this->isEchoMode()) {
|
70
|
+
$fmt = '<?php echo %s; ?>';
|
71
|
+
|
72
|
+
if ($node->getEscaping()->isEnabled()) {
|
73
|
+
if ($node->getEscaping()->isOnce()) {
|
74
|
+
$fmt = "<?php echo htmlspecialchars(%s,ENT_QUOTES,'%s',false); ?>";
|
75
|
+
} else {
|
76
|
+
$fmt = "<?php echo htmlspecialchars(%s,ENT_QUOTES,'%s'); ?>";
|
77
|
+
}
|
78
|
+
}
|
79
|
+
$this->addDebugInfos($node);
|
80
|
+
$this->raw(sprintf($fmt, $content, $this->charset));
|
81
|
+
} else {
|
82
|
+
$content = $node->getContent();
|
83
|
+
if (!preg_match('~^\$?[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$~', $content)) {
|
84
|
+
$this->raw('(' . $content . ')');
|
85
|
+
} else {
|
86
|
+
$this->raw($content);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
public function enterTopBlock(Run $node)
|
92
|
+
{
|
93
|
+
$this->addDebugInfos($node);
|
94
|
+
|
95
|
+
$content = $this->trimInlineComments($node->getContent());
|
96
|
+
|
97
|
+
if (!$node->isBlock()) {
|
98
|
+
if (preg_match('~[:;]\s*$~', $content)) {
|
99
|
+
$this->write(sprintf('<?php %s ?>' , $content));
|
100
|
+
} else {
|
101
|
+
$this->write(sprintf('<?php %s; ?>' , $content));
|
102
|
+
}
|
103
|
+
} else {
|
104
|
+
$this->write(sprintf('<?php %s { ?>' , $content));
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
public function enterMidBlock(Run $node)
|
109
|
+
{
|
110
|
+
$this->addDebugInfos($node);
|
111
|
+
|
112
|
+
$content = $this->trimInlineComments($node->getContent());
|
113
|
+
|
114
|
+
$this->write(sprintf('<?php } %s { ?>' , $content));
|
115
|
+
}
|
116
|
+
|
117
|
+
public function leaveTopBlock(Run $node)
|
118
|
+
{
|
119
|
+
if ($node->isBlock()) {
|
120
|
+
$this->write('<?php } ?>');
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
public function enterObjectRefClass(ObjectRefClass $node)
|
125
|
+
{
|
126
|
+
if ($this->isEchoMode()) {
|
127
|
+
$this->raw('<?php echo ');
|
128
|
+
}
|
129
|
+
$this->raw('MtHaml\Runtime::renderObjectRefClass(');
|
130
|
+
|
131
|
+
$this->pushEchoMode(false);
|
132
|
+
}
|
133
|
+
|
134
|
+
public function leaveObjectRefClass(ObjectRefClass $node)
|
135
|
+
{
|
136
|
+
$this->raw(')');
|
137
|
+
|
138
|
+
$this->popEchoMode(true);
|
139
|
+
if ($this->isEchoMode()) {
|
140
|
+
$this->raw('; ?>');
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
public function enterObjectRefId(ObjectRefId $node)
|
145
|
+
{
|
146
|
+
if ($this->isEchoMode()) {
|
147
|
+
$this->raw('<?php echo ');
|
148
|
+
}
|
149
|
+
$this->raw('MtHaml\Runtime::renderObjectRefId(');
|
150
|
+
|
151
|
+
$this->pushEchoMode(false);
|
152
|
+
}
|
153
|
+
|
154
|
+
public function leaveObjectRefId(ObjectRefId $node)
|
155
|
+
{
|
156
|
+
$this->raw(')');
|
157
|
+
|
158
|
+
$this->popEchoMode(true);
|
159
|
+
if ($this->isEchoMode()) {
|
160
|
+
$this->raw('; ?>');
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
public function enterObjectRefPrefix(NodeAbstract $node)
|
165
|
+
{
|
166
|
+
$this->raw(', ');
|
167
|
+
}
|
168
|
+
|
169
|
+
public function enterFilter(Filter $node)
|
170
|
+
{
|
171
|
+
$filter = $this->env->getFilter($node->getFilter());
|
172
|
+
|
173
|
+
if (!$filter->isOptimizable($this, $node, $this->env->getOptions())) {
|
174
|
+
$this->pushEchoMode(false);
|
175
|
+
$this->write('<?php echo MtHaml\Runtime::filter('.$this->env->getOption('mthaml_variable').', '.var_export($node->getFilter(), true).', get_defined_vars(),');
|
176
|
+
$this->indent();
|
177
|
+
|
178
|
+
$first = true;
|
179
|
+
foreach ($node->getChilds() as $statement) {
|
180
|
+
if ($first) {
|
181
|
+
$first = false;
|
182
|
+
} else {
|
183
|
+
$this->raw(" .\n");
|
184
|
+
}
|
185
|
+
|
186
|
+
$this->writeIndentation();
|
187
|
+
$statement->getContent()->accept($this);
|
188
|
+
$this->raw('. "\n"');
|
189
|
+
}
|
190
|
+
$this->raw("\n");
|
191
|
+
|
192
|
+
return false;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
public function leaveFilter(Filter $node)
|
197
|
+
{
|
198
|
+
$filter = $this->env->getFilter($node->getFilter());
|
199
|
+
|
200
|
+
if (!$filter->isOptimizable($this, $node, $this->env->getOptions())) {
|
201
|
+
$this->undent();
|
202
|
+
$this->write(') ?>');
|
203
|
+
$this->popEchoMode();
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
protected function writeDebugInfos($lineno)
|
208
|
+
{
|
209
|
+
}
|
210
|
+
|
211
|
+
protected function renderDynamicAttributes(Tag $tag)
|
212
|
+
{
|
213
|
+
$n = 0;
|
214
|
+
|
215
|
+
$this->raw(' <?php echo MtHaml\Runtime::renderAttributes(array(');
|
216
|
+
|
217
|
+
$this->setEchoMode(false);
|
218
|
+
|
219
|
+
foreach ($tag->getAttributes() as $attr) {
|
220
|
+
|
221
|
+
if (0 !== $n) {
|
222
|
+
$this->raw(', ');
|
223
|
+
}
|
224
|
+
|
225
|
+
if ($attr instanceof TagAttributeInterpolation) {
|
226
|
+
$this->raw('MtHaml\Runtime\AttributeInterpolation::create(');
|
227
|
+
$attr->getValue()->accept($this);
|
228
|
+
$this->raw(')');
|
229
|
+
} elseif ($attr instanceof TagAttributeList) {
|
230
|
+
$this->raw('MtHaml\Runtime\AttributeList::create(');
|
231
|
+
$attr->getValue()->accept($this);
|
232
|
+
$this->raw(')');
|
233
|
+
} else {
|
234
|
+
$this->raw('array(');
|
235
|
+
$attr->getName()->accept($this);
|
236
|
+
$this->raw(', ');
|
237
|
+
if ($attr->getValue()) {
|
238
|
+
$attr->getValue()->accept($this);
|
239
|
+
} else {
|
240
|
+
$this->raw('TRUE');
|
241
|
+
}
|
242
|
+
$this->raw(')');
|
243
|
+
}
|
244
|
+
|
245
|
+
++$n;
|
246
|
+
}
|
247
|
+
|
248
|
+
$this->raw(')');
|
249
|
+
|
250
|
+
$this->setEchoMode(true);
|
251
|
+
|
252
|
+
$this->raw(', ');
|
253
|
+
$this->raw($this->stringLiteral($this->env->getOption('format')));
|
254
|
+
$this->raw(', ');
|
255
|
+
$this->raw($this->stringLiteral($this->charset));
|
256
|
+
$this->raw( ($this->env->getOption('enable_escaper') && $this->env->getOption('escape_attrs'))?
|
257
|
+
'' : ', false');
|
258
|
+
|
259
|
+
$this->raw('); ?>');
|
260
|
+
}
|
261
|
+
|
262
|
+
public function trimInlineComments($code)
|
263
|
+
{
|
264
|
+
// Removes inlines comments ('//' and '#'), while ignoring '//' and '#'
|
265
|
+
// embedded in quoted strings.
|
266
|
+
|
267
|
+
$re = "!
|
268
|
+
(?P<code>
|
269
|
+
(?P<expr>(?:
|
270
|
+
# anything except \", ', `
|
271
|
+
[^\"'`]
|
272
|
+
|
273
|
+
# double quoted string
|
274
|
+
| \"(?: [^\"\\\\]+ | \\\\. )*\"
|
275
|
+
|
276
|
+
# single quoted string
|
277
|
+
| '(?: [^'\\\\]+ | \\\\. )*'
|
278
|
+
|
279
|
+
# backticks string
|
280
|
+
| `(?: [^`\\\\]+ | \\\\. )*`
|
281
|
+
)+?)
|
282
|
+
)
|
283
|
+
(?P<comment>\s*(?://|\#).*)?
|
284
|
+
$!xA";
|
285
|
+
|
286
|
+
return preg_replace($re, '$1', $code);
|
287
|
+
}
|
288
|
+
}
|
@@ -0,0 +1,265 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
namespace MtHaml\NodeVisitor;
|
4
|
+
|
5
|
+
use MtHaml\Node\Root;
|
6
|
+
use MtHaml\Node\Tag;
|
7
|
+
use MtHaml\Node\TagAttribute;
|
8
|
+
use MtHaml\Node\Statement;
|
9
|
+
use MtHaml\Node\Text;
|
10
|
+
use MtHaml\Node\Insert;
|
11
|
+
use MtHaml\Node\Run;
|
12
|
+
use MtHaml\Node\InterpolatedString;
|
13
|
+
use MtHaml\Node\Comment;
|
14
|
+
use MtHaml\Node\Doctype;
|
15
|
+
use MtHaml\Node\Filter;
|
16
|
+
use MtHaml\Node\ObjectRefClass;
|
17
|
+
use MtHaml\Node\ObjectRefId;
|
18
|
+
|
19
|
+
class Printer extends NodeVisitorAbstract
|
20
|
+
{
|
21
|
+
protected $indent;
|
22
|
+
protected $output = '';
|
23
|
+
|
24
|
+
public function getOutput()
|
25
|
+
{
|
26
|
+
return $this->output;
|
27
|
+
}
|
28
|
+
|
29
|
+
protected function indent()
|
30
|
+
{
|
31
|
+
$this->indent += 1;
|
32
|
+
|
33
|
+
return $this;
|
34
|
+
}
|
35
|
+
|
36
|
+
protected function undent()
|
37
|
+
{
|
38
|
+
$this->indent -= 1;
|
39
|
+
|
40
|
+
return $this;
|
41
|
+
}
|
42
|
+
|
43
|
+
protected function write($string, $indent = true, $break = true)
|
44
|
+
{
|
45
|
+
if ($indent) {
|
46
|
+
$this->writeIndentation();
|
47
|
+
}
|
48
|
+
$this->raw($string);
|
49
|
+
if ($break) {
|
50
|
+
$this->output .= "\n";
|
51
|
+
}
|
52
|
+
|
53
|
+
return $this;
|
54
|
+
}
|
55
|
+
|
56
|
+
protected function raw($string)
|
57
|
+
{
|
58
|
+
$this->output .= $string;
|
59
|
+
|
60
|
+
return $this;
|
61
|
+
}
|
62
|
+
|
63
|
+
protected function writeIndentation()
|
64
|
+
{
|
65
|
+
$this->output .= str_repeat(' ', $this->indent * 2);
|
66
|
+
|
67
|
+
return $this;
|
68
|
+
}
|
69
|
+
|
70
|
+
public function enterRoot(Root $node)
|
71
|
+
{
|
72
|
+
$this->write('root(')->indent();
|
73
|
+
}
|
74
|
+
public function leaveRoot(Root $node)
|
75
|
+
{
|
76
|
+
$this->undent()->write(')');
|
77
|
+
}
|
78
|
+
|
79
|
+
public function enterTag(Tag $node)
|
80
|
+
{
|
81
|
+
$name = $node->getTagName();
|
82
|
+
$flags = $node->getFlags();
|
83
|
+
if ($flags & Tag::FLAG_REMOVE_INNER_WHITESPACES) {
|
84
|
+
$name .= '<';
|
85
|
+
}
|
86
|
+
if ($flags & Tag::FLAG_REMOVE_OUTER_WHITESPACES) {
|
87
|
+
$name .= '>';
|
88
|
+
}
|
89
|
+
if ($flags & Tag::FLAG_SELF_CLOSE) {
|
90
|
+
$name .= '/';
|
91
|
+
}
|
92
|
+
|
93
|
+
$this->write('tag(' . $name, true, false)
|
94
|
+
->indent();
|
95
|
+
|
96
|
+
if ($node->hasContent()) {
|
97
|
+
$this->raw(' ');
|
98
|
+
$node->getContent()->accept($this);
|
99
|
+
}
|
100
|
+
|
101
|
+
if ($node->hasAttributes() || $node->hasChilds()) {
|
102
|
+
$this->raw("\n");
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
public function enterTagContent(Tag $node)
|
107
|
+
{
|
108
|
+
return false;
|
109
|
+
}
|
110
|
+
|
111
|
+
public function leaveTag(Tag $node)
|
112
|
+
{
|
113
|
+
$this->undent()->write(')', $node->hasAttributes()||$node->hasChilds());
|
114
|
+
}
|
115
|
+
|
116
|
+
public function enterTagAttribute(TagAttribute $node)
|
117
|
+
{
|
118
|
+
$this->write('attr(', true, false);
|
119
|
+
}
|
120
|
+
|
121
|
+
public function leaveTagAttribute(TagAttribute $node)
|
122
|
+
{
|
123
|
+
$this->write(')', false, true);
|
124
|
+
}
|
125
|
+
|
126
|
+
public function enterStatement(Statement $node)
|
127
|
+
{
|
128
|
+
$this->write('', true, false);
|
129
|
+
}
|
130
|
+
|
131
|
+
public function leaveStatement(Statement $node)
|
132
|
+
{
|
133
|
+
$this->write('', false, true);
|
134
|
+
}
|
135
|
+
|
136
|
+
public function enterText(Text $node)
|
137
|
+
{
|
138
|
+
$content = $node->getContent();
|
139
|
+
|
140
|
+
$escaping = $node->getEscaping();
|
141
|
+
if (true === $escaping->isEnabled()) {
|
142
|
+
$flag = '&';
|
143
|
+
if ($node->getEscaping()->isOnce()) {
|
144
|
+
$flag .= '!';
|
145
|
+
}
|
146
|
+
$content = $flag . $content;
|
147
|
+
} elseif (false === $escaping->isEnabled()) {
|
148
|
+
$content = '!' . $content;
|
149
|
+
}
|
150
|
+
|
151
|
+
$this->raw('text('.$content.')');
|
152
|
+
}
|
153
|
+
|
154
|
+
public function enterInsert(Insert $node)
|
155
|
+
{
|
156
|
+
$content = $node->getContent();
|
157
|
+
|
158
|
+
$escaping = $node->getEscaping();
|
159
|
+
if (true === $escaping->isEnabled()) {
|
160
|
+
$flag = '&';
|
161
|
+
if ($node->getEscaping()->isOnce()) {
|
162
|
+
$flag .= '!';
|
163
|
+
}
|
164
|
+
$content = $flag . $content;
|
165
|
+
} elseif (false === $escaping->isEnabled()) {
|
166
|
+
$content = '!' . $content;
|
167
|
+
}
|
168
|
+
|
169
|
+
$this->raw('insert('.$content.')');
|
170
|
+
}
|
171
|
+
|
172
|
+
public function enterRun(Run $node)
|
173
|
+
{
|
174
|
+
$this->write('run(' . $node->getContent(), true, $node->hasChilds())
|
175
|
+
->indent();
|
176
|
+
}
|
177
|
+
|
178
|
+
public function enterRunMidblock(Run $node)
|
179
|
+
{
|
180
|
+
if ($node->hasMidblock()) {
|
181
|
+
$this->write('midblock(')->indent();
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
public function leaveRunMidblock(Run $node)
|
186
|
+
{
|
187
|
+
if ($node->hasMidblock()) {
|
188
|
+
$this->undent()->write(')');
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
public function leaveRun(Run $node)
|
193
|
+
{
|
194
|
+
$this->undent()->write(')', $node->hasChilds());
|
195
|
+
}
|
196
|
+
|
197
|
+
public function enterInterpolatedString(InterpolatedString $node)
|
198
|
+
{
|
199
|
+
$this->raw('interpolated(');
|
200
|
+
}
|
201
|
+
|
202
|
+
public function leaveInterpolatedString(InterpolatedString $node)
|
203
|
+
{
|
204
|
+
$this->raw(')');
|
205
|
+
}
|
206
|
+
|
207
|
+
public function enterComment(Comment $node)
|
208
|
+
{
|
209
|
+
$this->write('comment(' . $node->getCondition(), true, false)->indent();
|
210
|
+
}
|
211
|
+
|
212
|
+
public function enterCommentChilds(Comment $node)
|
213
|
+
{
|
214
|
+
if ($node->hasChilds()) {
|
215
|
+
$this->raw("\n");
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
public function leaveComment(Comment $node)
|
220
|
+
{
|
221
|
+
$this->undent()->write(')', $node->hasChilds());
|
222
|
+
}
|
223
|
+
|
224
|
+
public function enterDoctype(Doctype $doctype)
|
225
|
+
{
|
226
|
+
$str = 'doctype(';
|
227
|
+
$str .= $doctype->getDoctypeId() ?: 'default';
|
228
|
+
if ($options = $doctype->getOptions()) {
|
229
|
+
$str .= ', ' . $options;
|
230
|
+
}
|
231
|
+
$str .= ')';
|
232
|
+
$this->write($str);
|
233
|
+
}
|
234
|
+
|
235
|
+
public function enterFilter(Filter $node)
|
236
|
+
{
|
237
|
+
$this->write('filter(' . $node->getFilter())->indent();
|
238
|
+
}
|
239
|
+
|
240
|
+
public function leaveFilter(Filter $node)
|
241
|
+
{
|
242
|
+
$this->undent()->write(')');
|
243
|
+
}
|
244
|
+
|
245
|
+
public function enterObjectRefClass(ObjectRefClass $node)
|
246
|
+
{
|
247
|
+
$this->raw('object_ref_class(');
|
248
|
+
}
|
249
|
+
|
250
|
+
public function leaveObjectRefClass(ObjectRefClass $node)
|
251
|
+
{
|
252
|
+
$this->raw(')');
|
253
|
+
}
|
254
|
+
|
255
|
+
public function enterObjectRefId(ObjectRefId $node)
|
256
|
+
{
|
257
|
+
$this->raw('object_ref_id(');
|
258
|
+
}
|
259
|
+
|
260
|
+
public function leaveObjectRefId(ObjectRefId $node)
|
261
|
+
{
|
262
|
+
$this->raw(')');
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|