Pug Renderer - a (heavily based on the PhpRenderer) renderer for rendering Pug view scripts into a PSR-7 Response object

Overview

Pug Renderer

This is a (heavily based on the PhpRenderer) renderer for rendering Pug view scripts into a PSR-7 Response object. It works well with Slim Framework 3.

Security risks

Pug Renderer uses Pug.php under the hood. Pug Renderer is merely a thin layer to Pug.php work with Slim 3. We will not keep track of vulnerabilities. Please refer to the original project to find out more how to prevent issues and to report vulnerabilities.

Installation

Install with Composer:

$ composer require md/pug-slim

Usage with Slim 3

getContainer(); $container['renderer'] = new PugRenderer("./templates"); $app->get('/hello/{name}', function ($request, $response, $args) { return $this->renderer->render($response, "/hello.pug", $args); }); $app->run();">
use Slim\Views\PugRenderer;

include "vendor/autoload.php";

$app = new Slim\App();
$container = $app->getContainer();
$container['renderer'] = new PugRenderer("./templates");

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->renderer->render($response, "/hello.pug", $args);
});

$app->run();

Usage with any PSR-7 Project

render(new Response(), "/path/to/template.pug", $yourData);">
//Construct the View
$pugView = new PugRenderer("./path/to/templates");

//Render a Template
$response = $pugView->render(new Response(), "/path/to/template.pug", $yourData);

Template Variables

You can add variables to your renderer that will be available to all templates you render.

"Title" ]; $pugView = new PugRenderer("./path/to/templates", $templateVariables); // or setter $pugView->setAttributes($templateVariables); // or individually $pugView->addAttribute($key, $value);">
// via the constructor
$templateVariables = [
    "title" => "Title"
];
$pugView = new PugRenderer("./path/to/templates", $templateVariables);

// or setter
$pugView->setAttributes($templateVariables);

// or individually
$pugView->addAttribute($key, $value);

Data passed in via ->render() takes precedence over attributes.

"Title" ]; $pugView = new PhpRenderer("./path/to/templates", $templateVariables); //... $pugView->render($response, $template, [ "title" => "My Title" ]); // In the view above, the $title will be "My Title" and not "Title"">
$templateVariables = [
    "title" => "Title"
];
$pugView = new PhpRenderer("./path/to/templates", $templateVariables);

//...

$pugView->render($response, $template, [
    "title" => "My Title"
]);
// In the view above, the $title will be "My Title" and not "Title"

Exceptions

\RuntimeException - if template does not exist

\InvalidArgumentException - if $data contains 'template'

References

You might also like...
This is a community-based project designed in the view of R.V.R & J.C College of Engineering hostel mess maintenance.

Hostel-Maintenance-System Introduction This is a community-based project designed in the view of R.V.R & J.C College of Engineering hostel mess mainte

Magento 2 Italian Language Pack is special gift for Magento 2 Community Edition. The data of the translation is supplied by Magento 2 Translation Project of Crowdin site, on which you will contribute into the project and download the zip file to install on your own store. This knowledge base will include full of the clear guides that supports you to convert the default language (English) into Italian language on your entire store. Block malicious scripts using botscout.com protection for your laravel app
Block malicious scripts using botscout.com protection for your laravel app

Laravel BotScout Protect your website against automated scripts using the botscout.com API. Installation You can install the package via composer: com

The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts.

Sitemap_index.xml The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts

Run PHP scripts on the fly at runtime on a PocketMine-MP server (useful for debugging)

Scripter Run PHP scripts on the fly at runtime on a PocketMine-MP server. This is useful for runtime debugging, when you don't want to restart the ser

Composer plugin replacing placeholders in the scripts section by dynamic values

Composer Substitution Plugin The Composer Substitution plugin replaces placeholders in the scripts section by dynamic values. It also permits to cache

Scripts-dev directive for composer

scriptsdev for Composer It's like require-dev, but for scripts Installation Just run composer require neronmoon/scriptsdev --dev Usage After installin

One-file composer scripts

Melody - One-file composer scripts Create a file named test.php: ?php CONFIG packages: - "symfony/finder: ~2.8" CONFIG; $finder = Symfony\Com

Magento Deployment Scripts

Magento Deployment Scripts Author: Fabrizio Branca This is a collection of scripts used to build/package, deploy and install Magento projects. Import

Comments
  • Pug-php 3 compatibility

    Pug-php 3 compatibility

    Hi, pug-php 3 is now at the release candidate step and embed a completely new engine (https://github.com/phug-php/phug that will be the same engine for both tale-pug and pug-php).

    Could you please test your adapter again the two supported pug-php versions (2.7.2 and 3.0.0-RC1)?

    We're preparing a documentation website and we will talk about all framework integrations compatible with phug (so pug-php 3).

    Then if it succeed, please update your composer.json with "pug-php/pug": "^2.6.0 || ^3.0.0" and tag a release so when we will release pug-php 3 as stable, it would be available for your users with a simple composer update.

    Thanks.

    opened by kylekatarnls 1
  • Add unit tests

    Add unit tests

    Hi, here are some proposals for your engine:

    • Add unit tests to ensure all works as expected and will continue to
    • Travis CI configuration to get each commit tested automatically on all supported versions of PHP: https://travis-ci.org/pug-php/pug-slim
    • Use DIRECTORY_SEPARATOR and trim template path to get cross-os compatibility
    opened by kylekatarnls 1
Releases(1.0)
Owner
Marcello Duarte
Marcello Duarte
Deeper is a easy way to compare if 2 objects is equal based on values in these objects. This library is heavily inspired in Golang's reflect.DeepEqual().

Deeper Deeper is a easy way to compare if 2 objects is equal based on values in these objects. This library is heavily inspired in Golang's reflect.De

Joubert RedRat 4 Feb 12, 2022
Developer-friendly framework heavily inspired by Laravel and based on Timber and Wpemerge solutions for WordPress themes development with Bedrock folder structure

Lightweight Brocooly (Brocket) Improved Controllers, Middleware and Routers, but slightly less powerful Container Open beta. Package in development Cr

Ihar Aliakseyenka 3 Mar 4, 2022
A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.

Net A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package. Features: No hard dependencies; Favours

Minibase 16 Jun 7, 2022
A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.

Net A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package. Features: No hard dependencies; Favours

Minibase 16 Jun 7, 2022
A collection of command line scripts for Magento 2 code generation, and a PHP module system for organizing command line scripts.

What is Pestle? Pestle is A PHP Framework for creating and organizing command line programs An experiment in implementing python style module imports

Alan Storm 526 Dec 5, 2022
An article about alternative solution for convert object into a JSON Object for your api.

Do we really need a serializer for our JSON API? The last years I did build a lot of JSON APIs but personally was never happy about the magic of using

Alexander Schranz 1 Feb 1, 2022
Engine for performing and rendering text diffs

Text_Diff Engine for performing and rendering text diffs This package provides a text-based diff engine and renderers for multiple diff output formats

PEAR - PHP Extension and Application Repository 15 Jan 4, 2022
Testing utilities for the psr/log package that backs the PSR-3 specification.

FIG - Log Test Testing utilities for the psr/log package that backs the PSR-3 specification. Psr\Log\Test\LoggerInterfaceTest provides a base test cla

PHP-FIG 3 Nov 19, 2022
Your alter ego object. Takes the best of object and array worlds.

Supporting Opensource formapro\values is an MIT-licensed open source project with its ongoing development made possible entirely by the support of com

FormaPro 31 Jun 25, 2021
PHP library that helps to map any input into a strongly-typed value object structure.

Valinor • PHP object mapper with strong type support Valinor is a PHP library that helps to map any input into a strongly-typed value object structure

Team CuyZ 873 Jan 7, 2023