Giter Club home page Giter Club logo

yuki-html's Introduction

yuki-html project status

Build Status

Efficient way to create and modify HTML tags.

Why you should use it

Sometimes you need to return html tag from class, and be able to modify it later:

<?php

    class myImage{
        public static function getHtml(){
            return '<img src="myimage.png" />';
        }
    }
    $img = myImage::getHtml();
    // I wanna add alt and style attributes before output, but how I can?
    echo $img;

So, How?

<?php

	use yuki\html\tag;
    class myImage{
        public static function getHtml(){
            return tag::create('img', array('src' => 'myimage.png'));
        }
    }
    $img = myImage::getHtml();

Now you can do what you want:

<?php

    $img['alt'] = 'My Image!';
    $img['style'] = "border: none;";
    echo $img; // <img src="myimage.png" alt="My Image!" style="border: none;" />

You even able to get attributes

<?php

    echo $img['src']; // myimage.png

To remove attributes

<?php

    unset($img['style']);
    echo $img; // <img src="myimage.png" alt="My Image!" />

To wrap

<?php

	use yuki\html\tag;
    $a = tag::create('a', array('href'=>'/'));
    $a->appendChild($img);
    echo $a; // <a href="/"><img src="myimage.png" alt="My Image!" /></a>

To set text, it will be escaped!

<?php

    $a->setText('click here >>');
    echo $a; // <a href="/">click here &gt;&gt;</a>

Usage

<?php

	use yuki\html\tag;
    $head = tag::create('head');
    $head->appendChild(
            tag::create('title')->setText('Page Title')
        );
    $head->appendChild(
            tag::create('meta', array(
                'name'=>'description', 
                'contents' => 'Page Description'
            )
        );
    $head['lang'] = 'en';
    echo $head; // Will output generated html code.

About

Requirements

  • Any flavor of PHP 5.3 should do
  • [optional] PHPUnit 3.5+ to execute the test suite (phpunit --version)

Submitting bugs and feature requests

Bugs and feature request are tracked on Github

Author

olamedia - [email protected]
See also the list of contributors which participated in this project.

License

yuki-html is licensed under the MIT License - see the LICENSE file for details

Acknowledgements

This library is inspired by symfony (TagHelper), kohana (HTML) and other frameworks

yuki-html's People

Contributors

olamedia avatar theshock avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.