Giter Site home page Giter Site logo

transports's Introduction

Welcome to Transport

The idea is how to transport your code (HTML and Javascript) from your business logic (Model - Controller) into View.

Like a global variable, when can set and access it from anywhere in our code.

Currently we provide HTMLTransport and JavascriptTransport. For HTML Transport, you can give it the name each time you set (inserting) the code into it, just like a variable. For Javascript, you can not insert identical script, just to make sure you don't duplicate your javascript code.

How to use

Install via composer :

    composer require livecms/transports

HTML :

require vendor/autoload.php;

$htmlTransport = new LiveCMS\Transport\HtmlTransport;

// Set new transport with name 'form'
$html = '<div class="input"><input type="text" name="name" /></div>';
$htmlTransport->set($html, 'form');

// Set new transport with name 'message'
$html = '<div class="message">Hello, Admin</div>';
$htmlTransport->set($html, 'message');

// Append code to 'form'
$html = '<div class="input"><input type="email" name="email" /></div>';
$htmlTransport->append($html, 'form');

// Show content of 'form'
echo $htmlTransport->get('form');

/**
Result :
<div class="input"><input type="text" name="name" /></div>
<div class="input"><input type="email" name="email" /></div>
*/

// Delete content of 'form'
$htmlTransport->flush('form');
echo $htmlTransport->get('form');

/**
Result :
*/

// Use method pull() to get content and delete it.
echo $htmlTransport->pull('form');

// Delete all content
$htmlTransport->flushAll();
echo $htmlTransport->get('message');

/**
Result :
*/

Javascript :

require vendor/autoload.php;

$jsTransport = new LiveCMS\Transport\JavascriptTransport;

// Set new javascript code
$js = <<<JS
    $(':input').first().addClass('focus');
JS;
$jsTransport->set($js);

// Adding another javascript code
$js = <<<JS
    $('.message').text('Hi, bro. Whats up?');
JS;
$jsTransport->append($js);

// Adding another javascript code that same with previous, the code will not be saved.
$js = <<<JS
    $(':input').first().addClass('focus');
JS;
$jsTransport->append($js);

// Show content
echo $jsTransport->get();

/**
Result :
    $(':input').first().addClass('focus');
    $('.message').text('Hi, bro. Whats up?');
*/

// Delete content
$jsTransport->flush();
echo $jsTransport->get();

/**
Result :
*/

LICENSE

MIT

CONTRIBUTING

Fork this repo and make a pull request

ISSUE AND DISCUSSION

Please create new issue or see the closed issues too.

transports's People

Contributors

mrofi avatar

Stargazers

 avatar

Watchers

 avatar  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.