Skip to content

skodak/rtlcss-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RTLCSS for PHP

RTLCSS is a framework for converting Left-To-Right (LTR) Cascading Style Sheets(CSS) to Right-To-Left (RTL).

Usage

Installation using composer

Add the library to your composer.json

{
    "repositories": [{
        "type": "vcs",
        "url": "https://github.com/moodlehq/rtlcss-php"
    }],
    "require-dev": {
        "moodlehq/rtlcss-php": "*"
    }
}

Flipping

$parser = new Sabberworm\CSS\Parser($css);
$tree = $parser->parse()
$rtlcss = new MoodleHQ\RTLCSS\RTLCSS($tree);
$rtlcss->flip();
echo $tree->render();

For parsing options and rendering, refer to Sabeerword/PHP-CSS-Parser.

Output sample

.div {
    direction: ltr;
    left: 10px;
    border: 10px 5px 0px 2px;
    float: left;
}

Becomes:

.div {
    direction: rtl;
    right: 10px;
    border: 10px 2px 0px 5px;
    float: right;
}

Options

You can prefix your CSS with comments starting with /*rtl:*/ for special handling.

Do not flip values

Prepend with /*rtl:ignore*/, or wrap within /*rtl:begin:ignore*/ and /*rtl:end:ignore*/.

.div {
    /*rtl:ignore*/
    float: left;
    left: 10px;
}
.div {
    direction: ltr;
    /*rtl:begin:ignore*/
    float: left;
    left: 10px;
    /*rtl:end:ignore*/
}

Becomes:

.div {
    float: left;
    right: 10px;
}
.div {
    direction: rtl;
    float: left;
    left: 10px;
}

Remove CSS

Prepend with /*rtl:remove*/, wrap within /*rtl:begin:remove*/ and /*rtl:end:remove*/.

.div {
    /*rtl:remove*/
    float: left;
    left: 10px;
}
.div {
    direction: ltr;
    /*rtl:begin:remove*/
    float: left;
    left: 10px;
    /*rtl:end:remove*/
}

Becomes:

.div {
    right: 10px;
}
.div {
    direction: rtl;
}

Additional CSS

Write the CSS in a content starting with /*rtl:raw:.

.div {
    /*rtl:raw:
        text-align: left;
    */
    float: left;
}

Becomes:

.div {
    text-align: left;
    float: right;
}

About this tool

This tool is very heavily inspired by MohammaYounes/rtlcss, even though at this stage it does not include all of its features. See this library as a partial port of the latter.

Credits

License

Licensed under the MIT License.

About

RTLCSS-PHP is a framework for converting LTR CSS to RTL.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%