Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Aug 9, 2022
1 parent 76ed5f3 commit 7196737
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 57 deletions.
10 changes: 10 additions & 0 deletions docs/usage/framework-agnostic-php.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ ray()->image('data:image/png;base64,iVBORw0KGgoAAA...truncated');
ray()->image('iVBORw0KGgoAAA...truncated');
```

### Displaying a link

You can render a clickable link in Ray, by using the `link` (or `url`) methods.

```php
ray()->link('spatie.be'); // we'll assume that you meant `https://spatie.be`
ray()->link('spatie.be', 'Spatie homepage'); // optionally, you can pass a label
ray()->url('myray.app'); // `url` is an alias of `link`
```

### Rendering HTML

To render a piece of HTML directly in Ray, you can use the `html` method.
Expand Down
115 changes: 59 additions & 56 deletions docs/usage/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,62 +31,65 @@ To display something in Ray use the `ray()` function. It accepts everything: str

## Framework agnostic PHP

| Call | Description |
| --- | --- |
| `ray($variable)` | Display a string, array or object |
| `ray($variable, $another, …)` | Ray accepts multiple arguments |
| `ray()->backtrace()` | Check entire backtrace |
| `ray(…)->blue()` | Output in blue |
| `ray()->caller()` | Discover where code is being called |
| `ray()->carbon($carbon)` | Send `Carbon` instances to Ray |
| `ray($callable)->catch([$callable, $classname, …])` | Handle any exceptions encountered by `try` |
| `ray()->className($object)` | Send the classname of an object to Ray |
| `ray()->clearScreen()` | Clear current screen |
| `ray()->clearAll()` | Clear current and all previous screens |
| `ray()->count()` | Count how many times a piece of code is called |
| `ray()->counterValue(name)` | Return the value of a named counter |
| `ray(…)->die()` or `rd(…)` | Stop the PHP process |
| `ray()->disable()` | Disable sending stuff to Ray |
| `ray()->disabled()` | Check if Ray is disabled |
| `ray()->enable()` | Enable sending stuff to Ray |
| `ray()->enabled()` | Check if Ray is enabled |
| `ray()->exception($e)` | Display information about an Exception |
| `ray()->file($path)` | Display contents of a file |
| `ray(…)->gray()` | Output in gray |
| `ray(…)->green()` | Output in green |
| `ray(…)->hide()` | Display something in Ray and make it collapse immediately |
| `ray()->hideApp()` | Hide the app |
| `ray()->html($html)` | Render a piece of HTML |
| `ray()->image($path)` | Display an image from a path or URL |
| `ray()->if(true, callback)` | Conditionally show things based on a truthy value or callable |
| `ray()->json($json, $another, …)` | Send one or more valid JSON strings to Ray |
| `ray(…)->label($name)` | Set the label name |
| `ray(…)->large()` | Output text bigger |
| `ray()->limit(N)->…` | Limit the number of payloads that can be sent to Ray to N; used for debugging within loops |
| `ray()->measure()` | Display runtime and memory usage. When measure is called again, the time between this and previous call is also displayed |
| `ray()->newScreen()` | Start a new screen |
| `ray()->newScreen('title')` | Start a new named screen |
| `ray(…)->notify($message)` | Display a notification |
| `ray()->once($arg1, …)` | Only send a payload once when in a loop |
| `ray(…)->orange()` | Output in orange |
| `ray(…)->pass($variable)` | Display something in Ray and return the value instead of a Ray instance |
| `ray()->pause()` | Pause execution |
| `ray()->phpinfo()` | Display PHP info |
| `ray()->phpinfo($key, $another, …)` | Display specific parts of PHP info |
| `ray(…)->purple()` | Output in purple |
| `ray()->rateLimiter()->max(int $maxCalls)` | Limits the amount of calls sent to Ray |
| `ray()->rateLimiter()->perSecond($maxCalls)` | Limits the amount of calls sent to Ray in a second |
| `ray()->rateLimiter()->clear()` | Clears the rate limits |
| `ray()->raw($value)` | Send raw output of a value to Ray without fancy formatting |
| `ray(…)->red()` | Output in red |
| `ray()->separator()` | Add a visual separator |
| `ray()->showApp()` | Bring the app to the foreground |
| `ray(…)->small()` | Output text smaller |
| `ray()->table($array, $label)` | Format an associative array with optional label |
| `ray()->text($string)` | Display the raw text for a string while preserving whitespace formatting |
| `ray()->toJson($variable, $another, … )` | Display the JSON representation of 1 or more values that can be converted |
| `ray()->trace()` | Check entire backtrace |
| `ray()->xml($xmlString)` | Display formatted XML in Ray |
| Call | Description |
|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| `ray($variable)` | Display a string, array or object |
| `ray($variable, $another, …)` | Ray accepts multiple arguments |
| `ray()->backtrace()` | Check entire backtrace |
| `ray(…)->blue()` | Output in blue |
| `ray()->caller()` | Discover where code is being called |
| `ray()->carbon($carbon)` | Send `Carbon` instances to Ray |
| `ray($callable)->catch([$callable, $classname, …])` | Handle any exceptions encountered by `try` |
| `ray()->className($object)` | Send the classname of an object to Ray |
| `ray()->clearScreen()` | Clear current screen |
| `ray()->clearAll()` | Clear current and all previous screens |
| `ray()->count()` | Count how many times a piece of code is called |
| `ray()->counterValue(name)` | Return the value of a named counter |
| `ray(…)->die()` or `rd(…)` | Stop the PHP process |
| `ray()->disable()` | Disable sending stuff to Ray |
| `ray()->disabled()` | Check if Ray is disabled |
| `ray()->enable()` | Enable sending stuff to Ray |
| `ray()->enabled()` | Check if Ray is enabled |
| `ray()->exception($e)` | Display information about an Exception |
| `ray()->file($path)` | Display contents of a file |
| `ray(…)->gray()` | Output in gray |
| `ray(…)->green()` | Output in green |
| `ray(…)->hide()` | Display something in Ray and make it collapse immediately |
| `ray()->hideApp()` | Hide the app |
| `ray()->html($html)` | Render a piece of HTML |
| `ray()->image($path)` | Display an image from a path or URL |
| `ray()->if(true, callback)` | Conditionally show things based on a truthy value or callable |
| `ray()->json($json, $another, …)` | Send one or more valid JSON strings to Ray |
| `ray(…)->label($name)` | Set the label name |
| `ray(…)->large()` | Output text bigger |
| `ray()->limit(N)->…` | Limit the number of payloads that can be sent to Ray to N; used for debugging within loops |
| `ray()->link($url, $label = null)` | Display a clickable URL in Ray |

| `ray()->measure()` | Display runtime and memory usage. When measure is called again, the time between this and previous call is also displayed |
| `ray()->newScreen()` | Start a new screen |
| `ray()->newScreen('title')` | Start a new named screen |
| `ray(…)->notify($message)` | Display a notification |
| `ray()->once($arg1, …)` | Only send a payload once when in a loop |
| `ray(…)->orange()` | Output in orange |
| `ray(…)->pass($variable)` | Display something in Ray and return the value instead of a Ray instance |
| `ray()->pause()` | Pause execution |
| `ray()->phpinfo()` | Display PHP info |
| `ray()->phpinfo($key, $another, …)` | Display specific parts of PHP info |
| `ray(…)->purple()` | Output in purple |
| `ray()->rateLimiter()->max(int $maxCalls)` | Limits the amount of calls sent to Ray |
| `ray()->rateLimiter()->perSecond($maxCalls)` | Limits the amount of calls sent to Ray in a second |
| `ray()->rateLimiter()->clear()` | Clears the rate limits |
| `ray()->raw($value)` | Send raw output of a value to Ray without fancy formatting |
| `ray(…)->red()` | Output in red |
| `ray()->separator()` | Add a visual separator |
| `ray()->showApp()` | Bring the app to the foreground |
| `ray(…)->small()` | Output text smaller |
| `ray()->table($array, $label)` | Format an associative array with optional label |
| `ray()->text($string)` | Display the raw text for a string while preserving whitespace formatting |
| `ray()->toJson($variable, $another, … )` | Display the JSON representation of 1 or more values that can be converted |
| `ray()->trace()` | Check entire backtrace |
| `ray()->url($url, $label = null)` | Display a clickable URL in Ray |
| `ray()->xml($xmlString)` | Display formatted XML in Ray |

### Updating a Ray instance

Expand Down
2 changes: 1 addition & 1 deletion src/Ray.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public function separator(): self
public function url(string $url, string $label = ''): self
{
if (! Str::startsWith($url, 'http')) {
$url = "https//{$url}";
$url = "https://{$url}";
}

if (empty($label)) {
Expand Down
32 changes: 32 additions & 0 deletions tests/RayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,38 @@ public function it_sends_an_html_payload()
$this->assertMatchesOsSafeSnapshot($this->client->sentPayloads());
}

/** @test */
public function it_sends_an_url_payload()
{
$this->ray->url('https://spatie.be');

$this->assertMatchesOsSafeSnapshot($this->client->sentPayloads());
}

/** @test */
public function it_sends_a_correct_url_payload_even_without_a_protocol()
{
$this->ray->url('spatie.be');

$this->assertMatchesOsSafeSnapshot($this->client->sentPayloads());
}

/** @test */
public function it_sends_an_url_with_label_payload()
{
$this->ray->url('https://spatie.be', 'Spatie');

$this->assertMatchesOsSafeSnapshot($this->client->sentPayloads());
}

/** @test */
public function it_sends_a_link_payload()
{
$this->ray->link('https://spatie.be', 'Spatie');

$this->assertMatchesOsSafeSnapshot($this->client->sentPayloads());
}

/** @test */
public function it_sends_a_text_payload()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"uuid": "fakeUuid",
"payloads": [
{
"type": "custom",
"content": {
"content": "<a href='https:\/\/spatie.be'>https:\/\/spatie.be<\/a>",
"label": "HTML"
},
"origin": {
"file": "\/tests\/RayTest.php",
"line_number": "xxx",
"hostname": "fake-hostname"
}
}
],
"meta": []
}
]
20 changes: 20 additions & 0 deletions tests/__snapshots__/RayTest__it_sends_a_link_payload__1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"uuid": "fakeUuid",
"payloads": [
{
"type": "custom",
"content": {
"content": "<a href='https:\/\/spatie.be'>Spatie<\/a>",
"label": "HTML"
},
"origin": {
"file": "\/tests\/RayTest.php",
"line_number": "xxx",
"hostname": "fake-hostname"
}
}
],
"meta": []
}
]
20 changes: 20 additions & 0 deletions tests/__snapshots__/RayTest__it_sends_an_url_payload__1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"uuid": "fakeUuid",
"payloads": [
{
"type": "custom",
"content": {
"content": "<a href='https:\/\/spatie.be'>https:\/\/spatie.be<\/a>",
"label": "HTML"
},
"origin": {
"file": "\/tests\/RayTest.php",
"line_number": "xxx",
"hostname": "fake-hostname"
}
}
],
"meta": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"uuid": "fakeUuid",
"payloads": [
{
"type": "custom",
"content": {
"content": "<a href='https:\/\/spatie.be'>Spatie<\/a>",
"label": "HTML"
},
"origin": {
"file": "\/tests\/RayTest.php",
"line_number": "xxx",
"hostname": "fake-hostname"
}
}
],
"meta": []
}
]

0 comments on commit 7196737

Please sign in to comment.