Skip to content

Commit

Permalink
Merge pull request #4 from absszero/support-component
Browse files Browse the repository at this point in the history
support blade component
  • Loading branch information
absszero authored Apr 2, 2022
2 parents 4ddf1b0 + 6f6fd67 commit 327536d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
13 changes: 12 additions & 1 deletion lib/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

class_controller_pattern = compile(r"(.+)\.php\s*,\s*[\"']{1}(.+)")

component_pattern = compile(r"<\/?x-([^\/>]*)")

extensions = []


Expand Down Expand Up @@ -159,6 +161,10 @@ def env_place(path, line, selected):


def view_place(path, line, selected):
matched = component_pattern.search(line)
if matched:
path = matched.group(1).strip()

split = path.split(':')
vendor = ''
# vendor or namespace
Expand All @@ -168,7 +174,12 @@ def view_place(path, line, selected):
vendor = split[0] + '/'

path = split[-1]
path = vendor + path.replace('.', '/') + '.blade.php'
path = vendor + path.replace('.', '/')
if matched:
path += '.php'
else:
path += '.blade.php'

return Place(path)


Expand Down
2 changes: 1 addition & 1 deletion lib/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_selection(self):
selected = self.view.extract_scope(start)
if self.line.contains(selected):
if self.is_class:
selected = self.get_selected_by_delimiters(selected, ',[', '])')
selected = self.get_selected_by_delimiters(selected, ',[<', '>])')
return selected
return self.get_selected_by_delimiters(selected, self.delimiters)

Expand Down
10 changes: 7 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ Goto various Laravel files

## Feature

- Go to Blade Template files *(EX. hello.blade.php)*
- Go to Blade Template files (EX. hello.blade.php)

- Go to Controller and highlight method *(EX. \Namespace\Controller.php@Method)*
- Go to Blade Component files (EX. &lt;x-alert&gt;)

- Go to Static files (*EX. hello.js*)
- Go to Blade Template files (EX. hello.blade.php)

- Go to Controller and highlight method (EX. \Namespace\Controller.php@Method)

- Go to Static files (EX. hello.js)

- Go to Config files and highlight option (EX. config/app.php)

Expand Down
8 changes: 7 additions & 1 deletion tests/sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@

Route::group(['namespace' => 'L8'], function () {
Route::get('/', [EightController::class, 'index']);
});
});

<x-vendor::hello />

</x-alert>

<x-forms.input/>
24 changes: 24 additions & 0 deletions tests/test_place.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ def test_controller(self):
self.assertEqual(True, place.is_controller)
self.assertEqual("HelloController.php@index", place.path)

def test_component(self):
self.fixture("""<x-form.|input/>""")

selection = Selection(self.view)
place = get_place(selection)

self.assertEqual("form/input.php", place.path)

def test_closing_tag_component(self):
self.fixture("""</x-al|ert>""")

selection = Selection(self.view)
place = get_place(selection)

self.assertEqual("alert.php", place.path)

def test_component_with_namespace(self):
self.fixture("""<x-namespace::|alert/>""")

selection = Selection(self.view)
place = get_place(selection)

self.assertEqual("namespace/alert.php", place.path)

def test_view(self):
self.fixture("""Route::get('/', function () {
return view('hello|_view');
Expand Down

0 comments on commit 327536d

Please sign in to comment.