holantomas/semantic

创建语义化网站的工具

0.4 2017-02-01 20:50 UTC

This package is auto-updated.

Last update: 2024-09-21 19:41:58 UTC


README

Downloads this Month Latest Stable Version

此扩展旨在为Nette框架提供HTML文档API。

安装

Composer包尚未准备就绪

最佳安装方式是使用Composer

$ composer require holantomas/semantic

在neon配置中注册扩展

extensions:
	semantic: holantomas\Semantic\Bridges\Nette\SemanticExtension

您可以根据自己的需要设置自己的IDocument实现。

semantic:
	document: namespace\to\your\document # Or false to disble it

如果您已经有了IDocument的实现,您必须指定文档属性上的@required注解,这将导致当属性为空或NULL时发出警告。您不必关心属性的可见性

use holantomas\Semantic\IDocument;

class MyDocument implements IDocument {

	/**
	 * @var string
	 * @required - this make property required (throws warnings)
	 */
	private $title = '';

}

启用(可选)Tracy面板 - 如果Tracy面板被禁用,则在渲染时,如果@required属性为NULL或空,文档将抛出E_USER_WARNING

tracy:
	bar:
		- holantomas\Semantic\Bridges\Tracy\SemanticPanel

要显示面板中的属性,您必须在每个属性上指定@panel

use holantomas\Semantic\IDocument;

class MyDocument implements IDocument {

	/**
	 * @var string
	 * @required - this make property required (throws warnings)
	 * @panel - this make property show in tracy panel
	 */
	private $title = '';

}

可以通过Checker::$REQUIREMENT_ANNOTATIONSemanticPanel::$RENDER_ANNOTATION自定义注解

使用方法

Document会自动注册为服务并插入到名为document的presenter模板参数中。您不需要在presenter中执行$this->template->document = $this->document;

namespace App;

use Nette\Application\UI\Presenter;
use holantomas\Semantic\IDocument;

class BasePresenter extends Presenter
{
	/** @var IDocument @inject */
	public $document;
	
}

class ExamplePresenter extends BasePresenter
{
	public function actionDefault(){
		$this->document->setTitle('Hello world!');
	}
	
}
<html>
	<head>
		<title>{$document->getTitle()}</title>
		...
	</head>
	...
</html>

当然,您可以将文档自动注入到所有服务或组件中并修改属性。

Open graph和测试即将推出