Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions _internal/DeerLister.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

require_once "Icons.php";
require_once "ParsedownExtension.php";
namespace DeerLister;

use Twig\Loader\FilesystemLoader;
use Twig\Environment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once "FileDisplay.php";
namespace DeerLister\Displays;

/**
* Provides display for images
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace DeerLister\Displays;

interface FileDisplay
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once "FileDisplay.php";
namespace DeerLister\Displays;

/**
* Provides display for images
Expand Down
2 changes: 2 additions & 0 deletions _internal/Icons.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace DeerLister;

class Icons
{
private static $brands =
Expand Down
4 changes: 4 additions & 0 deletions _internal/ParsedownExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace DeerLister;

use Parsedown;

class ParsedownExtension extends Parsedown
{
private $title = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

require_once "FilePreview.php";
namespace DeerLister\Previews;

use Twig\Environment;

/**
* Provides previews for audios
Expand All @@ -12,7 +14,7 @@ public function doesHandle(string $filename, string $ext): bool
return in_array($ext, ["mp3", "wav", "ogg", "webm", "flac"]);
}

public function renderPreview(string $path, string $extension, Twig\Environment $twig): string
public function renderPreview(string $path, string $extension, Environment $twig): string
{
return $twig->render("previews/audio.html.twig", [ "path" => $path ]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

require_once "FilePreview.php";
namespace DeerLister\Previews;

use Twig\Environment;

/**
* Provides previews for code or text
Expand Down Expand Up @@ -49,7 +51,7 @@ public function doesHandle(string $filename, string $ext): bool
return in_array($ext, self::EXTENSIONS);
}

public function renderPreview(string $path, string $extension, Twig\Environment $twig): string
public function renderPreview(string $path, string $extension, Environment $twig): string
{
if (in_array($extension, [ "txt", "log", "def", "csv", "tsv" ])) $extension = "plaintext";
else if (in_array($extension, [ "csproj", "vcxproj", "pom" ])) $extension = "xml";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace DeerLister\Previews;

use Twig\Environment;

interface FilePreview
{
/**
Expand All @@ -17,9 +21,9 @@ public function doesHandle(string $filename, string $ext): bool;
*
* @param string $path The relative path to the file
* @param string $extension The file extension without leading dot
* @param Twig\Environment $twig Instance of twig which can be used to render the file preview
* @param Environment $twig Instance of twig which can be used to render the file preview
*
* @return string The file preview content
*/
public function renderPreview(string $path, string $extension, Twig\Environment $twig): string;
public function renderPreview(string $path, string $extension, Environment $twig): string;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

require_once "FilePreview.php";
namespace DeerLister\Previews;

use Twig\Environment;

/**
* Provides previews for images
Expand All @@ -12,7 +14,7 @@ public function doesHandle(string $filename, string $ext): bool
return in_array($ext, ["apng", "png", "jpg", "jpeg", "gif", "svg", "webp"]);
}

public function renderPreview(string $path, string $extension, Twig\Environment $twig): string
public function renderPreview(string $path, string $extension, Environment $twig): string
{
return $twig->render("previews/image.html.twig", [ "path" => $path ]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

require_once "FilePreview.php";
namespace DeerLister\Previews;

use DeerLister\ParsedownExtension;
use Twig\Environment;

/**
* Provides previews for markdown
Expand All @@ -12,7 +15,7 @@ public function doesHandle(string $filename, string $ext): bool
return in_array($ext, ["md"]);
}

public function renderPreview(string $path, string $extension, Twig\Environment $twig): string
public function renderPreview(string $path, string $extension, Environment $twig): string
{
$parsedown = new ParsedownExtension();
$parsedown->setSafeMode(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

require_once "FilePreview.php";
namespace DeerLister\Previews;

use Twig\Environment;

/**
* Provides previews for PDF
Expand All @@ -12,7 +14,7 @@ public function doesHandle(string $filename, string $ext): bool
return in_array($ext, ["pdf"]);
}

public function renderPreview(string $path, string $extension, Twig\Environment $twig): string
public function renderPreview(string $path, string $extension, Environment $twig): string
{
return $twig->render("previews/pdf.html.twig", [ "path" => $path ]);
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

require_once "FilePreview.php";
namespace DeerLister\Previews;

use Twig\Environment;

/**
* Provides previews for videos
Expand All @@ -12,7 +14,7 @@ public function doesHandle(string $filename, string $ext): bool
return in_array($ext, ["mp4", "webm"]);
}

public function renderPreview(string $path, string $extension, Twig\Environment $twig): string
public function renderPreview(string $path, string $extension, Environment $twig): string
{
return $twig->render("previews/video.html.twig", [ "path" => $path ]);
}
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
"twig/twig": "^3.0",
"erusev/parsedown": "^1.7",
"yosymfony/toml": "^1.0"
},
"autoload": {
"psr-4": {
"DeerLister\\": "_internal/"
}
}
}
26 changes: 10 additions & 16 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
<?php

use DeerLister\DeerLister;
use DeerLister\Displays\AudioDisplay;
use DeerLister\Displays\ImageDisplay;
use DeerLister\Previews\AudioPreview;
use DeerLister\Previews\CodePreview;
use DeerLister\Previews\ImagePreview;
use DeerLister\Previews\MarkdownPreview;
use DeerLister\Previews\PdfPreview;
use DeerLister\Previews\VideoPreview;

require_once "vendor/autoload.php";
require_once "_internal/DeerLister.php";

// autoload previews
spl_autoload_register(function($class) {
$filePreview = "_internal/previews/" . $class . ".php";
$fileDisplay = "_internal/displays/" . $class . ".php";

if (file_exists($filePreview))
{
include $filePreview;
}
else if (file_exists($fileDisplay))
{
include $fileDisplay;
}
});

$lister = new DeerLister();

Expand Down