Skip to content

Commit

Permalink
Make custom blocks path configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ifox committed Mar 2, 2020
1 parent aef641f commit 9a75480
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions config/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Indicates if blocks templates should be inlined in HTML.
// When setting to false, make sure to build Twill with your all your custom blocks.
'inline_blocks_templates' => true,
'custom_vue_blocks_resource_path' => 'assets/js/blocks',
'blocks' => [
'text' => [
'title' => 'Body text',
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private function npmBuild()
*/
private function copyBlocks()
{
$localCustomBlocksPath = resource_path('assets/js/blocks');
$localCustomBlocksPath = resource_path(config('twill.block_editor.custom_vue_blocks_resource_path', 'assets/js/blocks'));
$twillCustomBlocksPath = base_path(config('twill.vendor_path')) . '/frontend/js/components/blocks/customs';

if (!$this->filesystem->exists($twillCustomBlocksPath)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/GenerateBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class GenerateBlocks extends Command
{
const NO_BLOCKS_DEFINED = "There are no blocks defined yet. Please refer to https://twill.io/docs/#block-editor-3 in order to create blocks.";
const SCANNING_BLOCKS = "Starting to scan block views directory...";
const SCANNING_BLOCKS = "Starting to scan block views directory...";

/**
* The name and signature of the console command.
Expand Down Expand Up @@ -73,7 +73,7 @@ public function handle()
'render' => $this->sanitize($vueBlockTemplate),
])->render();

$vueBlockPath = $this->makeDirectory(resource_path('assets/js/blocks/')) . 'Block' . Str::title($blockName) . '.vue';
$vueBlockPath = $this->makeDirectory(resource_path(config('twill.block_editor.custom_vue_blocks_resource_path', 'assets/js/blocks'))) . '/Block' . Str::title($blockName) . '.vue';

$this->filesystem->put($vueBlockPath, $vueBlockContent);

Expand Down
10 changes: 5 additions & 5 deletions tests/integration/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace A17\Twill\Tests\Integration;

use A17\Twill\Models\User;
use A17\Twill\Commands\GenerateBlocks;
use A17\Twill\Models\User;

class CommandsTest extends TestCase
{
Expand Down Expand Up @@ -32,7 +32,7 @@ public function testCanExecuteModuleCommand()
public function testCanExecuteBlocksCommand()
{
$this->deleteDirectory($path = resource_path('views/admin/blocks'));
$this->deleteDirectory(resource_path('assets/js/blocks'));
$this->deleteDirectory(resource_path(config('twill.custom_vue_blocks_resource_path', 'assets/js/blocks')));

$this->artisan('twill:blocks')->expectsOutput(
GenerateBlocks::NO_BLOCKS_DEFINED
Expand All @@ -44,7 +44,7 @@ public function testCanExecuteBlocksCommand()
true
);
$this->files->makeDirectory(
resource_path('assets/js/blocks'),
resource_path(config('twill.custom_vue_blocks_resource_path', 'assets/js/blocks')),
0755,
true
);
Expand All @@ -63,12 +63,12 @@ public function testCanExecuteBlocksCommand()
);

$this->assertFileExists(
resource_path('assets/js/blocks/BlockQuote.vue')
resource_path(config('twill.custom_vue_blocks_resource_path', 'assets/js/blocks') . '/BlockQuote.vue')
);

$this->assertEquals(
read_file(stubs('blocks/BlockQuote.vue')),
read_file(resource_path('assets/js/blocks/BlockQuote.vue'))
read_file(resource_path(config('twill.custom_vue_blocks_resource_path', 'assets/js/blocks') . '/BlockQuote.vue'))
);
}

Expand Down

0 comments on commit 9a75480

Please sign in to comment.