Skip to content

Instantly share code, notes, and snippets.

@johanhalse
Created August 31, 2023 06:20
Show Gist options
  • Save johanhalse/eca5a7a53d9d2d21b75324a56b3b3dfe to your computer and use it in GitHub Desktop.
Save johanhalse/eca5a7a53d9d2d21b75324a56b3b3dfe to your computer and use it in GitHub Desktop.
Sublime text command for quickly switching between a Rails view_component view and component
import sublime
import sublime_plugin
import os
class ComponentSwitcherCommand(sublime_plugin.TextCommand):
def open_ext(self, filename, ext):
file_to_open = f"{filename}{ext}"
if os.path.exists(file_to_open):
self.view.window().open_file(file_to_open)
else:
sublime.error_message(f"The file '{file_to_open}' does not exist.")
def run(self, edit):
full_path = self.view.sheet().file_name();
filename, file_extension = os.path.splitext(full_path)
if file_extension == ".rb":
self.open_ext(filename, ".html.erb")
else:
self.open_ext(filename.replace(".html", ""), ".rb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment