Skip to content

Commit

Permalink
Merge branch 'master' into compile-tailwindcss
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva authored Apr 28, 2024
2 parents 9f5c930 + 94926a6 commit 53dd80e
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 56 deletions.
3 changes: 2 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ This serves two purposes:
2. At release time, you can move the Unreleased section changes into a new release version section.

### Added
- for new features.
- Added support for using HTML comments to create Markdown code block filepath labels in https://github.com/hydephp/develop/pull/1693
- You can now specify which path to open when using the `--open` option in the serve command in https://github.com/hydephp/develop/pull/1694

### Changed
- After updating a Tailwind minor version, table headers in Typography `.prose` classes are now centered instead of left-aligned by default. See https://github.com/tailwindlabs/tailwindcss-typography/commit/f520c53470630e3ad4d43e3c2306882d33bf5c52
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"watch": "mix watch"
},
"devDependencies": {
"@tailwindcss/typography": "^0.5.12",
"@tailwindcss/typography": "^0.5.13",
"autoprefixer": "^10.4.19",
"hydefront": "^3.3.0",
"laravel-mix": "^6.0.49",
Expand Down
6 changes: 4 additions & 2 deletions packages/framework/src/Console/Commands/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public function handle(): int
return Command::SUCCESS;
}

/** @return array<integer, array<string, string>> */
protected function generate(): array
{
return array_map([RouteListItem::class, 'format'], array_values(Hyde::routes()->all()));
return array_map(RouteListItem::format(...), array_values(Hyde::routes()->all()));
}

/** @param array<integer, array<string, string>> $routes */
protected function makeHeader(array $routes): array
{
return array_map([Hyde::class, 'makeTitle'], array_keys($routes[0]));
return array_map(Hyde::makeTitle(...), array_keys($routes[0]));
}
}
15 changes: 9 additions & 6 deletions packages/framework/src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ServeCommand extends Command
{--dashboard= : Enable the realtime compiler dashboard. (Overrides config setting)}
{--pretty-urls= : Enable pretty URLs. (Overrides config setting)}
{--play-cdn= : Enable the Tailwind Play CDN. (Overrides config setting)}
{--open : Open the site preview in the browser.}
{--open=false : Open the site preview in the browser.}
';

/** @var string */
Expand All @@ -46,8 +46,8 @@ public function safeHandle(): int
$this->configureOutput();
$this->printStartMessage();

if ($this->option('open')) {
$this->openInBrowser();
if ($this->option('open') !== 'false') {
$this->openInBrowser((string) $this->option('open'));
}

$this->runServerProcess(sprintf('php -S %s:%d %s',
Expand Down Expand Up @@ -143,16 +143,19 @@ protected function checkArgvForOption(string $name): ?string
return null;
}

protected function openInBrowser(): void
protected function openInBrowser(string $path = '/'): void
{
$command = match (PHP_OS_FAMILY) {
$binary = match (PHP_OS_FAMILY) {
'Windows' => 'start',
'Darwin' => 'open',
'Linux' => 'xdg-open',
default => null
};

$process = $command ? Process::command(sprintf('%s http://%s:%d', $command, $this->getHostSelection(), $this->getPortSelection()))->run() : null;
$command = sprintf('%s http://%s:%d', $binary, $this->getHostSelection(), $this->getPortSelection());
$command = rtrim("$command/$path", '/');

$process = $binary ? Process::command($command)->run() : null;

if (! $process || $process->failed()) {
$this->warn('Unable to open the site preview in the browser on your system:');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Support\Facades\View;
use Illuminate\Support\HtmlString;

use function array_merge;
use function preg_replace;
use function str_contains;
use function str_ireplace;
Expand All @@ -36,6 +37,8 @@ class CodeblockFilepathProcessor implements MarkdownPreProcessorContract, Markdo
'/* filepath ',
'# filepath: ',
'# filepath ',
'<!-- filepath: ',
'<!-- filepath ',
];

/**
Expand All @@ -52,7 +55,7 @@ public static function preprocess(string $markdown): string
// We then replace these markers in the post-processor.
$lines[$index - 2] .= sprintf(
"\n<!-- HYDE[Filepath]%s -->",
trim(str_ireplace(static::$patterns, '', $line))
trim(str_ireplace(array_merge(static::$patterns, ['-->']), '', $line))
);

// Remove the original comment lines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testPreprocessExpandsFilepath()
$markdown = "\n```php\n// filepath: foo.php\necho 'Hello World';\n```";
$expected = "\n<!-- HYDE[Filepath]foo.php -->\n```php\necho 'Hello World';\n```";

$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
}

public function testPreprocessAcceptsMultipleFilepathFormats()
Expand All @@ -37,7 +37,7 @@ public function testPreprocessAcceptsMultipleFilepathFormats()
$markdown = "\n```php\n{$pattern}foo.php\necho 'Hello World';\n```";
$expected = "\n<!-- HYDE[Filepath]foo.php -->\n```php\necho 'Hello World';\n```";

$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
}
}

Expand All @@ -54,7 +54,45 @@ public function testFilepathPatternIsCaseInsensitive()
$markdown = "\n```php\n{$pattern}foo.php\necho 'Hello World';\n```";
$expected = "\n<!-- HYDE[Filepath]foo.php -->\n```php\necho 'Hello World';\n```";

$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
}
}

public function testPreprocessCanUseHtmlComments()
{
$markdown = <<<'MD'
```html
<!-- filepath: foo.html -->
<p>Hello World</p>
```
MD;

$expected = <<<'MD'
<!-- HYDE[Filepath]foo.html -->
```html
<p>Hello World</p>
```
MD;

$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
}

public function testPreprocessCanUseHtmlCommentsWithDifferentPatterns()
{
$patterns = [
'<!-- filepath: ',
'<!-- Filepath: ',
'<!-- FilePath: ',
'<!-- FILEPATH: ',
];

foreach ($patterns as $pattern) {
$markdown = "\n```html\n{$pattern}foo.html\n<p>Hello World</p>\n```";
$expected = "\n<!-- HYDE[Filepath]foo.html -->\n```html\n<p>Hello World</p>\n```";

$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
}
}

Expand All @@ -72,10 +110,8 @@ public function testPreprocessAcceptsMultipleLanguages()
$markdown = "\n```$language\n// filepath: foo.$language\nfoo\n```";
$expected = "\n<!-- HYDE[Filepath]foo.$language -->\n```$language\nfoo\n```";

$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
$this->assertSame($expected, CodeblockFilepathProcessor::preprocess($markdown));
}

$this->assertEquals($expected, CodeblockFilepathProcessor::preprocess($markdown));
}

public function testPreprocessAcceptsMultipleInputBlocks()
Expand Down
Loading

0 comments on commit 53dd80e

Please sign in to comment.