GithubHelp home page GithubHelp logo

pinky's Introduction

Pinky

A PHP Transpiler for (Inky), the templating language made for the Foundation for Email framework.

Installation

You can install this bundle using composer

composer require lorenzo/pinky

Usage and Examples

Basic Usage

<?php
use Pinky;

$transpiled = Pinky\transformFile('path/to/file.html');

// $transpiled is an instance of DOMDocument
echo $transpiled->saveHTML();

You can transpile strings directly:

<?php
use Pinky;

$transpiled = Pinky\transformString('<row>Contents</row>');
echo $transpiled->saveHTML();

And you can also transpile many files or strings in batch:

<?php
use Pinky;

$files = [$path1, $path2, $path3];

$transpiled = Pinky\transformManyFiles($files);
foreach ($transpiled as $result) {
    echo $result->saveHTML();
}

License

See the LICENSE file for license info (it's the MIT license).

pinky's People

Contributors

basster avatar djlechuck avatar dritter avatar fabpot avatar josegonzalez avatar kanow avatar lorenzo avatar netstyler avatar stephpy avatar stof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pinky's Issues

Center doesn't work properly

Without finding a fix or further investigating the issue, it seems that center doesn't work as it should. here is my layout:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width"/>
</head>
    <body>
            <table class="body">
                <tr>
                    <td class="center" align="center" valign="top">
                        <center>
                            <div>
                                <container class="body-drip">
                                    <spacer size="16"></spacer>

                                    <div>
<!-- this doesn't work -->
                                        <center>
                                            <img src="path to image"/>
                                        </center>
                                    </div>
                                </container>
                            </div>
                        </center>
                    </td>
                </tr>
            </table>
            <!-- prevent Gmail on iOS font size manipulation -->
            <div style="display:none; white-space:nowrap; font:15px courier; line-height:0;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
        </body>
</html>

this does work:

<div class="center" align="center">
    <img src="path to image"/>
</div>

Warning: DOMDocument::load(): I/O warning : failed to load external entity "/path/to/vendor/lorenzo/pinky/src/inky.xsl"

I,

In our application, we have a strange bug. Sometimes, the belowed error appears:

Warning: DOMDocument::load(): I/O warning : failed to load external entity "/path/to/vendor/lorenzo/pinky/src/inky.xsl"

Our application is a Symfony one, which use the Mailer component and the twig/inky-extra which use this library.
We send many email without any problem, but sometimes this happens and we are not able to understand why.
What's even stranger is that for the same email template, but with a different context (input data, code used to before calling the service which send it) sometimes it it works and sometimes the error occure... ๐Ÿ˜•

I thought that it was linked to the data we used, but the offending code is the loading of inky.xsl and inky-center.xsl, so it comes before our template is processed.

The only way we found to fix this was to add this code before the call of Inky:

if (\PHP_VERSION_ID < 80000) {
    libxml_disable_entity_loader(false);
}

Have you any idea of what's happening? There is not many literature about this on the internet. ๐Ÿ˜…

Cyrillic support

After update to version 1.0.8 stopped wort cyrillic support, On version 1.0.7 work fine.

Example

<container> is not parsed when surrounded with center tag

When I use following cake layout:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<?php echo $this->Html->css('Psa/Newsletters.newsletter.css'); ?>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="viewport" content="width=device-width">
	<title><?php echo $newsletter['subject']; ?></title>
</head>
<body>
<table class="body">
	<tr>
		<td class="center" align="center" valign="top">
			<center>
				<container>
					<?php
					echo $this->fetch('content');
					?>
				</container>
			</center>
		</td>
	</tr>
</table>
<!-- prevent Gmail on iOS font size manipulation -->
<div style="display:none; white-space:nowrap; font:15px courier; line-height:0;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</body>
</html>

Then the container inky tag is not parsed correctly.
The Container tag gets only some styles but is not parsed as a table.

Why did I use a center tag as surrounding tag?
The boilerplate from foundation-email has one: https://foundation.zurb.com/emails/docs/sass-guide.html#boilerplate

;)

I am not sure if this is a bug or just nonsense to have a center tag surrounding the container and rows of inky.

We pass the whole markup directly to Pinky\transformString($html);

What seems not to work:

<?php
use Pinky;

$transpiled = Pinky\transformString('<center><container><row>Contents</row></container></center>');
echo $transpiled->saveHTML();

Escaping characters

Is the responsibility in this library or Inky for escaping certain characters that we do now want HTML endcoed?

Specifically a URL with a query-string inside the Inky template will have ampersands converted to &amp; - this causes a conflict with another built-in feature for the front-end I'm using where the semi-colon is double-encoded. But I don't think the URL should have the ampersands encoded in the first place.

Any thoughts on this or have I missed some docs on it? TIA.

best way to add your own modifications?

What is the best solution to add your own modifications?

For example we use litmus to test if e-mails look correct in all applications. It also does a few checks if the mail contains good metadata. Two issues were given by litmus that requires me to modify the html that was generated from this library.

How do I add a lang attribute on if pinky adds/modifies this?
How do I add role=presentation to the tables pinky adds?

If I read the code all it does is executing 2 xsd files.

First <container> will be ignored when it's the first element in <center>

If I use the container in a center element, the container will be not rendered as a table. In src/inky.xsl in line 104 my container will be matched and a class float-center is added to the element. It will be not changed to a table element.

The expected behaviour for me were an table with the added class="float-center". It seems that the matching from line 11 ist not working. I don't know why is it so ( I'm not familiar with this xsl stuff).

To fix this problem for the moment I changed the code in line 104 in this way:
<xsl:template match="center/*[position() = 1 and not(contains(@class, 'float-center')) and not('container')]">

This solves the problem for me but I believe that's not the right way. Nevertheless I want to understand why the first matching, to change the container (line 11), is not working.

CI setup

The library currently has tests, but no CI setup.
It would be great to configure a CI, which would enforce tests to run on contributions, and could run tests on all supported PHP versions.

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.