受Emmet启发的简单DOM生成器

dev-master 2017-02-12 09:35 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:25:32 UTC


README

Emmet启发的简单DOM生成器。简单且流畅。

安装

% composer require dmitrivereshchagin/sprout

使用

您可以通过以下方式从子树构建您的DOM(尽管应该避免递归)

use Sprout\Node as Root;

$head = Root::create('head')
    ->meta('charset="utf-8"')->merge()
    ->up()
    ->title()->text('Title')
    ->root()
;

$body = Root::create('body')
    ->h1('id="header"')->text('Header')
    ->up()
    ->p()->text('Paragraph of text.')->times(2)
    ->root()
;

echo Root::create('html', 'lang="en"')
    ->insert($head, $body)
;

或者您可以使用标记节点构建整个树

echo Root::create('html', 'lang="en"')->mark('h')
    // head subtree
    // ...
    ->to('h')
    // body subtree
    // ...
    ->root()
;

测试

% composer test