Skip to content

Commit

Permalink
Merge pull request #198
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
leonardosahon authored Nov 8, 2024
2 parents c185579 + 99ece15 commit b27214d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/BobDBuilder/Cmd/Traits/Make/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function init_pages(): void
public function pages(): void
{
\$this->builder->route("index")->bind(function (ViewBuilder \$builder) {
\$this->route("index")->bind(function (ViewBuilder \$builder) {
\$builder->page("title", "Homepage")
->page("desc", "This is the default homepage description")
->assets(
Expand All @@ -142,7 +142,7 @@ public function pages(): void
->body("homepage");
});
\$this->builder->route("another-page")->bind(function (ViewBuilder \$builder) {
\$this->route("another-page")->bind(function (ViewBuilder \$builder) {
\$builder->page("title", "Another Page")
->page("desc", "This is another page's description")
->assets(
Expand Down
84 changes: 46 additions & 38 deletions src/Core/Traits/Resources.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
declare(strict_types=1);
namespace BrickLayer\Lay\Core\Traits;
use BrickLayer\Lay\__InternalOnly\CacheInitOptions;
use BrickLayer\Lay\Libs\LayDir;
use Dotenv\Dotenv;
use JetBrains\PhpStorm\ObjectShape;

trait Resources {
private static object $server;
Expand Down Expand Up @@ -75,25 +73,27 @@ protected static function set_internal_site_data(array $options) : void {
self::$site = (object) $obj;
}

#[ObjectShape([
"lay" => 'string',
"lay_static" => 'string',
"framework" => 'string',
"framework_workers" => 'string',
"workers" => 'string',
"root" => 'string',
"temp" => 'string',
"exceptions" => 'string',
"cron_outputs" => 'string',
"bricks" => 'string',
"db" => 'string',
"utils" => 'string',
"web" => 'string',
"shared" => 'string',
"domains" => 'string',
"uploads" => 'string',
"uploads_no_root" => 'string',
])]
/**
* @psalm-return object{
* lay: string,
* lay_static: string,
* framework: string,
* framework_workers: string,
* workers: string,
* root: string,
* temp: string,
* exceptions: string,
* cron_outputs: string,
* bricks: string,
* db: string,
* utils: string,
* web: string,
* shared: string,
* domains: string,
* uploads: string,
* uploads_no_root: string
* }
*/
public static function server_data() : object
{
if(!isset(self::$server)){
Expand All @@ -105,23 +105,31 @@ public static function server_data() : object
}


#[ObjectShape([
"base" => 'string',
"proto" => 'string',
"base_no_proto" => 'string',
"base_no_proto_no_www" => 'string',
"domain" => 'string',
"domain_no_proto" => 'string',
"domain_no_proto_no_www" => 'string',
"server_mocked" => 'bool',
"author" => 'string',
"global_api" => 'string',
"name" => 'object[long, short]',
"color" => 'object[pry, sec]',
"mail" => 'object[0,1,...n]',
"tel" => 'object[0,1,...n]',
"others" => 'object',
])]
/**
* @psalm-return object{
* base: string,
* proto: string,
* base_no_proto: string,
* base_no_proto_no_www: string,
* domain: string,
* domain_no_proto: string,
* domain_no_proto_no_www: string,
* server_mocked: bool,
* author: string,
* global_api: string,
* name: object{
* long : string,
* short: string
* },
* color: object{
* pry: string,
* sec: string
* },
* mail: object<int>,
* tel: object<int>,
* others: object
* }
*/
public static function site_data() : object
{
self::is_init(true);
Expand Down
9 changes: 5 additions & 4 deletions src/Core/View/Tags/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public function href(string $href, bool $print = true, bool $lazy = false): stri
$as = $this->attr['as'] ?? "style";
$rel = $this->attr['rel'] ?? "stylesheet";
$type = $this->attr['type'] ?? "text/css";
$lazy_type = $this->attr['lazy'] ?? "prefetch"; // 'preload' || 'prefetch';
$attr = $this->get_attr(function ($v, $k) use ($lazy) {
if (($lazy && $k == "rel") || $k == "src")

if (($lazy && ($k == "rel" || $k == "media" || $k == "type")) || $k == "src") {
return CustomContinueBreak::CONTINUE;
}

return $v;
});
Expand All @@ -58,10 +59,10 @@ public function href(string $href, bool $print = true, bool $lazy = false): stri

if ($lazy) {
$attr = <<<ATTR
media="print" onload="this.rel='$rel';this.media='$media'" rel="$lazy_type" href="$href" type="$type" as="$as" $attr
media="print" onload="this.media='$media'; this.onload=null" rel="$rel" href="$href" type="$type" as="$as" $attr
ATTR;

$link = "\n\t<link $attr>\n\t<noscript><link rel=\"$rel\" href=\"$href\" ></noscript>";
$link = "\n\t<link $attr>\n\t<noscript><link rel=\"$rel\" media='$media' type='$type' href=\"$href\" ></noscript>";
}

if ($print)
Expand Down

0 comments on commit b27214d

Please sign in to comment.