/** * Compile the view at the given path. * * @param string $path * @return void */ public function compile($path) { $contents = $this->environment->compileString($this->files->get($path), $path); if (!is_null($this->cachePath)) { $this->files->put($this->getCompiledPath($path), $contents); } }
/** * Compile the view at the given path. * * @param string $path * @return void */ public function compile($path) { if (is_null($this->cachePath)) { return; } $contents = $this->mthaml->compileString($this->files->get($path), $path); $this->files->put($this->getCompiledPath($path), $contents); }
/** * Compile the view at the given path. * * @param string $path * @return void */ public function compile($path) { $this->footer = array(); // First compile the Haml $contents = $this->mthaml->compileString($this->files->get($path), $path); // Then the Blade syntax $contents = $this->compileString($contents); if (!is_null($this->cachePath)) { $this->files->put($this->getCompiledPath($path), $contents); } }
/** * @dataProvider getTestData */ public function testSpec($name, $test) { if (!getenv('HAML_SPEC_TEST_JSON_PATH')) { $this->markTestSkipped('HAML_SPEC_TEST_JSON_PATH not set'); } $config = array('enable_escaper' => false); if (isset($test['config'])) { foreach ($test['config'] as $key => $value) { switch ($key) { case 'format': $config['format'] = $value; break; default: } } } $locals = array(); if (isset($test['locals'])) { $locals = $test['locals']; } $env = new Environment('twig', $config); $str = $env->compileString($test['haml'], "{$name}.haml"); $loader = new \Twig_Loader_Array(array('test.twig' => $str)); $twig = new \Twig_Environment($loader); $twig->addExtension(new Extension()); $html = $twig->render('test.twig', $locals); $expect = $test['html']; $this->assertSame($expect, rtrim($html)); }
public function compileString($string, $moreOption = array(), $returnRoot = false) { if (!empty($moreOption['reduce_runtime'])) { $this->noReduceRuntime = false; } if (!empty($moreOption['reduce_runtime_array_tolerant'])) { $this->reduceRuntimeArrayTolerant = true; } if (empty($moreOption['filename'])) { return parent::compileString($string, '[unnamed]'); } $prepareWork = false; if (is_string($moreOption)) { $moreOption = array('filename' => $moreOption); } $this->currentMoreEnv = new MoreEnv($moreOption, $this); $filename = $moreOption['filename']; if ($this->currentMoreEnv['prepare']) { list($string, $filename, $prepareWork) = $this->prepare($string, $filename); } $string = $this->parseInlineSnipCaller($string); $string = $this->parseInlinePlaceholder($string, $this->currentMoreEnv['globalDefaultPlaceholderValue']); if ($returnRoot) { // copied from parent::compileString // run until PhpRenderer $target = $this->getTarget(); $node = $target->parse($this, $string, $filename); foreach ($this->getVisitors() as $visitor) { $node->accept($visitor); } $compiled = $node; } else { $compiled = parent::compileString($string, $filename); } if ($prepareWork && !$this->currentMoreEnv['debug']) { unlink($filename); } if (($parent = $this->currentMoreEnv['parentenv']) instanceof MoreEnv) { $this->currentMoreEnv = $parent; } return $compiled; }
/** * Render * @param View $view * @param string $path * @param array $params * @return boolean */ public function render($view, $path, array $params = []) { $this->fire('HamlEngineRender', [$view, $path, $params]); $php = $this->getPhpCacheFolder() . DIRECTORY_SEPARATOR . $path . $this->suffix_php; $haml = $this->getFolder() . DIRECTORY_SEPARATOR . $path . $this->suffix_haml; $yml = $this->getFolder() . DIRECTORY_SEPARATOR . $path . $this->suffix_yml; if (file_exists($yml)) { $meta = Yaml::parse(file_get_contents($yml)); } else { $meta = []; } $path_php = false; $engine = $this->php_engine; if (file_exists($haml)) { if (!file_exists($php) || filemtime($php) != filemtime($haml)) { $this->log()->debug("render haml file `{$haml}`"); $haml_code = file_get_contents($haml); $php_code = $this->haml_engine->compileString($haml_code, $haml); $this->filesystem()->checkPathDir(dirname($php)); file_put_contents($php, $php_code); touch($haml); } $path_php = $path; $engine->setFolder($this->getPhpCacheFolder())->setSuffixPhp($this->suffix_php); } else { $file = $this->getFolder() . DIRECTORY_SEPARATOR . $path . $this->ext_php; if (file_exists($file)) { $path_php = $path; $engine->setFolder($this->getFolder())->setSuffixPhp($this->ext_php); } } if ($path_php) { $this->renderStyle($view, $path); $this->renderScript($view, $path); $this->php_engine->setMeta($meta)->render($view, $path_php, $params); } else { return false; } return true; }
protected function generateResultHtml($extension) { HamlLoader::register(); $haml = new HamlGenerator('php', array('enable_escaper' => false)); $template = 'Resources/views/result.haml'; $targetFile = 'tmp/result.php'; $compiled = $haml->compileString(file_get_contents($template), $template); file_put_contents($targetFile, $compiled); // $results = $this->convertResultCommentsToHtml( // Logger::getResultArray($extension) // ); // $results = $this->convertResultCommentsToHtml(Logger::getIssueResults($extension)); $passedChecks = Logger::getPassedChecksOfIssueHandler($extension); $failedChecks = Logger::getFailedChecksOfIssueHandler($extension); // $failedChecks = $results['failedChecks']; // $score = $results['score']; ob_start(); include $targetFile; $result = ob_get_contents(); ob_end_clean(); $targetHtml = 'tmp/result.html'; file_put_contents($targetHtml, $result); }
<?php use MtHaml\Autoloader; use MtHaml\Environment; require_once __DIR__ . '/Autoloader.php'; Autoloader::register(); $haml = new MtHaml\Environment('php', array('enable_escaper' => false, 'escape_html' => false, 'escape_attrs' => false)); echo $haml->getOption("escape_html"); $remove_methods = true; foreach (glob(__DIR__ . "/../../app/views/*.haml") as $file) { $filename = basename($file); if ($filename !== "") { $compiled = $haml->compileString(file_get_contents($file), $filename); $filename_fixed = str_replace("haml", "php", $filename); if ($remove_methods) { preg_match_all('/\\<\\?php echo MtHaml\\\\Runtime::renderAttributes(.*)\\?\\>/', $compiled, $to_render, PREG_PATTERN_ORDER); foreach ($to_render[0] as $value) { $initial_value = $value; $remove_open_and_close = substr(substr($value, 6), 0, -3); preg_match_all('/MtHaml\\\\Runtime\\\\AttributeList::create\\(\\(.*\\"\\)\\)/', $remove_open_and_close, $replace_with_array); foreach ($replace_with_array as $attribute_list_method) { if (!empty($attribute_list_method)) { $item = $attribute_list_method[0]; $attr = preg_replace('/\\"\\)\\)/', "", preg_replace('/MtHaml\\\\Runtime\\\\AttributeList::create\\(\\(/', "", $item)); $remove_quotes = str_replace('"', "", $attr); $separate_attributes = explode(":", $remove_quotes); $attributes = array(trim($separate_attributes[0]), trim($separate_attributes[1])); $value = str_replace($attribute_list_method, $attributes, $value); } } $to_eval = substr(substr($value, 11), 0, -3);