ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilUIMarkdownPreviewGUI Class Reference
+ Inheritance diagram for ilUIMarkdownPreviewGUI:
+ Collaboration diagram for ilUIMarkdownPreviewGUI:

Public Member Functions

 __construct ()
 
 executeCommand ()
 
 getAsyncUrl ()
 Returns an endpoint where the clientside input can submit it's value to and receive the current preview. More...
 
 getParameterName ()
 Returns the name of the $_POST variable the asynchronous input submits to. More...
 
 renderAsync ()
 Sends a JSON-response with the rendered preview of the submitted input. More...
 
 render (string $markdown_text)
 Returns the rendered preview of the given string. More...
 
 getAsyncUrl ()
 Returns an endpoint where the clientside input can submit it's value to and receive the current preview. More...
 
 getParameterName ()
 Returns the name of the $_POST variable the asynchronous input submits to. More...
 
 renderAsync ()
 Sends a JSON-response with the rendered preview of the submitted input. More...
 
 render (string $markdown_text)
 Returns the rendered preview of the given string. More...
 

Protected Member Functions

 sendResponse (string $html)
 

Protected Attributes

const CMD_RENDER_ASYNC = 'renderAsync'
 
Refinery $refinery
 
ilCtrlInterface $ctrl
 
HTTPServices $http
 

Detailed Description

Author
Thibeau Fuhrer thibe.nosp@m.au@s.nosp@m.r.sol.nosp@m.utio.nosp@m.ns @noinspection AutoloadingIssuesInspection

Definition at line 31 of file class.ilUIMarkdownPreviewGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilUIMarkdownPreviewGUI::__construct ( )

Definition at line 39 of file class.ilUIMarkdownPreviewGUI.php.

40 {
41 global $DIC;
42
43 $this->refinery = $DIC->refinery();
44 $this->ctrl = $DIC->ctrl();
45 $this->http = $DIC->http();
46 }
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilUIMarkdownPreviewGUI::executeCommand ( )

Definition at line 48 of file class.ilUIMarkdownPreviewGUI.php.

48 : void
49 {
50 if (!$this->ctrl->isAsynch() && self::CMD_RENDER_ASYNC !== $this->ctrl->getCmd()) {
51 $this->http->saveResponse(
52 $this->http
53 ->response()
54 ->withBody(Streams::ofString('Whoops, something went wrong!'))
55 ->withStatus(404)
56 );
57
58 $this->http->sendResponse();
59 $this->http->close();
60 }
61
62 $this->renderAsync();
63 }
renderAsync()
Sends a JSON-response with the rendered preview of the submitted input.

References ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), and renderAsync().

+ Here is the call graph for this function:

◆ getAsyncUrl()

ilUIMarkdownPreviewGUI::getAsyncUrl ( )

Returns an endpoint where the clientside input can submit it's value to and receive the current preview.

Note that ilCtrl does not return fully qualified URIs, therefore string is type-hinted.

Implements ILIAS\UI\Component\Input\Field\MarkdownRenderer.

Definition at line 65 of file class.ilUIMarkdownPreviewGUI.php.

65 : string
66 {
67 return $this->ctrl->getLinkTargetByClass(
68 self::class,
69 self::CMD_RENDER_ASYNC,
70 null,
71 true
72 );
73 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ getParameterName()

ilUIMarkdownPreviewGUI::getParameterName ( )

Returns the name of the $_POST variable the asynchronous input submits to.

Implements ILIAS\UI\Component\Input\Field\MarkdownRenderer.

Definition at line 75 of file class.ilUIMarkdownPreviewGUI.php.

75 : string
76 {
77 return 'raw_markdown';
78 }

Referenced by renderAsync().

+ Here is the caller graph for this function:

◆ render()

ilUIMarkdownPreviewGUI::render ( string  $markdown_text)

Returns the rendered preview of the given string.

Implements ILIAS\UI\Component\Input\Field\MarkdownRenderer.

Definition at line 96 of file class.ilUIMarkdownPreviewGUI.php.

96 : string
97 {
98 return $this->refinery->string()->markdown()->toHTML()->transform($markdown_text);
99 }

References ILIAS\Repository\refinery().

Referenced by renderAsync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderAsync()

ilUIMarkdownPreviewGUI::renderAsync ( )

Sends a JSON-response with the rendered preview of the submitted input.

Implements ILIAS\UI\Component\Input\Field\MarkdownRenderer.

Definition at line 80 of file class.ilUIMarkdownPreviewGUI.php.

80 : void
81 {
82 $parameter_name = $this->getParameterName();
83
84 if (!$this->http->wrapper()->post()->has($parameter_name)) {
85 $this->sendResponse('');
86 }
87
88 $raw_markdown = $this->http->wrapper()->post()->retrieve(
89 $parameter_name,
90 $this->refinery->to()->string()
91 );
92
93 $this->sendResponse($this->render($raw_markdown));
94 }
getParameterName()
Returns the name of the $_POST variable the asynchronous input submits to.
render(string $markdown_text)
Returns the rendered preview of the given string.

References getParameterName(), ILIAS\FileDelivery\http(), ILIAS\Repository\refinery(), render(), and sendResponse().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendResponse()

ilUIMarkdownPreviewGUI::sendResponse ( string  $html)
protected

Definition at line 101 of file class.ilUIMarkdownPreviewGUI.php.

101 : void
102 {
103 $this->http->saveResponse(
104 $this->http->response()->withBody(Streams::ofString($html))
105 );
106
107 $this->http->sendResponse();
108 $this->http->close();
109 }

References ILIAS\FileDelivery\http().

Referenced by renderAsync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl

ilCtrlInterface ilUIMarkdownPreviewGUI::$ctrl
protected

Definition at line 36 of file class.ilUIMarkdownPreviewGUI.php.

◆ $http

HTTPServices ilUIMarkdownPreviewGUI::$http
protected

Definition at line 37 of file class.ilUIMarkdownPreviewGUI.php.

◆ $refinery

Refinery ilUIMarkdownPreviewGUI::$refinery
protected

Definition at line 35 of file class.ilUIMarkdownPreviewGUI.php.

◆ CMD_RENDER_ASYNC

const ilUIMarkdownPreviewGUI::CMD_RENDER_ASYNC = 'renderAsync'
protected

Definition at line 33 of file class.ilUIMarkdownPreviewGUI.php.


The documentation for this class was generated from the following file: