davidepastore/slim-markdown-view

Render PHP view scripts into a PSR-7 Response object.

v0.1.1 2016-08-12 19:20 UTC

This package is auto-updated.

Last update: 2024-03-26 06:41:09 UTC


README

Latest version Build Status Coverage Status Quality Score Total Downloads PSR2 Conformance

A renderer for rendering Markdown into a PSR-7 Response object. It works well with Slim Framework 3.

Installation

Install with Composer:

composer require davidepastore/slim-markdown-view

Usage With Slim 3

use \DavidePastore\Slim\Views\MarkdownRenderer;

include "vendor/autoload.php";

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

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

$app->run();

Usage with any PSR-7 Project

//Construct the View
$markdownView = new MarkdownRenderer("./path/to/templates");

//Render a file
$response = $markdownView->render(new Response(), "/path/to/template.md");

Custom Parsedown instance

//Construct the View
$parsedown = Parsedown::instance()->setUrlsLinked(false);
$markdownView = new MarkdownRenderer("./path/to/templates", $parsedown);

//Render a file
$response = $markdownView->render(new Response(), "/path/to/template.md");

Exceptions

\RuntimeException - if template does not exist

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits