mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Provide a concrete class for one-off remarkup blocks
Summary: I want to use some of these for instructional text in Diffusion. Provide a concrete class to make one-offs cacheable and switch Releeph to use it. Test Plan: {F44175} Reviewers: btrahan, chad, edward Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D6032
This commit is contained in:
parent
2fd018ad92
commit
1430c2c449
4 changed files with 116 additions and 91 deletions
|
@ -1113,6 +1113,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorMarkupCache' => 'applications/cache/storage/PhabricatorMarkupCache.php',
|
||||
'PhabricatorMarkupEngine' => 'infrastructure/markup/PhabricatorMarkupEngine.php',
|
||||
'PhabricatorMarkupInterface' => 'infrastructure/markup/PhabricatorMarkupInterface.php',
|
||||
'PhabricatorMarkupOneOff' => 'infrastructure/markup/PhabricatorMarkupOneOff.php',
|
||||
'PhabricatorMenuItemView' => 'view/layout/PhabricatorMenuItemView.php',
|
||||
'PhabricatorMenuView' => 'view/layout/PhabricatorMenuView.php',
|
||||
'PhabricatorMenuViewTestCase' => 'view/layout/__tests__/PhabricatorMenuViewTestCase.php',
|
||||
|
@ -2890,6 +2891,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorManiphestConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorManiphestTaskTestDataGenerator' => 'PhabricatorTestDataGenerator',
|
||||
'PhabricatorMarkupCache' => 'PhabricatorCacheDAO',
|
||||
'PhabricatorMarkupOneOff' => 'PhabricatorMarkupInterface',
|
||||
'PhabricatorMenuItemView' => 'AphrontTagView',
|
||||
'PhabricatorMenuView' => 'AphrontTagView',
|
||||
'PhabricatorMenuViewTestCase' => 'PhabricatorTestCase',
|
||||
|
@ -3558,7 +3560,6 @@ phutil_register_library_map(array(
|
|||
'ReleephBranchEditor' => 'PhabricatorEditor',
|
||||
'ReleephBranchNamePreviewController' => 'PhabricatorController',
|
||||
'ReleephBranchPreviewView' => 'AphrontFormControl',
|
||||
'ReleephBranchTemplate' => 'PhabricatorMarkupInterface',
|
||||
'ReleephBranchViewController' => 'ReleephController',
|
||||
'ReleephCommitFinderException' => 'Exception',
|
||||
'ReleephCommitMessageFieldSpecification' => 'ReleephFieldSpecification',
|
||||
|
|
|
@ -252,15 +252,10 @@ final class ReleephProjectEditController extends ReleephController {
|
|||
$commit_author_inset = $this->buildCommitAuthorInset($commit_author);
|
||||
|
||||
// Build the Template inset
|
||||
$help_markup = phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
'class' => 'phabricator-remarkup',
|
||||
),
|
||||
PhabricatorMarkupEngine::renderOneObject(
|
||||
new ReleephBranchTemplate(),
|
||||
'field',
|
||||
$request->getUser()));
|
||||
$help_markup = PhabricatorMarkupEngine::renderOneObject(
|
||||
id(new PhabricatorMarkupOneOff())->setContent($this->getBranchHelpText()),
|
||||
'default',
|
||||
$request->getUser());
|
||||
|
||||
$branch_template_input = id(new AphrontFormTextControl())
|
||||
->setName('branchTemplate')
|
||||
|
@ -384,4 +379,55 @@ EOTEXT
|
|||
->appendChild($control);
|
||||
}
|
||||
|
||||
private function getBranchHelpText() {
|
||||
return <<<EOTEXT
|
||||
|
||||
==== Interpolations ====
|
||||
|
||||
| Code | Meaning
|
||||
| ----- | -------
|
||||
| `%P` | The name of your project, with spaces changed to "-".
|
||||
| `%p` | Like %P, but all lowercase.
|
||||
| `%Y` | The four digit year associated with the branch date.
|
||||
| `%m` | The two digit month.
|
||||
| `%d` | The two digit day.
|
||||
| `%v` | The handle of the commit where the branch was cut ("rXYZa4b3c2d1").
|
||||
| `%V` | The abbreviated commit id where the branch was cut ("a4b3c2d1").
|
||||
| `%..` | Any other sequence interpreted by `strftime()`.
|
||||
| `%%` | A literal percent sign.
|
||||
|
||||
|
||||
==== Tips for Branch Templates ====
|
||||
|
||||
Use a directory to separate your release branches from other branches:
|
||||
|
||||
lang=none
|
||||
releases/%Y-%M-%d-%v
|
||||
=> releases/2012-30-16-rHERGE32cd512a52b7
|
||||
|
||||
Include a second hierarchy if you share your repository with other projects:
|
||||
|
||||
lang=none
|
||||
releases/%P/%p-release-%Y%m%d-%V
|
||||
=> releases/Tintin/tintin-release-20121116-32cd512a52b7
|
||||
|
||||
Keep your branch names simple, avoiding strange punctuation, most of which is
|
||||
forbidden or escaped anyway:
|
||||
|
||||
lang=none, counterexample
|
||||
releases//..clown-releases..//`date --iso=seconds`-$(sudo halt)
|
||||
|
||||
Include the date early in your template, in an order which sorts properly:
|
||||
|
||||
lang=none
|
||||
releases/%Y%m%d-%v
|
||||
=> releases/20121116-rHERGE32cd512a52b7 (good!)
|
||||
|
||||
releases/%V-%m.%d.%Y
|
||||
=> releases/32cd512a52b7-11.16.2012 (awful!)
|
||||
|
||||
|
||||
EOTEXT;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class ReleephBranchTemplate
|
||||
implements PhabricatorMarkupInterface {
|
||||
final class ReleephBranchTemplate {
|
||||
|
||||
const KEY = 'releeph.default-branch-template';
|
||||
|
||||
|
@ -186,83 +185,4 @@ final class ReleephBranchTemplate
|
|||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/* -( Help Text and Markup Interface )------------------------------------- */
|
||||
|
||||
public function getMarkupFieldKey($field) {
|
||||
$text = $this->getMarkupText($field);
|
||||
return sprintf(
|
||||
'%s:%s',
|
||||
get_class($this),
|
||||
PhabricatorHash::digest($text));
|
||||
}
|
||||
|
||||
public function newMarkupEngine($field) {
|
||||
return PhabricatorMarkupEngine::newDifferentialMarkupEngine();
|
||||
}
|
||||
|
||||
public function didMarkupText(
|
||||
$field,
|
||||
$output,
|
||||
PhutilMarkupEngine $engine) {
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function shouldUseMarkupCache($field) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getMarkupText($field) {
|
||||
return <<<EOTEXT
|
||||
|
||||
==== Interpolations ====
|
||||
|
||||
| Code | Meaning
|
||||
| ----- | -------
|
||||
| `%P` | The name of your project, with spaces changed to "-".
|
||||
| `%p` | Like %P, but all lowercase.
|
||||
| `%Y` | The four digit year associated with the branch date.
|
||||
| `%m` | The two digit month.
|
||||
| `%d` | The two digit day.
|
||||
| `%v` | The handle of the commit where the branch was cut ("rXYZa4b3c2d1").
|
||||
| `%V` | The abbreviated commit id where the branch was cut ("a4b3c2d1").
|
||||
| `%..` | Any other sequence interpreted by `strftime()`.
|
||||
| `%%` | A literal percent sign.
|
||||
|
||||
|
||||
==== Tips for Branch Templates ====
|
||||
|
||||
Use a directory to separate your release branches from other branches:
|
||||
|
||||
lang=none
|
||||
releases/%Y-%M-%d-%v
|
||||
=> releases/2012-30-16-rHERGE32cd512a52b7
|
||||
|
||||
Include a second hierarchy if you share your repository with other projects:
|
||||
|
||||
lang=none
|
||||
releases/%P/%p-release-%Y%m%d-%V
|
||||
=> releases/Tintin/tintin-release-20121116-32cd512a52b7
|
||||
|
||||
Keep your branch names simple, avoiding strange punctuation, most of which is
|
||||
forbidden or escaped anyway:
|
||||
|
||||
lang=none, counterexample
|
||||
releases//..clown-releases..//`date --iso=seconds`-$(sudo halt)
|
||||
|
||||
Include the date early in your template, in an order which sorts properly:
|
||||
|
||||
lang=none
|
||||
releases/%Y%m%d-%v
|
||||
=> releases/20121116-rHERGE32cd512a52b7 (good!)
|
||||
|
||||
releases/%V-%m.%d.%Y
|
||||
=> releases/32cd512a52b7-11.16.2012 (awful!)
|
||||
|
||||
|
||||
EOTEXT
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
58
src/infrastructure/markup/PhabricatorMarkupOneOff.php
Normal file
58
src/infrastructure/markup/PhabricatorMarkupOneOff.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Concrete object for accessing the markup engine with arbitrary blobs of
|
||||
* text, like form instructions. Usage:
|
||||
*
|
||||
* $output = PhabricatorMarkupEngine::renderOneObject(
|
||||
* id(new PhabricatorMarkupOneOff())->setContent($some_content),
|
||||
* 'default',
|
||||
* $viewer);
|
||||
*
|
||||
* This is less efficient than batching rendering, but appropriate for small
|
||||
* amounts of one-off text in form instructions.
|
||||
*/
|
||||
final class PhabricatorMarkupOneOff implements PhabricatorMarkupInterface {
|
||||
|
||||
private $content;
|
||||
|
||||
public function setContent($content) {
|
||||
$this->content = $content;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContent() {
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function getMarkupFieldKey($field) {
|
||||
return PhabricatorHash::digestForIndex($this->getContent()).':oneoff';
|
||||
}
|
||||
|
||||
public function newMarkupEngine($field) {
|
||||
return PhabricatorMarkupEngine::newMarkupEngine(array());
|
||||
}
|
||||
|
||||
public function getMarkupText($field) {
|
||||
return $this->getContent();
|
||||
}
|
||||
|
||||
public function didMarkupText(
|
||||
$field,
|
||||
$output,
|
||||
PhutilMarkupEngine $engine) {
|
||||
|
||||
require_celerity_resource('phabricator-remarkup-css');
|
||||
return phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
'class' => 'phabricator-remarkup',
|
||||
),
|
||||
$output);
|
||||
}
|
||||
|
||||
public function shouldUseMarkupCache($field) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue