2017 © Pedro Peláez
 

library php-content-stylizer

Content stylizer for Schibsted Media Platform data

image

schibsted-tech-polska/php-content-stylizer

Content stylizer for Schibsted Media Platform data

  • Wednesday, February 15, 2017
  • by svd-stp
  • Repository
  • 18 Watchers
  • 1 Stars
  • 196 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Content Stylizer - PHP

This library was written to support converting text objects introduced in Schibsted Media Platform's article format version 5 into HTML in PHP., (*1)

To use it you have to create Stylizer instance and define a list of supported tags in one of two ways. Then you can use getHtml method passing text and an array with markups and receiving HTML code as an output., (*2)

Basic usage:

Defining tags list (method 1):

$stylizer = new \ContentStylizer\Stylizer([
    [
        'beginning' => '<strong>',
        'end' => '</strong>',
        'type' => 'strong',
    ],
]);

Defining tags list (method 2):

$stylizer = new \ContentStylizer\Stylizer();
$stylizer->addTag('strong', '<strong>', '</strong>');

Converting text into HTML:

$text = 'Sample text';
$markups = [
    [
        'length' => 6,
        'offset' => 0,
        'type' => 'strong',
    ],
];

$html = $stylizer->getHtml($text, $markups);

Parameters inside tags:

Both beginning and end attribute of any tag can be defined using string or anonymous function. The second way allows us to add some logic to HTML creation process and to use parameters passed in markup objects., (*3)

Let's define link tag:, (*4)

$stylizer->addTag('link', function (\stdClass $params) {
    return '<a href="' . $params->uri . '" target="_blank">;
}, '</a>');

Then we can use link markup:, (*5)

$html = $stylizer->getHtml('Our link', [
    [
        'length' => 4,
        'offset' => 4,
        'type' => 'link',
        'uri' => 'http://www.example.com',
    ],
]);

Note that $params object contains all attributes of markup one except length, offset and type which means that in this example it contains only uri parameter., (*6)

Singleton tags:

There is also a way of defining singleton tags, e.g. line breaks - Stylizer will treat as singleton every tag without end parameter defined., (*7)

It can be defined in an array passed to constructor:, (*8)

    ...
    [
        'beginning' => '<br>',
        'type' => 'br',
    ],
    ...

We can define it using addTag method as well:, (*9)

$stylizer->addTag('br', '<br>');

If we define br tag, Stylizer will also add line break in every place in text before PHP_EOL sign occurence., (*10)

Tests:

This library contains unit tests and some other CI tools which can be easily run using Node.js. To do it install Node.js environment, then Grunt CLI:, (*11)

sudo npm install -g grunt-cli

and project dependencies:, (*12)

npm install

To start testing just simply execute:, (*13)

grunt test

The Versions

15/02 2017

dev-master

9999999-dev https://github.com/Schibsted-Tech-Polska/php-content-stylizer

Content stylizer for Schibsted Media Platform data

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • php >=5.6.0

 

The Development Requires

by STP Svenska Dagbladet team

svd content stylizer stylizr

15/02 2017

1.0.2

1.0.2.0 https://github.com/Schibsted-Tech-Polska/php-content-stylizer

Content stylizer for Schibsted Media Platform data

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • php >=5.6.0

 

The Development Requires

by STP Svenska Dagbladet team

stylizr stylizer svd content

10/02 2017

1.0.1

1.0.1.0 https://github.schibsted.io/SvD/php-content-stylizer

Content stylizer for Schibsted Media Platform data

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • php >=5.6.0

 

The Development Requires

by STP Svenska Dagbladet team

stylizr stylizer svd content

07/02 2017

1.0.0

1.0.0.0 https://github.schibsted.io/SvD/php-content-stylizer

Content stylizer for Schibsted Media Platform data

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • php >=5.6.0

 

The Development Requires

by STP Svenska Dagbladet team

stylizr stylizer svd content

03/02 2017

0.1.0

0.1.0.0 https://github.schibsted.io/SvD/php-content-stylizer

Content stylizer for Schibsted Media Platform data

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • php >=5.6.0

 

The Development Requires

by STP Svenska Dagbladet team

stylizr stylizer svd content

We request your permission to obtain statistical data of your navigation on this website, in compliance with Royal Decree-Law 13/2012 (Spain). If you continue browsing, we consider that you accept the use of cookies. OK | More information