machy8/macdom

最佳、高度可定制的HTML预处理器,拥有许多令人惊叹的功能。

v3.0.0 2017-10-08 10:47 UTC

This package is auto-updated.

Last update: 2024-09-24 07:27:17 UTC


README

Build Status Coverage Status Packagist License Join the chat at https://gitter.im/Machy8/Macdom

  • 更多信息请参阅 WIKI (始终更新到最新稳定版本)
  • 在CODEPEN上尝试 (JavaScript版本总是落后于PHP版本,因此可能包含已在PHP版本中修复的bug和错误)

示例

Macdom

!5
html
    head
        utf-8
        viewport
        favicon includes/favicon.ico
        title Macdom example
    body
        h1 #title .titles .main-title Hello world
        nav
            @ a $http://www.[@].com $blank Link on -
            [google] .first-link Google
            [yahoo] Yahoo
            [github] Github	
        div #wrapper Some text <b>here</b>.
        https://www.code.jquery.com/jquery-1.12.0.min.js async

结果

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta content="width=device-width" name="viewport">
		<link rel="shortcut icon" href="includes/favicon.ico">
		<title>Macdom example</title>
	</head>
	<body>
		<h1 id="title" class="titles main-title">Hello world</h1>
		<nav>
			<a target="blank" href="http://www.google.com" class="first-link">Link on - Google</a>
			<a target="blank" href="http://www.yahoo.com">Link on - Yahoo</a>
			<a target="blank" href="http://www.github.com">Link on - Github</a>
		</nav>
		<div id="wrapper">
			Some text <b>here</b>.
		</div>
		<script async="" type="text/javascript" src="https://www.code.jquery.com/jquery-1.12.0.min.js"></script>
	</body>
</html>

需求

  • PHP 7.0+
  • 如果您使用Nette框架 - v2.3+

安装

1 - 使用composer下载Macdom

 composer require machy8/macdom

2 - 使用方法

典型

$macdom = new Macdom\Engine;
$compiled = $macdom->compile($content);

Nette框架

use Macdom\Bridges\Latte\FileLoader;
use Macdom\Engine;

/**
 * @var Engine
 */
private $macdom;

/**
 * @var FileLoader
 */
private $fileLoader;


public function __construct(Engine $macdom, FileLoader $fileLoader) {
	$this->macdom = $macdom;
	$this->fileLoader = $fileLoader;
}


protected function createTemplate()
{
	$template = parent::createTemplate();
	$this->fileLoader->setMacdom($this->macdom);
	$template->getLatte()->setLoader($this->fileLoader);
	return $template;
}

并添加一个包含以下内容的配置neon文件(或者尝试Composer同步器。它将为您自动完成)。

extensions:
    macdom: Macdom\Bridges\Nette\MacdomExtension
  
macdom:
    debugger: TRUE