承接 best-served-cold/html-builder 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

best-served-cold/html-builder

Composer 安装命令:

composer require best-served-cold/html-builder

包简介

HTML Builder - Build HTML programatically.

README 文档

README

Build Status Build Status Code Coverage Latest Stable Version Scrutinizer Code Quality SensioLabsInsight

HTML Builder

Basic HTML builder for HTML5. We're not suggesting that you use this to build entire pages, but occasionally there is a need to create HTML programatically, like a table, and that's what this is for!

Install

composer require best-served-cold/html-builder

Usage

Call in the Builder and Output classes:

use BestServedCold\HTMLBuilder\Html;
use BestServedCold\HTMLBuilder\Output;

Create an element

$p = Html::p()->content('some content');
echo (new Output($p))->get(); 

Returns:

<p>
    some content
</p>

Adding attributes

$div  = Html::div()->class('someClass')->id('someId');
echo (new Output($div))->get();

Returns:

<div class="someClass" id="someId">
</div>

Adding children

$div2 = Html::div(
    Html::p()->content('child content')->class('someClass'),
    function () {
        return Html::input()
            ->type('text')
            ->name('test')
            ->disabled();
    }
)->onblur('somefunc();');
echo (new Output($div2))->get();

NB: Accepts arrays as well as Closures.

Returns:

<div onblur="someFunc();">
    <p class="someClass">
        child content
    </p>
    <input type="text" name="test" disabled>
</div>

Change tab size and depth

$div3 = Html::div(
    Html::p(
        Html::span()
            ->data('bob')
            ->content('span content')
    ),
    Html::comment(' this is some comment ')

);
Output::setTabSize(2); // persistent
Output::setDepth(2); // persistent
echo (new Output($div3))->get();
Output::setTabSize(4);
Output::setDepth(0);

Returns:

    <div>
      <p>
        <span data="bob">
          span content
        </span>
      </p>
      <!-- this is some comment -->
    </div>

Basic table

$table = Html::table(
    Html::thead(
        Html::tr(
            Html::th()->content('mary')->class('woman'),
            Html::th()->content('susan')->class('woman'),
            Html::th()->content('harry')->scope('col')
        )
    ),
    Html::tbody(
        Html::tr(
            Html::td()->content('margret')->class('woman'),
            Html::td()->content('bob')->onfocus('someFunction()'),
            Html::td()->content('skyscraper')->id('oddOneOut')
        ),
        Html::tr(
            Html::td()->content('brian')->colspan(3)
        )
    )
)->attribute('someNonStandardAttribute', 'mary');
echo (new Output($table))->get();

Returns:

<table someNonStandardAttribute="mary">
    <thead>
        <tr>
            <th class="woman">
                mary
            </th>
            <th class="woman">
                susan
            </th>
            <th scope="col">
                harry
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="woman">
                margret
            </td>
            <td onfocus="someFunction()">
                bob
            </td>
            <td id="oddOneOut">
                skyscraper
            </td>
        </tr>
        <tr>
            <td colspan="3">
                brian
            </td>
        </tr>
    </tbody>
</table>

Examples

To run the examples:

$ cd example
$ php ./example.php

统计信息

  • 总下载量: 65
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固