From 5c694aef284a042cd61b1635fa52d03098758c3c Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Sun, 21 Aug 2022 09:43:03 -0400 Subject: [PATCH 1/2] Adding updated content --- src/Tails.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Tails.php b/src/Tails.php index 2a93f15..95b3bc4 100644 --- a/src/Tails.php +++ b/src/Tails.php @@ -99,6 +99,21 @@ public static function replaceBladeHTMLWithBladeDirectives($string){ } } + // trim any curly brace from {!! array.item !!} to {!! $array->item !!} + $bladeCurlyBraceMatches = []; + preg_match_all('/{!!(.*?)!!}/', $string, $bladeCurlyBraceMatches); + foreach($bladeCurlyBraceMatches[1] as $index => $curlyBrace){ + $trimmedContent = trim($curlyBrace); + // dd($trimmedContent[0]); + if(isset($trimmedContent[0])){ + // if it's a string we don't replace it + if($trimmedContent[0] != "'" && $trimmedContent[0] != '"'){ + $outputVariable = str_replace('.', '->', $trimmedContent); + $string = str_replace($bladeCurlyBraceMatches[0][$index], '{!! $' . $outputVariable . '!!}', $string); + } + } + } + foreach(config('tails.blade_tags') as $tag => $value){ $string = str_replace($tag, $value, $string); } From bf053c97a57d597d1950cf29b6421d907a3d3055 Mon Sep 17 00:00:00 2001 From: Tony Lea Date: Sun, 21 Aug 2022 10:16:57 -0400 Subject: [PATCH 2/2] Adding fixes and updating tmp blade storage --- config/config.php | 3 +-- src/Commands/Clear.php | 2 +- src/Tails.php | 6 +++--- src/TailsServiceProvider.php | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/config/config.php b/config/config.php index e32a71a..e05a3db 100644 --- a/config/config.php +++ b/config/config.php @@ -7,8 +7,7 @@ 'api_key' => env('TAILS_API_KEY', null), 'api_endpoint' => 'https://devdojo.com/api/v1', 'webhook_key' => env('TAILS_WEBHOOK_KEY', null), - - 'view_folder' => 'tails', + // You can convert HTML tags to any desired blade tags. This conversion will happen // when the content is pulled from Tails, it will then be rendered as blade tags. 'blade_tags' => [ diff --git a/src/Commands/Clear.php b/src/Commands/Clear.php index 98477d1..690e50b 100644 --- a/src/Commands/Clear.php +++ b/src/Commands/Clear.php @@ -37,7 +37,7 @@ public function handle() $this->info("Cleared cached result with key: {$cacheKey}"); } - $tailsViewFolder = resource_path('views/' . config('tails.view_folder')); + $tailsViewFolder = storage_path('app/tails-tmp'); Tails::recursiveDeleteTailsViewFolder($tailsViewFolder); $this->info("Cleared blade files from {$tailsViewFolder}"); diff --git a/src/Tails.php b/src/Tails.php index 95b3bc4..b21f3dd 100644 --- a/src/Tails.php +++ b/src/Tails.php @@ -143,7 +143,7 @@ public static function get($route, $project){ public static function storeBladeFile($project, $projectPage, $contents, $key = 'html'){ - $viewFolder = resource_path('views/' . config('tails.view_folder') . '/' . $project); + $viewFolder = storage_path('app/tails-tmp') . '/' . $project; if(empty($projectPage)){ $projectPage = 'index'; } @@ -159,7 +159,7 @@ public static function storeBladeFile($project, $projectPage, $contents, $key = file_put_contents($file, $contents); } - $viewLocation = config('tails.view_folder') . '.' . $project . '.' . $projectPage; + $viewLocation = 'tails::' . $project . '.' . $projectPage; return $viewLocation; } @@ -214,7 +214,7 @@ public function webhook(Request $request){ $cacheKey = 'tails.' . $project->slug . $page_slug; Cache::forget($cacheKey); - $tailsViewFolder = resource_path('views/' . config('tails.view_folder')); + $tailsViewFolder = storage_path('app/tails-tmp'); $this->recursiveDeleteTailsViewFolder($tailsViewFolder); Artisan::call('view:clear'); diff --git a/src/TailsServiceProvider.php b/src/TailsServiceProvider.php index 3787a3d..2e46c6d 100644 --- a/src/TailsServiceProvider.php +++ b/src/TailsServiceProvider.php @@ -17,7 +17,7 @@ public function boot() { // Load tails views and routes - $this->loadViewsFrom(__DIR__.'/../resources/views', 'tails'); + $this->loadViewsFrom(storage_path('app/tails-tmp'), 'tails'); $this->loadRoutesFrom(__DIR__.'/routes.php'); if ($this->app->runningInConsole()) { @@ -38,7 +38,7 @@ public function boot() [$data, $project, $projectPage, $key] = Tails::getProjectDataFromString($projectString); Tails::storeBladeFile( $project, $projectPage, $data, $key ); - $includeFile = config('tails.view_folder') . '.' . $project . '.' . $projectPage; + $includeFile = 'tails::' . $project . '.' . $projectPage; if($key != 'html'){ $includeFile .= '.' . $key; }