Skip to content

Commit

Permalink
Init implementation
Browse files Browse the repository at this point in the history
* Update readme
* Add gitattributes and gitignore
* Add GH workflows - props to @szepeviktor for initial implementation
* Add changelog file
* Add code of conduct file
* Add captainhook config
* Add composer file
* Add phpunit file
* Add phpcs config
* Add phpstan config
* Add initial implementation of the renderer
  * It does nothing at the moment.
* Add initial tests
  * Currently failing, so the test is skipped.
* Add parallel lint

Co-authored-by: Viktor Szépe <[email protected]>
  • Loading branch information
dingo-d and szepeviktor authored Nov 3, 2022
1 parent 42b7092 commit dace261
Show file tree
Hide file tree
Showing 16 changed files with 698 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Exclude these files from release archives.
# This will also make them unavailable when using Composer with `--prefer-dist`.
# https://blog.madewithlove.be/post/gitattributes/
#
/.editorconfig export-ignore
/.github export-ignore
/.gitignore export-ignore
/.gitattributes export-ignore
/CODE_OF_CONDUCT.md export-ignore
/tests export-ignore
/phpcs.xml.dist export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml export-ignore
/captainhook.json export-ignore

#
# Auto detect text files and perform LF normalization
# http://davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/
#
* text=auto

#
# The above will handle all files NOT found below
#
*.md text
*.php text
*.inc text
*.js text
192 changes: 192 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
name: "CI Checks"

on:
push:
branches:
- "develop"
- "main"
paths-ignore:
- "**.md"
pull_request:
paths-ignore:
- "**.md"

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
byte_level:
name: "0️⃣ Permission checks"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Check file permissions"
run: |
test "$(find . -type f -not -path './.git/*' -executable)" = ""
syntax_errors:
name: "1️⃣ Syntax errors checks"
runs-on: "ubuntu-latest"
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "7.4"
coverage: "none"

- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Find non-printable ASCII characters"
run: |
! LC_ALL=C.UTF-8 find . -type f -name "*.php" -print0 | xargs -0 -- grep -PHn "[^\t -~]"
- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "highest"

- name: "Check source code for syntax errors"
run: "composer exec -- parallel-lint src/ tests/"

unit_tests:
name: "2️⃣ Unit tests"
needs:
- "byte_level"
- "syntax_errors"
runs-on: "ubuntu-latest"
continue-on-error: ${{ matrix.allowed_failure }}
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.0', '7.4' ]
allowed_failure: [ false ]
dependencies:
- "lowest"
- "highest"
include:
- php: '8.2'
allowed_failure: true
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
coverage: "xdebug"

- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependencies }}"

- name: "Execute unit tests"
run: "composer run test:coverage"

- name: "Upload coverage to Codecov"
env:
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"
if: "${{ env.CODECOV_TOKEN && matrix.php == '7.4' && matrix.dependencies == 'highest' }}"
uses: "codecov/codecov-action@v3"
with:
token: "${{ env.CODECOV_TOKEN }}"
files: "./tests/coverage/clover.xml"
flags: "unittests"
name: "libs-codecov"
fail_ci_if_error: "true"

static_analysis:
name: "3️⃣ Static analysis checks"
needs:
- "byte_level"
- "syntax_errors"
runs-on: "ubuntu-latest"
continue-on-error: ${{ matrix.allowed_failure }}
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.0', '7.4' ]
allowed_failure: [ false ]
include:
- php: '8.2'
allowed_failure: true
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
coverage: "none"

- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Validate Composer configuration"
run: "composer validate --strict"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "highest"

- name: "Execute static analysis"
run: "composer run test:types"

coding_standards:
name: "4️⃣ Coding standards checks"
needs:
- "byte_level"
- "syntax_errors"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.0', '7.4' ]
allowed_failure: [ false ]
include:
- php: '8.2'
allowed_failure: true
steps:
- name: "Set up PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php }}"
coverage: "none"
tools: "cs2pr"

- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Check adherence to EditorConfig"
uses: "greut/eclint-action@v0"

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "highest"

- name: "Check coding style"
run: |
composer run test:style -- -q --report=checkstyle | cs2pr
exported_files:
name: "5️⃣ Exported files checks"
needs:
- "byte_level"
- "syntax_errors"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout code"
uses: "actions/checkout@v3"

- name: "Check exported files"
run: |
EXPECTED="CHANGELOG.md,LICENSE,README.md,composer.json"
CURRENT="$(git archive HEAD | tar --list --exclude="src" --exclude="src/*" | paste -s -d ",")"
echo "CURRENT=${CURRENT}"
echo "EXPECTED=${EXPECTED}"
test "${CURRENT}" = "${EXPECTED}"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor

.phpunit.result.cache
composer.lock
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log for the PHP MJML Renderer
All notable changes to this project will be documented in this file.

This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).


[Unreleased]: https://github.com/dingo-d/php-mjml-renderer/compare/main...HEAD
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# php-mjml-renderer
# MJML Renderer for PHP

A PHP implementation of MJML rendering engine

## Why?

The [existing library](https://github.com/qferr/mjml-php) that is used to parse MJML language into HTML is using either a MJML API, or a node executable to parse the MJML language into HTML.

The idea is to create a separate renderer written entirely in PHP that will be able to parse the MJML language and return the correct HTML.

Why? Why not?

## Installation

```bash
composer require dingo-d/php-mjml-renderer
```

## Usage

```php
<?php
require_once 'vendor/autoload.php';

use MadeByDenis\PhpMjmlRenderer\Renderer;

$renderer = new Renderer();

$html = $renderer->render('
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>Hello world</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
');
```
Loading

0 comments on commit dace261

Please sign in to comment.