Skip to content

Commit

Permalink
Merge pull request #46 from bumpcore/45-compiling-php-templates-from-…
Browse files Browse the repository at this point in the history
…blade-workflow

view compiling
  • Loading branch information
megasteve19 authored Apr 14, 2023
2 parents 00ea455 + 2396dc6 commit 9e7f554
Show file tree
Hide file tree
Showing 46 changed files with 311 additions and 226 deletions.
52 changes: 52 additions & 0 deletions .github/scripts/compile-templates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

use Illuminate\Contracts\View\ViewCompilationException;
use Illuminate\Filesystem\Filesystem;
use Illuminate\View\Compilers\BladeCompiler;

require __DIR__ . '/../../vendor/autoload.php';

class Compiler extends BladeCompiler
{
protected function compileForeach($expression)
{
preg_match('/\( *(.+) +as +(.*)\)$/is', $expression ?? '', $matches);

if (count($matches) === 0)
{
throw new ViewCompilationException('Malformed @foreach statement.');
}

$iteratee = trim($matches[1]);

$iteration = trim($matches[2]);

return "<?php foreach({$iteratee} as {$iteration}): ?>";
}

protected function compileEndforeach()
{
return '<?php endforeach; ?>';
}
}

$compiler = new Compiler(new Filesystem(), __DIR__, false);

foreach (['bootstrap-five', 'tailwind'] as $framework)
{
foreach (scandir(__DIR__ . '/../../resources/views/' . $framework) as $template)
{
if (!str_ends_with($template, '.blade.php'))
{
continue;
}

$bladePath = __DIR__ . '/../../resources/views/' . $framework . '/' . $template;
$compiledPath = __DIR__ . '/../../resources/php/' . $framework . '/' . str_replace('.blade.php', '.php', $template);

file_put_contents(
$compiledPath,
$compiler->compileString(file_get_contents($bladePath))
);
}
}
48 changes: 24 additions & 24 deletions .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
name: Fix syling

on:
push:
branches:
- master
- "*.x"
paths:
- "**.php"
push:
branches:
- master
- "*.x"
paths:
- "**.php"

pull_request:
paths:
- "**.php"
pull_request:
paths:
- "**.php"

permissions:
contents: write
contents: write
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Install dependencies
run: composer install
- name: Install dependencies
run: composer install

- name: Execute php-cs-fixer
run: ./vendor/bin/php-cs-fixer fix
- name: Execute php-cs-fixer
run: ./vendor/bin/php-cs-fixer fix

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
34 changes: 34 additions & 0 deletions .github/workflows/view-compiling.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: View Compiling

on:
push:
branches:
- master
- "*.x"
paths:
- "**.php"

pull_request:
paths:
- "**.php"

permissions:
contents: write
jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Install dependencies
run: composer install

- name: Execute script
run: php .github/scripts/compile-templates.php

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Compiling Templates
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ parameters:
- "#Undefined variable: \\$this#"
- "#Call to an undefined method BumpCore\\\\EditorPhp\\\\EditorPhp::getParagraphs\\(\\).#"
- "#Variable \\$data might not be defined.#"
- "#Unreachable statement - code above always terminates.#"
reportUnmatchedIgnoredErrors: false
8 changes: 4 additions & 4 deletions resources/php/bootstrap-five/attaches.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div class="rounded d-flex gap-3 mb-3">
<div class="bg-light text-uppercase fs-5 fw-bold p-4 rounded"><?= $data('file.extension'); ?></div>
<div class="bg-light text-uppercase fs-5 fw-bold p-4 rounded"><?php echo $data('file.extension'); ?></div>
<div>
<p class="text-lg fw-bold mb-0">
<a
class="link-dark gap-1 d-inline-flex justify-content-center align-items-center"
href="<?= $data('file.url'); ?>"
href="<?php echo $data('file.url'); ?>"
target="_blank"
>
<span><?= $data('title') ?? $data('file.name'); ?></span>
<span><?php echo $data('title') ?? $data('file.name'); ?></span>
<svg
class="inline"
fill="currentColor"
Expand All @@ -27,6 +27,6 @@ class="inline"
</svg>
</a>
</p>
<p class="fw-semibold text-secondary"><small><?= number_format($data('file.size') * 0.000001, 2); ?>MiB</small></p>
<p class="fw-semibold text-secondary"><small><?php echo number_format($data('file.size') * 0.000001, 2); ?>MiB</small></p>
</div>
</div>
10 changes: 5 additions & 5 deletions resources/php/bootstrap-five/checklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
class="d-flex flex-column align-items-start pl-8 gap-1 mb-3"
style="list-style: none"
>
<?php foreach ($data('items', []) as $item): ?>
<?php foreach($data('items', []) as $item): ?>
<li class="inline-flex justify-center align-items-center gap-2">
<span class="bg-light rounded-circle <?= $item['checked'] ? 'text-secondary' : 'text-black'; ?>">
<span class="bg-light rounded-circle <?php echo $item['checked'] ? 'text-secondary' : 'text-black'; ?>">
<svg
fill="currentColor"
height="24"
Expand All @@ -19,10 +19,10 @@ class="d-flex flex-column align-items-start pl-8 gap-1 mb-3"
</span>

<?php if($item['checked']): ?>
<del><?= $item['text']; ?></del>
<del><?php echo $item['text']; ?></del>
<?php else: ?>
<span><?= $item['text']; ?></span>
<span><?php echo $item['text']; ?></span>
<?php endif; ?>
</li>
<?php endforeach; ?>
<?php endforeach; ?>
</div>
2 changes: 1 addition & 1 deletion resources/php/bootstrap-five/code.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="p-4 bg-light rounded mb-3">
<div class="overflow-x-auto w-full bg-white rounded p-3">
<pre><?= $data('code'); ?></pre>
<pre><?php echo $data('code'); ?></pre>
</div>
</div>
11 changes: 6 additions & 5 deletions resources/php/bootstrap-five/embed.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<div class="mb-3 bg-light p-4 rounded">
<iframe
class="block mb-3 rounded bg-white"
height="<?= $data('height'); ?>"
height="<?php echo $data('height'); ?>"
loading="lazy"
src="<?= $data('embed'); ?>"
src="<?php echo $data('embed'); ?>"
width="100%"
></iframe>

<p class="bg-white p-4 rounded mb-1">
<?= $data('caption'); ?>
<?php echo $data('caption'); ?>

</p>

<p>
<small>
<a
class="link-secondary"
href="<?= $data('source'); ?>"
href="<?php echo $data('source'); ?>"
target="_blank"
><?= $data('source'); ?></a>
><?php echo $data('source'); ?></a>
</small>
</p>

Expand Down
37 changes: 19 additions & 18 deletions resources/php/bootstrap-five/header.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?php switch($data('level')): case 1: ?>
<h1 class="fw-bold mb-3"><?= $data('text'); ?></h1>
<?php break;
<?php switch($data('level')):
case (1): ?>
<h1 class="fw-bold mb-3"><?php echo $data('text'); ?></h1>
<?php break; ?>

case 2: ?>
<h2 class="fw-bold mb-3"><?= $data('text'); ?></h2>
<?php break;
<?php case (2): ?>
<h2 class="fw-bold mb-3"><?php echo $data('text'); ?></h2>
<?php break; ?>

case 3: ?>
<h3 class="fw-bold mb-3"><?= $data('text'); ?></h3>
<?php break;
<?php case (3): ?>
<h3 class="fw-bold mb-3"><?php echo $data('text'); ?></h3>
<?php break; ?>

case 4: ?>
<h4 class="fw-semibold mb-3"><?= $data('text'); ?></h4>
<?php break;
<?php case (4): ?>
<h4 class="fw-semibold mb-3"><?php echo $data('text'); ?></h4>
<?php break; ?>

case 5: ?>
<h5 class="fw-semibold mb-3"><?= $data('text'); ?></h5>
<?php break;
<?php case (5): ?>
<h5 class="fw-semibold mb-3"><?php echo $data('text'); ?></h5>
<?php break; ?>

case 6: ?>
<h6 class="fw-semibold mb-1"><?= $data('text'); ?></h6>
<?php break; ?>
<?php case (6): ?>
<h6 class="fw-semibold mb-1"><?php echo $data('text'); ?></h6>
<?php break; ?>
<?php endswitch; ?>
4 changes: 2 additions & 2 deletions resources/php/bootstrap-five/image.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<img
alt="<?= $data('caption'); ?>"
src="<?= $data('file.url'); ?>"
alt="<?php echo $data('caption'); ?>"
src="<?php echo $data('file.url'); ?>"
class="d-block mb-3 w-100 rounded"
>
12 changes: 6 additions & 6 deletions resources/php/bootstrap-five/linktool.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<div class="bg-light d-flex mb-3 rounded overflow-hidden flex-column flex-sm-row">
<img
alt="<?= $data('meta.title'); ?>"
alt="<?php echo $data('meta.title'); ?>"
width="100%"
src="<?= $data('meta.image.url'); ?>"
src="<?php echo $data('meta.image.url'); ?>"
style="object-fit: cover"
>
<div class="m-4 p-4 bg-white rounded flex-2">
<h4 class="text-xl fw-semibold"><?= $data('meta.title'); ?></h4>
<h4 class="text-xl fw-semibold"><?php echo $data('meta.title'); ?></h4>
<p class="mb-3 text-sm">
<small>
<a
class="link-dark fw-bold"
href="<?= $data('link'); ?>"
href="<?php echo $data('link'); ?>"
target="_blank"
><?= $data('link'); ?></a>
><?php echo $data('link'); ?></a>
</small>
</p>
<p class="mb-0"><?= $data('meta.description'); ?></p>
<p class="mb-0"><?php echo $data('meta.description'); ?></p>
</div>
</div>
14 changes: 7 additions & 7 deletions resources/php/bootstrap-five/list.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php if ($data('style') === 'ordered'): ?>
<?php if($data('style') === 'ordered'): ?>
<ol class="mb-3">
<?php foreach ($data('items', []) as $item): ?>
<li class="mb-1"><?= $item; ?></li>
<?php endforeach; ?>
<?php foreach($data('items', []) as $item): ?>
<li class="mb-1"><?php echo $item; ?></li>
<?php endforeach; ?>
</ol>
<?php else: ?>
<ul class="mb-3">
<?php foreach ($data('items', []) as $item): ?>
<li class="mb-1"><?= $item; ?></li>
<?php endforeach; ?>
<?php foreach($data('items', []) as $item): ?>
<li class="mb-1"><?php echo $item; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
2 changes: 1 addition & 1 deletion resources/php/bootstrap-five/paragraph.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p class="mb-3"><?= $data('text'); ?></p>
<p class="mb-3"><?php echo $data('text'); ?></p>
12 changes: 6 additions & 6 deletions resources/php/bootstrap-five/personality.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<div class="bg-light d-flex mb-3 rounded overflow-hidden flex-column flex-sm-row">
<img
alt="<?= $data('name'); ?>"
src="<?= $data('photo'); ?>"
alt="<?php echo $data('name'); ?>"
src="<?php echo $data('photo'); ?>"
style="object-fit: cover"
width="100%"
>
<div class="m-4 p-4 bg-white rounded flex-2">
<h4 class="text-xl fw-semibold"><?= $data('name'); ?></h4>
<h4 class="text-xl fw-semibold"><?php echo $data('name'); ?></h4>
<p class="mb-3 text-sm">
<small>
<a
class="link-dark fw-bold"
href="<?= $data('link'); ?>"
href="<?php echo $data('link'); ?>"
target="_blank"
><?= $data('link'); ?></a>
><?php echo $data('link'); ?></a>
</small>
</p>
<p class="mb-0"><?= $data('description'); ?></p>
<p class="mb-0"><?php echo $data('description'); ?></p>
</div>
</div>
4 changes: 2 additions & 2 deletions resources/php/bootstrap-five/quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</svg>
</div>
<div class="z-1 position-relative">
<p class="fs-4 fw-semibold mb-0"><?= $data('text'); ?></p>
<small class="d-block text-end"><?= $data('caption'); ?></small>
<p class="fs-4 fw-semibold mb-0"><?php echo $data('text'); ?></p>
<small class="d-block text-end"><?php echo $data('caption'); ?></small>
</div>
</blockquote>
Loading

0 comments on commit 9e7f554

Please sign in to comment.