Roughly modularize document rendering in Files
Summary: Ref T13105. This change begins modularizing document rendering. I'm starting in Files since it's the use case with the smallest amount of complexity. Currently, we hard-coding the inline rendering for images, audio, and video. Instead, use the modular engine pattern to make rendering flexible and extensible. There aren't any options for switching modes yet and none of the renderers do anything fancy. This API is also probably very unstable. Test Plan: Viewwed images, audio, video, and other files. Saw reasonable renderings, with "nothing can render this" for any other file type. Maniphest Tasks: T13105 Differential Revision: https://secure.phabricator.com/D19237
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
abstract class PhabricatorDocumentEngine
|
||||
extends Phobject {
|
||||
|
||||
private $viewer;
|
||||
|
||||
final public function setViewer(PhabricatorUser $viewer) {
|
||||
$this->viewer = $viewer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
final public function getViewer() {
|
||||
return $this->viewer;
|
||||
}
|
||||
|
||||
final public function canRenderDocument(PhabricatorDocumentRef $ref) {
|
||||
return $this->canRenderDocumentType($ref);
|
||||
}
|
||||
|
||||
abstract protected function canRenderDocumentType(
|
||||
PhabricatorDocumentRef $ref);
|
||||
|
||||
final public function newDocument(PhabricatorDocumentRef $ref) {
|
||||
return $this->newDocumentContent($ref);
|
||||
}
|
||||
|
||||
final public function newDocumentIcon(PhabricatorDocumentRef $ref) {
|
||||
return id(new PHUIIconView())
|
||||
->setIcon($this->getDocumentIconIcon($ref));
|
||||
}
|
||||
|
||||
abstract protected function newDocumentContent(
|
||||
PhabricatorDocumentRef $ref);
|
||||
|
||||
protected function getDocumentIconIcon(PhabricatorDocumentRef $ref) {
|
||||
return 'fa-file-o';
|
||||
}
|
||||
|
||||
final public function getDocumentEngineKey() {
|
||||
return $this->getPhobjectClassConstant('ENGINEKEY');
|
||||
}
|
||||
|
||||
final public static function getAllEngines() {
|
||||
return id(new PhutilClassMapQuery())
|
||||
->setAncestorClass(__CLASS__)
|
||||
->setUniqueMethod('getDocumentEngineKey')
|
||||
->execute();
|
||||
}
|
||||
|
||||
final public function newSortVector(PhabricatorDocumentRef $ref) {
|
||||
$content_score = $this->getContentScore($ref);
|
||||
|
||||
return id(new PhutilSortVector())
|
||||
->addInt(-$content_score);
|
||||
}
|
||||
|
||||
protected function getContentScore() {
|
||||
return 2000;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user