-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove renderers and rename the Slack facade to Kit (#17)
- Loading branch information
1 parent
cac66f1
commit 6e1f7ee
Showing
24 changed files
with
235 additions
and
464 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jeremeamia\Slack\BlockKit; | ||
|
||
use Jeremeamia\Slack\BlockKit\Surfaces; | ||
|
||
use function rawurlencode; | ||
|
||
abstract class Kit | ||
{ | ||
public static function newAppHome(): Surfaces\AppHome | ||
{ | ||
return new Surfaces\AppHome(); | ||
} | ||
|
||
public static function newMessage(): Surfaces\Message | ||
{ | ||
return new Surfaces\Message(); | ||
} | ||
|
||
public static function newModal(): Surfaces\Modal | ||
{ | ||
return new Surfaces\Modal(); | ||
} | ||
|
||
public static function preview(Surfaces\Surface $surface): string | ||
{ | ||
if ($surface instanceof Surfaces\Message) { | ||
// Block Kit Builder doesn't support message directives. | ||
$surface->directives([]); | ||
} elseif ($surface instanceof Surfaces\Attachment) { | ||
// Block Kit Builder can only show an attachment within a message. | ||
$surface = self::newMessage()->addAttachment($surface); | ||
} elseif ($surface instanceof Surfaces\WorkflowStep) { | ||
throw new Exception('The "workflow_step" surface is not compatible with Block Kit Builder'); | ||
} | ||
|
||
$encoded = str_replace(['%22', '%3A'], ['"', ':'], rawurlencode($surface->toJson())); | ||
|
||
return "https://app.slack.com/block-kit-builder#{$encoded}"; | ||
} | ||
} |
Oops, something went wrong.