Skip to content

Commit

Permalink
Add action aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Jan 1, 2025
1 parent a766517 commit 6514195
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Datastar.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ public static function getInstance(): Datastar
*/
public function init(): void
{
parent::init();

Craft::setAlias('@putyourlightson/datastar', __DIR__);
parent::init();

$this->registerComponents();
$this->registerTwigExtension();
Expand Down
40 changes: 40 additions & 0 deletions src/variables/DatastarVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,46 @@ public function sse(string $template, array $variables = [], array $options = []
return 'sse(' . implode(', ', $args) . ')';
}

/**
* Returns a Datastar SSE action with a `get` request.
*/
public function get(string $template, array $variables = [], array $options = []): string
{
return $this->sse($template, $variables, array_merge($options, ['method' => 'get']));
}

/**
* Returns a Datastar SSE action with a `post` request.
*/
public function post(string $template, array $variables = [], array $options = []): string
{
return $this->sse($template, $variables, array_merge($options, ['method' => 'post']));
}

/**
* Returns a Datastar SSE action with a `put` request.
*/
public function put(string $template, array $variables = [], array $options = []): string
{
return $this->sse($template, $variables, array_merge($options, ['method' => 'put']));
}

/**
* Returns a Datastar SSE action with a `patch` request.
*/
public function patch(string $template, array $variables = [], array $options = []): string
{
return $this->sse($template, $variables, array_merge($options, ['method' => 'patch']));
}

/**
* Returns a Datastar SSE action with a `delete` request.
*/
public function delete(string $template, array $variables = [], array $options = []): string
{
return $this->sse($template, $variables, array_merge($options, ['method' => 'delete']));
}

/**
* Runs an action and returns the response.
*/
Expand Down

0 comments on commit 6514195

Please sign in to comment.