Skip to content
This repository has been archived by the owner on Jan 20, 2021. It is now read-only.

Commit

Permalink
copy HasDropdown mixin and import it into app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Mar 7, 2019
1 parent 8800e00 commit 0998d5e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
48 changes: 37 additions & 11 deletions src/Commands/AuthMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Naoray\DarkTailwindPreset\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Auth\Console\AuthMakeCommand as MakeAuth;
use Naoray\DarkTailwindPreset\EnsuresResourceDirectoryExists;

class AuthMakeCommand extends MakeAuth
{
use EnsuresResourceDirectoryExists;

/**
* The views that need to be exported.
*
Expand All @@ -33,15 +34,40 @@ public function handle()
{
parent::handle();

$filesystem = new Filesystem;
$this->addHasDropdownMixin();
$this->copyImages();

if (! $filesystem->isDirectory($directory = resource_path('img'))) {
$filesystem->makeDirectory($directory, 0755, true);
}
$this->info('Run `yarn dev` to publish the images.');
}

File::copyDirectory(__DIR__.'/stubs/img', resource_path('img'));
/**
* Adds Has Dropdown mixin and imports it into Vue app.
*
* @return void
*/
protected function addHasDropdownMixin()
{
static::ensureResourceDirectoryExists('js/mixins');
copy(__DIR__ . '/stubs/HasDropdown.js', resource_path('js/mixins/HasDropdown.js'));

$this->info('Run `yarn dev` to publish the images.');
file_put_contents(resource_path('js/app.js'), str_replace(
'const app = new Vue({' . PHP_EOL,
"import HasDropdown from './mixins/HasDropdown'" . PHP_EOL .
'const app = new Vue({' . PHP_EOL .
' mixins: [HasDropdown],' . PHP_EOL,
file_get_contents(resource_path('js/app.js'))
));
}

/**
* Copy images into reosurces 'img' folder.
*
* @return void
*/
protected function copyImages()
{
static::ensureResourceDirectoryExists('img');
File::copyDirectory(__DIR__ . '/stubs/img', resource_path('img'));
}

/**
Expand All @@ -52,14 +78,14 @@ public function handle()
protected function exportViews()
{
foreach ($this->views as $key => $value) {
if (file_exists($view = resource_path('views/'.$value)) && ! $this->option('force')) {
if (! $this->confirm("The [{$value}] view already exists. Do you want to replace it?")) {
if (file_exists($view = resource_path('views/' . $value)) && !$this->option('force')) {
if (!$this->confirm("The [{$value}] view already exists. Do you want to replace it?")) {
continue;
}
}

copy(
__DIR__.'/stubs/views/'.$key,
__DIR__ . '/stubs/views/' . $key,
$view
);
}
Expand Down
29 changes: 29 additions & 0 deletions src/Commands/stubs/HasDropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default {
data() {
return {
showDropdown: false
}
},

methods: {
toggleDropdown() {
this.showDropdown = !this.showDropdown
this.$refs.dropdown.style.display = this.showDropdown ? 'block' : 'none'

if (this.showDropdown) {
this.$nextTick(() => {
document.addEventListener('click', this.closeDropdownListener)
})
}
},

closeDropdownListener(event) {
if (event.target.closest('.dropdown')) {
return
}

this.toggleDropdown()
document.removeEventListener('click', this.closeDropdownListener)
}
}
}

0 comments on commit 0998d5e

Please sign in to comment.