Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
Implement redact component
Browse files Browse the repository at this point in the history
  • Loading branch information
hxtree committed Feb 5, 2020
1 parent 909041f commit 5f8b647
Show file tree
Hide file tree
Showing 20 changed files with 5,593 additions and 4,070 deletions.
9,427 changes: 5,478 additions & 3,949 deletions docs/diagrams/Class Diagram.mdj

Large diffs are not rendered by default.

Binary file modified docs/diagrams/Class Diagram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LivingMarkup loads markup to instantiate objects, call their methods, and return

## Overview
1. A `Director` object and a `Builder` object are instantiated.
2. The `Director` is passed a `Builder` object and an array of parameters defining the `Page` build, including:
2. The `Director` is passed a `Builder` object and an array of parameters defining the `Engine` build, including:
- A `filename` string containing the URL or filepath to a XML or HTML document that will be inputted into the `Builder`.
- A `handlers` array. Each `handler` must contain both Xpath expressions, which is used to lookup elements, and class
name that is used to determine how that element once found will be instantiated as a Component.
Expand All @@ -38,8 +38,8 @@ document.
## `Builder`
The Builder receives parameters passed from the Director and uses them to instantiate and return a Page object.

## `Page`
The Page loads a DOM object and uses Handlers and Hooks to instantiate Components and modify the DOM.
## `Engine`
The Engine loads a DOM object and uses Handlers and Hooks to instantiate Components and modify the DOM.

### `Handlers`
A Handler consists of an XPath expressions and a class name and is used to define the Component.
Expand Down
2 changes: 1 addition & 1 deletion examples/DynamicPageExample/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'//widget' => 'LivingMarkup\Component\Widgets\{name}',
'//var' => 'LivingMarkup\Component\Variable',
'//condition' => 'LivingMarkup\Component\Condition',
'//redacted' => 'LivingMarkup\Component\Redacted'
'//redact' => 'LivingMarkup\Component\Redact'
],
'hooks' => [
'beforeLoad' => 'Executed before onLoad',
Expand Down
11 changes: 0 additions & 11 deletions examples/DynamicPageExample/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,5 @@ <h1>Test Site</h1>
<div class="main-content">
<p>This is a demonstration of LivingMarkup.</p>
</div>
<div>
<partial name="UserMenu"> <arg name="type">Sponge</arg> </partial>
The password is <redacted>Salted Leafs</redacted>, but that's okay.

<widget name="News" id="4522">
<arg name="heading">Latest News</arg>
<arg name="heading_level">3</arg>
</widget>

</div>
<footer />
</body>
</html>
9 changes: 0 additions & 9 deletions examples/DynamicPageExample/output.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,5 @@
<body>
<partial name="Breadcrumb"></partial><h1>Test Site</h1>
<div class="main-content"><p>This is a demonstration of LivingMarkup.</p></div>
<div>
<partial name="UserMenu"><arg name="type">Sponge</arg></partial>
The password is &#9608;&#9608;&#9608;&#9608;&#9608;&#9608;&#9608;&#9608;&#9608;&#9608;&#9608;&#9608;, but that's okay.

<!-- widget #4522-->
<h3>Latest News</h3>

</div>
<footer></footer>
</body>
</html>
43 changes: 14 additions & 29 deletions examples/ImgExample/index.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
<?php
/**
* This file is part of the LivingMarkup package.
*
* (c) Matthew Heroux <matthewheroux@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
<?php require $_SERVER['DOCUMENT_ROOT'] . '/src/Autoloader.php'; ?>
<!--
~ This file is part of the LivingMarkup package.
~
~ (c) Matthew Heroux <matthewheroux@gmail.com>
~
~ For the full copyright and license information, please view the LICENSE
~ file that was distributed with this source code.
-->

require '../../vendor/autoload.php';
<html lang="en">

// instantiate Director
$director = new LivingMarkup\Director();

// instantiate Builder
$builder = new LivingMarkup\Builder\DynamicPageBuilder();

// define build parameters
$parameters = [
'filename' => __DIR__ . DIRECTORY_SEPARATOR . 'input.html',
'handlers' => [
'//img' => 'LivingMarkup\Component\Img',
],
'hooks' => [
'onRender' => 'RETURN_CALL',
]
];

// echo Director build PageBuilder
echo $director->build($builder, $parameters);
<body>
<img src="livingMarkup_icon_logo.jpg" height="100" width="300" offset="100,-100" alt="Chicken Finger 12" />
</body>
</html>
15 changes: 0 additions & 15 deletions examples/ImgExample/input.html

This file was deleted.

9 changes: 0 additions & 9 deletions examples/ImgExample/output.html

This file was deleted.

2 changes: 1 addition & 1 deletion examples/IncludeHeaderExample/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<html>
<header></header>
<p>Welcome</p>
<p>I'm a <redacted>web developer</redacted></p>
<p>I'm a <redact>web developer</redact></p>
</html>
45 changes: 45 additions & 0 deletions examples/RedactExample/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php require $_SERVER['DOCUMENT_ROOT'] . '/src/Autoloader.php'; ?>
<html>
<p>Praesent ullamcorper eros nec neque luctus, sed sodales risus euismod. Proin consectetur elementum urna at feugiat.
Vivamus porttitor vulputate orci id consequat. Phasellus ut dui sagittis, elementum ante a, rutrum velit. Duis
mollis feugiat purus nec porttitor.
<redact>
Nulla tempor nunc et libero malesuada, mattis rutrum odio euismod. Proin commodo ligula luctus justo
viverra feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut purus mollis, feugiat massa
mollis, placerat purus.
</redact>
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas vitae
bibendum libero. Sed lacus ex, ornare non ligula dignissim, tincidunt ultrices mauris. Aliquam ac facilisis magna.
Vivamus blandit pretium finibus.
</p>

<redact>
<p>Donec ultricies rutrum nulla, vitae tempor ex porttitor nec. Donec nec sem metus. Nunc leo magna, pulvinar
non tellus vel, tincidunt consectetur sem. Nulla tempor mauris at quam imperdiet rutrum. Pellentesque habitant
morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus at gravida sem. Quisque blandit,
magna vel ultrices faucibus, felis elit rhoncus eros, vel tempus elit nulla non orci. Cras arcu elit,
pellentesque sed mollis nec, porttitor ut est. Ut elit orci, fringilla et commodo sed, tincidunt vehicula nisl.
Suspendisse vitae dolor eget tellus maximus ornare. Nulla non vestibulum est.</p>

<p>
Quisque mauris tortor, varius sit amet massa non, molestie congue dui. Nulla facilisi. Proin ac dolor fermentum
nisi elementum maximus. Donec nec odio vitae magna ultricies luctus vel id diam. Suspendisse venenatis <b>congue
ultricies<?php echo 'PASSWORD'; ?></b>. Pellentesque non ex elementum, dapibus ipsum eu, feugiat arcu.
Phasellus efficitur commodo ante vulputate aliquam. Sed posuere pulvinar quam, in elementum risus tristique a.
Nullam dictum arcu eu mi lobortis, sodales tempor dolor fringilla. Nulla feugiat mollis nisl, non vulputate
augue efficitur non. Nulla ac facilisis nisl, ac iaculis neque.
</p>
</redact>

<p>
Pellentesque scelerisque pharetra justo quis gravida. Cras mattis dui eu finibus luctus. Mauris non condimentum
purus. Suspendisse suscipit elementum nunc, a iaculis erat posuere vel. Quisque mattis gravida ipsum non tincidunt.
Sed ut posuere justo. Ut elementum ullamcorper ligula, ac lacinia nibh facilisis nec. Donec eu suscipit risus. Sed
arcu leo, ultrices id mollis ut, consectetur in lectus. Aenean a sollicitudin odio. Nam rhoncus mattis mauris et
commodo. Cras fringilla, est eget volutpat facilisis, dolor mauris porttitor mi, eget ullamcorper eros lectus sit
amet risus. Morbi vel magna eu odio auctor maximus sed ut ante. Maecenas commodo enim in
<redact>dui feugiat</redact>
sollicitudin.
</p>

</html>
7 changes: 6 additions & 1 deletion src/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
* file that was distributed with this source code.
*/


ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use LivingMarkup\Component\Component;

require '../../vendor/autoload.php';
Expand All @@ -29,7 +34,7 @@ function call_director($buffer)
'//a' => 'LivingMarkup\Component\A',
'//var' => 'LivingMarkup\Component\Variable',
'//condition' => 'LivingMarkup\Component\Condition',
'//redacted' => 'LivingMarkup\Component\Redacted'
'//redact' => 'LivingMarkup\Component\Redact'
],
'hooks' => [
'beforeLoad' => 'Executed before onLoad',
Expand Down
9 changes: 4 additions & 5 deletions src/Builder/DynamicPageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class DynamicPageBuilder implements BuilderInterface
*/
public function createObject(array $parameters): ?bool
{
// determine source
if (isset($parameters['filename'])) {
// set source
if (array_key_exists('filename', $parameters)) {
$source = file_get_contents($parameters['filename']);
} elseif (isset($parameters['markup'])) {
} elseif (array_key_exists('markup', $parameters)) {
$source = $parameters['markup'];
} else {
$source = '';
Expand All @@ -47,7 +47,6 @@ public function createObject(array $parameters): ?bool
}
}


// call hooks
if (is_array($parameters['hooks'])) {
foreach ($parameters['hooks'] as $name => $description) {
Expand All @@ -67,4 +66,4 @@ public function getObject(): ?object
{
return $this->engine;
}
}
}
6 changes: 3 additions & 3 deletions src/Builder/StaticPageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class StaticPageBuilder implements BuilderInterface
*/
public function createObject(array $parameters): ?bool
{
// determine source
if (isset($parameters['filename'])) {
// set source
if (array_key_exists('filename', $parameters)) {
$source = file_get_contents($parameters['filename']);
} elseif (isset($parameters['markup'])) {
} elseif (array_key_exists('markup', $parameters)) {
$source = $parameters['markup'];
} else {
$source = '';
Expand Down
30 changes: 30 additions & 0 deletions src/Component/Redact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the LivingMarkup package.
*
* (c) Matthew Heroux <matthewheroux@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace LivingMarkup\Component;

class Redact extends Component
{
public $char = '&#9608;';

// TODO: same sort of class would be useful for a search / highlighter function.

/**
* Renders with chars not between tag replaced with $char
*
* a black and white list of tags must consider redact element may be between tags
*
* @return string
*/
public function onRender(): string
{
return preg_replace("/<[^>]+>(*SKIP)(*F)|./", $this->char, $this->xml);
}
}
24 changes: 0 additions & 24 deletions src/Component/Redacted.php

This file was deleted.

1 change: 1 addition & 0 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function createDom(string $source): void

// create document iterator for this dom
$this->xpath = new DOMXPath($this->dom);

}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/DirectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testCanBuildPage()
'//a' => 'LivingMarkup\Component\A',
'//var' => 'LivingMarkup\Component\Variable',
'//condition' => 'LivingMarkup\Component\Condition',
'//redacted' => 'LivingMarkup\Component\Redacted'
'//redact' => 'LivingMarkup\Component\Redact'
],
'hooks' => [
'beforeLoad' => 'Executed before onLoad',
Expand All @@ -46,4 +46,4 @@ public function testCanBuildPage()
// TODO: assure this is correct class
$this->assertInstanceOf(Engine::class, $new_page);
}
}
}
11 changes: 4 additions & 7 deletions tests/ExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace LivingMarkup\Tests;

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

use PHPUnit\Framework\TestCase;
use LivingMarkup\Builder\DynamicPageBuilder;
use LivingMarkup\Builder\StaticPageBuilder;
Expand All @@ -34,7 +29,9 @@ final class ExamplesTest extends TestCase
{
private $excluded_examples = [
'HeadAndFooterExample',
'IncludeHeaderExample'
'IncludeHeaderExample',
'ImgExample',
'RedactExample'
];

public function test()
Expand All @@ -59,7 +56,7 @@ public function test()
'//a' => 'LivingMarkup\Component\A',
'//var' => 'LivingMarkup\Component\Variable',
'//condition' => 'LivingMarkup\Component\Condition',
'//redacted' => 'LivingMarkup\Component\Redacted'
'//redact' => 'LivingMarkup\Component\Redact'
],
'hooks' => [
'beforeLoad' => 'Executed before onLoad',
Expand Down
2 changes: 1 addition & 1 deletion tests/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1>Test Site</h1>
</p>
<partial name="UserMenu"> <arg name="type">Sponge</arg> </partial>
The password is
<redacted>Salted Leafs</redacted>
<redact>Salted Leafs</redact>
, but that's okay.


Expand Down

0 comments on commit 5f8b647

Please sign in to comment.