From 1341c8a6c1100d5be83120f888fb84bf152382b3 Mon Sep 17 00:00:00 2001 From: Lauri-Henrik Jalonen Date: Wed, 13 Mar 2013 06:44:27 -0700 Subject: [PATCH] Paste embeds look super cool Summary: Make Paste embeds look super cool Test Plan: {F35387} Reviewers: epriestley CC: aran, Korvin, chad, btrahan, AnhNhan Maniphest Tasks: T1770 Differential Revision: https://secure.phabricator.com/D5323 --- src/__celerity_resource_map__.php | 9 ++++ src/__phutil_library_map__.php | 2 + .../remarkup/PhabricatorPasteRemarkupRule.php | 9 ++++ .../paste/view/PasteEmbedView.php | 54 +++++++++++++++++++ webroot/rsrc/css/application/paste/paste.css | 20 +++++++ 5 files changed, 94 insertions(+) create mode 100644 src/applications/paste/view/PasteEmbedView.php create mode 100644 webroot/rsrc/css/application/paste/paste.css diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index ef2496b135..a7ee838e13 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -2644,6 +2644,15 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/css/application/owners/owners-path-editor.css', ), + 'paste-css' => + array( + 'uri' => '/res/5081cf13/rsrc/css/application/paste/paste.css', + 'type' => 'css', + 'requires' => + array( + ), + 'disk' => '/rsrc/css/application/paste/paste.css', + ), 'path-typeahead' => array( 'uri' => '/res/50246fb6/rsrc/js/application/herald/PathTypeahead.js', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index cdda45de05..f5eab22184 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -637,6 +637,7 @@ phutil_register_library_map(array( 'PackageDeleteMail' => 'applications/owners/mail/PackageDeleteMail.php', 'PackageMail' => 'applications/owners/mail/PackageMail.php', 'PackageModifyMail' => 'applications/owners/mail/PackageModifyMail.php', + 'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php', 'Phabricator404Controller' => 'applications/base/controller/Phabricator404Controller.php', 'PhabricatorAWSConfigOptions' => 'applications/config/option/PhabricatorAWSConfigOptions.php', 'PhabricatorAccessLog' => 'infrastructure/PhabricatorAccessLog.php', @@ -2159,6 +2160,7 @@ phutil_register_library_map(array( 'PackageDeleteMail' => 'PackageMail', 'PackageMail' => 'PhabricatorMail', 'PackageModifyMail' => 'PackageMail', + 'PasteEmbedView' => 'AphrontView', 'Phabricator404Controller' => 'PhabricatorController', 'PhabricatorAWSConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorAccessLogConfigOptions' => 'PhabricatorApplicationConfigOptions', diff --git a/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php b/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php index 47f37ddcb5..c7c88dd7a2 100644 --- a/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php +++ b/src/applications/paste/remarkup/PhabricatorPasteRemarkupRule.php @@ -16,8 +16,17 @@ final class PhabricatorPasteRemarkupRule return id(new PhabricatorPasteQuery()) ->setViewer($viewer) ->withIDs($ids) + ->needContent(true) ->execute(); } + protected function renderObjectEmbed($object, $handle, $options) { + $embed_paste = id(new PasteEmbedView()) + ->setPaste($object) + ->setHandle($handle); + + return $embed_paste->render(); + + } } diff --git a/src/applications/paste/view/PasteEmbedView.php b/src/applications/paste/view/PasteEmbedView.php new file mode 100644 index 0000000000..de7825ecc3 --- /dev/null +++ b/src/applications/paste/view/PasteEmbedView.php @@ -0,0 +1,54 @@ +paste = $paste; + return $this; + } + + public function setHandle(PhabricatorObjectHandle $handle) { + $this->handle = $handle; + return $this; + } + + public function render() { + if (!$this->paste) { + throw new Exception("Call setPaste() before render()!"); + } + + $lines = phutil_split_lines($this->paste->getContent()); + require_celerity_resource('paste-css'); + + $link = phutil_tag( + 'a', + array( + 'href' => '/P'.$this->paste->getID() + ), + $this->handle->getFullName()); + + $head = phutil_tag( + 'div', + array( + 'class' => 'paste-embed-head' + ), + $link); + + $body = phutil_tag( + 'div', + array(), + id(new PhabricatorSourceCodeView()) + ->setLines($lines)); + + return phutil_tag( + 'div', + array( + 'class' => 'paste-embed' + ), + array($head, $body)); + + } +} diff --git a/webroot/rsrc/css/application/paste/paste.css b/webroot/rsrc/css/application/paste/paste.css new file mode 100644 index 0000000000..92e86d0c28 --- /dev/null +++ b/webroot/rsrc/css/application/paste/paste.css @@ -0,0 +1,20 @@ +/** + * @provides paste-css + */ + +.paste-embed { + display: inline-block; + padding: 5px; + background: #f7f7f7; +} + +.paste-embed-head { + border-bottom: 1px solid #3d3d3d; + padding: 2px; + margin:2px; +} + +.paste-embed-head a { + color: #282828; + font-weight: bold; +}