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,147 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
namespace MtHaml\Parser;
|
4
|
+
|
5
|
+
class Buffer
|
6
|
+
{
|
7
|
+
protected $lines;
|
8
|
+
protected $line;
|
9
|
+
|
10
|
+
protected $lineno;
|
11
|
+
protected $column;
|
12
|
+
|
13
|
+
public function __construct($string, $lineno = 1)
|
14
|
+
{
|
15
|
+
$this->lines = preg_split('~\r\n|\n|\r~', $string);
|
16
|
+
$this->lineno = $lineno - 1;
|
17
|
+
}
|
18
|
+
|
19
|
+
public function nextLine()
|
20
|
+
{
|
21
|
+
$this->line = array_shift($this->lines);
|
22
|
+
if (null !== $this->line) {
|
23
|
+
++$this->lineno;
|
24
|
+
$this->column = 1;
|
25
|
+
|
26
|
+
return true;
|
27
|
+
}
|
28
|
+
|
29
|
+
return false;
|
30
|
+
}
|
31
|
+
|
32
|
+
public function peekLine()
|
33
|
+
{
|
34
|
+
if (isset($this->lines[0])) {
|
35
|
+
return $this->lines[0];
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
public function hasNextLine()
|
40
|
+
{
|
41
|
+
return isset($this->lines[0]);
|
42
|
+
}
|
43
|
+
|
44
|
+
public function mergeNextLine()
|
45
|
+
{
|
46
|
+
if (!isset($this->lines[0])) {
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
++$this->lineno;
|
50
|
+
$this->line .= "\n" . array_shift($this->lines);
|
51
|
+
}
|
52
|
+
|
53
|
+
public function replaceLine($string)
|
54
|
+
{
|
55
|
+
$this->line = $string;
|
56
|
+
}
|
57
|
+
|
58
|
+
public function isEol()
|
59
|
+
{
|
60
|
+
return $this->line === '';
|
61
|
+
}
|
62
|
+
|
63
|
+
public function peekChar()
|
64
|
+
{
|
65
|
+
if (isset($this->line[0])) {
|
66
|
+
return $this->line[0];
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
public function eatChar()
|
71
|
+
{
|
72
|
+
if (isset($this->line[0])) {
|
73
|
+
$char = $this->line[0];
|
74
|
+
$this->line = (string) substr($this->line, 1);
|
75
|
+
++$this->column;
|
76
|
+
|
77
|
+
return $char;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
public function eatChars($n)
|
82
|
+
{
|
83
|
+
$chars = (string) substr($this->line, 0, $n);
|
84
|
+
$this->line = (string) substr($this->line, $n);
|
85
|
+
$this->column += strlen($chars);
|
86
|
+
|
87
|
+
return $chars;
|
88
|
+
}
|
89
|
+
|
90
|
+
public function match($pattern, &$match = null, $eat = true)
|
91
|
+
{
|
92
|
+
if ($count = preg_match($pattern, $this->line, $match, PREG_OFFSET_CAPTURE)) {
|
93
|
+
$pos = array();
|
94
|
+
|
95
|
+
foreach ($match as $key => &$capture) {
|
96
|
+
$pos[$key] = array(
|
97
|
+
'lineno' => $this->lineno,
|
98
|
+
'column' => $capture[1],
|
99
|
+
);
|
100
|
+
$capture = $capture[0];
|
101
|
+
}
|
102
|
+
unset($capture); // ref
|
103
|
+
|
104
|
+
$match['pos'] = $pos;
|
105
|
+
|
106
|
+
if ($eat) {
|
107
|
+
$this->eat($match[0]);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
return $count > 0;
|
112
|
+
}
|
113
|
+
|
114
|
+
public function eat($string)
|
115
|
+
{
|
116
|
+
$this->line = (string) substr($this->line, strlen($string));
|
117
|
+
$this->column += strlen($string);
|
118
|
+
}
|
119
|
+
|
120
|
+
public function skipWs()
|
121
|
+
{
|
122
|
+
$this->match('~[ \t]+~A');
|
123
|
+
}
|
124
|
+
|
125
|
+
public function getColumn()
|
126
|
+
{
|
127
|
+
return $this->column;
|
128
|
+
}
|
129
|
+
|
130
|
+
public function getLineno()
|
131
|
+
{
|
132
|
+
return $this->lineno;
|
133
|
+
}
|
134
|
+
|
135
|
+
public function getPosition()
|
136
|
+
{
|
137
|
+
return array(
|
138
|
+
'lineno' => $this->lineno,
|
139
|
+
'column' => $this->column,
|
140
|
+
);
|
141
|
+
}
|
142
|
+
|
143
|
+
public function getLine()
|
144
|
+
{
|
145
|
+
return $this->line;
|
146
|
+
}
|
147
|
+
}
|
@@ -0,0 +1,218 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
namespace MtHaml;
|
4
|
+
|
5
|
+
use MtHaml\Runtime\AttributeInterpolation;
|
6
|
+
use MtHaml\Runtime\AttributeList;
|
7
|
+
|
8
|
+
class Runtime
|
9
|
+
{
|
10
|
+
/**
|
11
|
+
* Renders a list of attributes
|
12
|
+
*
|
13
|
+
* Handles the following special cases:
|
14
|
+
* - attribute named 'data' with iterable value it rendered as multiple
|
15
|
+
* html5 data- attributes
|
16
|
+
* - attribute with boolean value is rendered as boolean attribute. In html5
|
17
|
+
* format, only the attribute name is rendered, like 'checked'. In
|
18
|
+
* other formats, it is rendered with the attribute name as value, like
|
19
|
+
* 'checked="checked"'.
|
20
|
+
* - attribute with null or false value isn't rendered
|
21
|
+
* - multiple id attributes and id attributes with iterable values are
|
22
|
+
* rendered concatenated with underscores
|
23
|
+
* - multiple class attributes and class attributes with iterable values are
|
24
|
+
* rendered concatenated with spaces
|
25
|
+
*
|
26
|
+
* @param array $list A list of attributes (items are array($name, $value))
|
27
|
+
* @param string $format Output format (e.g. html5)
|
28
|
+
* @param string $charset Output charset
|
29
|
+
*/
|
30
|
+
public static function renderAttributes($list, $format, $charset, $escape = true)
|
31
|
+
{
|
32
|
+
$attributes = array();
|
33
|
+
|
34
|
+
self::mergeAttributes($attributes, $list, $format);
|
35
|
+
|
36
|
+
$result = null;
|
37
|
+
|
38
|
+
foreach ($attributes as $name => $value) {
|
39
|
+
if (null !== $result) {
|
40
|
+
$result .= ' ';
|
41
|
+
}
|
42
|
+
if ($value instanceof AttributeInterpolation) {
|
43
|
+
$result .= $value->value;
|
44
|
+
} elseif (true === $value) {
|
45
|
+
$result .= $escape ?
|
46
|
+
htmlspecialchars($name, ENT_QUOTES, $charset) : $name;
|
47
|
+
} else {
|
48
|
+
$result .= ($escape ?
|
49
|
+
htmlspecialchars($name, ENT_QUOTES, $charset) : $name)
|
50
|
+
.'="'
|
51
|
+
. ($escape ?
|
52
|
+
htmlspecialchars($value, ENT_QUOTES, $charset) : $value)
|
53
|
+
.'"';
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
return $result;
|
58
|
+
}
|
59
|
+
|
60
|
+
private static function mergeAttributes(&$dest, $list, $format)
|
61
|
+
{
|
62
|
+
foreach ($list as $item) {
|
63
|
+
|
64
|
+
if ($item instanceof AttributeInterpolation) {
|
65
|
+
$dest[] = $item;
|
66
|
+
continue;
|
67
|
+
} elseif ($item instanceof AttributeList) {
|
68
|
+
$pairs = array();
|
69
|
+
foreach ($item->attributes as $name => $value) {
|
70
|
+
$pairs[] = array($name, $value);
|
71
|
+
}
|
72
|
+
self::mergeAttributes($dest, $pairs, $format);
|
73
|
+
continue;
|
74
|
+
}
|
75
|
+
|
76
|
+
list ($name, $value) = $item;
|
77
|
+
|
78
|
+
if ('data' === $name) {
|
79
|
+
self::renderDataAttributes($dest, $value);
|
80
|
+
} elseif ('id' === $name) {
|
81
|
+
$value = self::renderJoinedValue($value, '_');
|
82
|
+
if (null !== $value) {
|
83
|
+
if (isset($dest['id'])) {
|
84
|
+
$dest['id'] .= '_' . $value;
|
85
|
+
} else {
|
86
|
+
$dest['id'] = $value;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
} elseif ('class' === $name) {
|
90
|
+
$value = self::renderJoinedValue($value, ' ');
|
91
|
+
if (null !== $value) {
|
92
|
+
if (isset($dest['class'])) {
|
93
|
+
$dest['class'] .= ' ' . $value;
|
94
|
+
} else {
|
95
|
+
$dest['class'] = $value;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
} elseif (true === $value) {
|
99
|
+
if ('html5' === $format) {
|
100
|
+
$dest[$name] = true;
|
101
|
+
} else {
|
102
|
+
$dest[$name] = $name;
|
103
|
+
}
|
104
|
+
} elseif (false === $value || null === $value) {
|
105
|
+
// do not output
|
106
|
+
} else {
|
107
|
+
if (isset($dest[$name])) {
|
108
|
+
// so that next assignment puts the attribute
|
109
|
+
// at the end for the array
|
110
|
+
unset($dest[$name]);
|
111
|
+
}
|
112
|
+
$dest[$name] = $value;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
private static function renderDataAttributes(&$dest, $value, $prefix = 'data')
|
118
|
+
{
|
119
|
+
if (\is_array($value) || $value instanceof \Traversable) {
|
120
|
+
foreach ($value as $subname => $subvalue) {
|
121
|
+
self::renderDataAttributes($dest, $subvalue, $prefix.'-'.$subname);
|
122
|
+
}
|
123
|
+
} else {
|
124
|
+
if (!isset($dest[$prefix])) {
|
125
|
+
$dest[$prefix] = $value;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
private static function renderJoinedValue($values, $separator)
|
131
|
+
{
|
132
|
+
$result = null;
|
133
|
+
|
134
|
+
if (\is_array($values) || $values instanceof \Traversable) {
|
135
|
+
foreach ($values as $value) {
|
136
|
+
if (\is_array($value) || $value instanceof \Traversable) {
|
137
|
+
$value = self::renderJoinedValue($value, $separator);
|
138
|
+
}
|
139
|
+
if (null !== $value && false !== $value) {
|
140
|
+
if (null !== $result) {
|
141
|
+
$result .= $separator;
|
142
|
+
}
|
143
|
+
$result .= $value;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
} else {
|
147
|
+
if (null !== $values && false !== $values) {
|
148
|
+
$result = $values;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
return $result;
|
153
|
+
}
|
154
|
+
|
155
|
+
public static function renderObjectRefClass($object, $prefix = null)
|
156
|
+
{
|
157
|
+
if (!$object) {
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
|
161
|
+
$class = self::getObjectRefClassString($object);
|
162
|
+
|
163
|
+
if (false !== $prefix && null !== $prefix) {
|
164
|
+
$class = $prefix . '_' . $class;
|
165
|
+
}
|
166
|
+
|
167
|
+
return $class;
|
168
|
+
}
|
169
|
+
|
170
|
+
public static function renderObjectRefId($object, $prefix = null)
|
171
|
+
{
|
172
|
+
if (!$object) {
|
173
|
+
return;
|
174
|
+
}
|
175
|
+
|
176
|
+
$id = null;
|
177
|
+
|
178
|
+
if (\is_callable(array($object, 'getId'))) {
|
179
|
+
$id = $object->getId();
|
180
|
+
} elseif (\is_callable(array($object, 'id'))) {
|
181
|
+
$id = $object->id();
|
182
|
+
}
|
183
|
+
|
184
|
+
if (false === $id || null === $id) {
|
185
|
+
$id = 'new';
|
186
|
+
}
|
187
|
+
|
188
|
+
$id = self::getObjectRefClassString($object) . '_' . $id;
|
189
|
+
|
190
|
+
if (false !== $prefix && null !== $prefix) {
|
191
|
+
$id = $prefix . '_' . $id;
|
192
|
+
}
|
193
|
+
|
194
|
+
return $id;
|
195
|
+
}
|
196
|
+
|
197
|
+
public static function getObjectRefClassString($object)
|
198
|
+
{
|
199
|
+
$class = self::getObjectRefName($object);
|
200
|
+
if (false !== $pos = \strrpos($class, '\\')) {
|
201
|
+
$class = \substr($class, $pos+1);
|
202
|
+
}
|
203
|
+
|
204
|
+
return \strtolower(\preg_replace('#(?<=[a-z])[A-Z]+#', '_$0', $class));
|
205
|
+
}
|
206
|
+
|
207
|
+
public static function getObjectRefName($object)
|
208
|
+
{
|
209
|
+
return \is_callable(array($object, 'hamlObjectRef'))
|
210
|
+
? $object->hamlObjectRef()
|
211
|
+
: \get_class($object);
|
212
|
+
}
|
213
|
+
|
214
|
+
public static function filter(Environment $mthaml, $filter, array $context, $content)
|
215
|
+
{
|
216
|
+
return $mthaml->getFilter($filter)->filter($content, $context, $mthaml->getOptions());
|
217
|
+
}
|
218
|
+
}
|
@@ -0,0 +1,157 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
namespace MtHaml\Support\Php;
|
4
|
+
|
5
|
+
use MtHaml\Environment;
|
6
|
+
use MtHaml\Exception;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Executor is a simple helper that can compile haml files, cache them, and execute them
|
10
|
+
*/
|
11
|
+
class Executor
|
12
|
+
{
|
13
|
+
private $environment;
|
14
|
+
|
15
|
+
private $options = array(
|
16
|
+
// Cache directory to store compiled templates
|
17
|
+
'cache' => null,
|
18
|
+
// Whether to by-pass cache, useful when debugging
|
19
|
+
'debug' => false,
|
20
|
+
);
|
21
|
+
|
22
|
+
public function __construct(Environment $environment, array $options)
|
23
|
+
{
|
24
|
+
$this->environment = $environment;
|
25
|
+
$this->options = $options + $this->options;
|
26
|
+
|
27
|
+
if (!$this->options['cache']) {
|
28
|
+
throw new Exception("A 'cache' option must be defined");
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Executes and displays the template $file, with variables $variables
|
34
|
+
*/
|
35
|
+
public function display($file, array $variables)
|
36
|
+
{
|
37
|
+
$fun = $this->compileFile($file);
|
38
|
+
$fun($variables);
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Executes the template $file with variables $variables, and returns its output
|
43
|
+
*/
|
44
|
+
public function render($file, array $variables)
|
45
|
+
{
|
46
|
+
$level = ob_get_level();
|
47
|
+
ob_start();
|
48
|
+
|
49
|
+
try {
|
50
|
+
$this->display($file, $variables);
|
51
|
+
} catch (\Exception $e) {
|
52
|
+
while (ob_get_level() > $level) {
|
53
|
+
ob_end_clean();
|
54
|
+
}
|
55
|
+
|
56
|
+
throw $e;
|
57
|
+
}
|
58
|
+
|
59
|
+
return ob_get_clean();
|
60
|
+
}
|
61
|
+
|
62
|
+
private function compileFile($file)
|
63
|
+
{
|
64
|
+
if (!file_exists($file)) {
|
65
|
+
throw new Exception(sprintf(
|
66
|
+
"File does not exist: `%s`"
|
67
|
+
, $file
|
68
|
+
));
|
69
|
+
}
|
70
|
+
|
71
|
+
$hash = hash('sha256', $file);
|
72
|
+
$funName = '__MtHamlTemplate_' . $hash;
|
73
|
+
|
74
|
+
if (function_exists($funName)) {
|
75
|
+
return $funName;
|
76
|
+
}
|
77
|
+
|
78
|
+
$cacheFile = $this->options['cache']
|
79
|
+
. '/' . substr($hash, 0, 2) . '/' . substr($hash, 2, 2) . '/'
|
80
|
+
. substr($hash, 4) . '_' . basename($file) . '.php';
|
81
|
+
|
82
|
+
if ($this->options['debug'] || !file_exists($cacheFile) || filemtime($cacheFile) !== filemtime($file)) {
|
83
|
+
|
84
|
+
$hamlCode = file_get_contents($file);
|
85
|
+
|
86
|
+
if (false === $hamlCode) {
|
87
|
+
throw new Exception(sprintf(
|
88
|
+
"Failed reading file: `%s`"
|
89
|
+
, $file
|
90
|
+
));
|
91
|
+
}
|
92
|
+
|
93
|
+
$compiledCode = $this->environment->compileString($hamlCode, $file);
|
94
|
+
$compiledCode = $this->wrapCompiledCode($compiledCode, $funName);
|
95
|
+
|
96
|
+
$this->writeCacheFile($cacheFile, $compiledCode);
|
97
|
+
}
|
98
|
+
|
99
|
+
require_once $cacheFile;
|
100
|
+
|
101
|
+
return $funName;
|
102
|
+
}
|
103
|
+
|
104
|
+
private function wrapCompiledCode($code, $funName)
|
105
|
+
{
|
106
|
+
// The code is wrapped in a function so that it can be parsed
|
107
|
+
// once, and executed multiple times. This is faster than repeatedly
|
108
|
+
// including the same PHP file.
|
109
|
+
return <<<PHP
|
110
|
+
<?php
|
111
|
+
|
112
|
+
function $funName(\$__variables)
|
113
|
+
{
|
114
|
+
extract(\$__variables);
|
115
|
+
?>$code<?php
|
116
|
+
}
|
117
|
+
PHP;
|
118
|
+
}
|
119
|
+
|
120
|
+
private function writeCacheFile($cacheFile, $contents)
|
121
|
+
{
|
122
|
+
$dir = dirname($cacheFile);
|
123
|
+
|
124
|
+
if (!is_dir($dir)) {
|
125
|
+
if (!mkdir($dir, 0777, true)) {
|
126
|
+
throw new Exception(sprintf(
|
127
|
+
"Failed creating cache directory: `%s`"
|
128
|
+
, $dir
|
129
|
+
));
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
if (!is_writeable($dir)) {
|
134
|
+
throw new Exception(sprintf(
|
135
|
+
"Cache directory is not writeable: `%s`"
|
136
|
+
, $dir
|
137
|
+
));
|
138
|
+
}
|
139
|
+
|
140
|
+
$tmpFile = tempnam($dir, basename($cacheFile));
|
141
|
+
|
142
|
+
if (false === file_put_contents($tmpFile, $contents)) {
|
143
|
+
throw new Exception(sprintf(
|
144
|
+
"Failed writing cache file: `%s`"
|
145
|
+
, $tmpFile
|
146
|
+
));
|
147
|
+
}
|
148
|
+
|
149
|
+
if (!rename($tmpFile, $cacheFile)) {
|
150
|
+
@unlink($tmpFile);
|
151
|
+
throw new Exception(sprintf(
|
152
|
+
"Failed writing cache file: `%s`"
|
153
|
+
, $cacheFile
|
154
|
+
));
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|