Skip to content

Commit

Permalink
Merge pull request #6 from thedevdojo/new/rewrite
Browse files Browse the repository at this point in the history
New/rewrite
  • Loading branch information
tnylea authored Aug 21, 2022
2 parents 271889c + bf053c9 commit c764de5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
3 changes: 1 addition & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Clear.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
21 changes: 18 additions & 3 deletions src/Tails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -128,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';
}
Expand All @@ -144,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;
}
Expand Down Expand Up @@ -199,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');
Expand Down
4 changes: 2 additions & 2 deletions src/TailsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
}
Expand Down

0 comments on commit c764de5

Please sign in to comment.