-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMagentoThemer.py
55 lines (41 loc) · 2.13 KB
/
MagentoThemer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import re
import ntpath
import sublime, sublime_plugin
class MagentoThemer:
AddContentView = None
Content = None
class MagentoThemerInsertConentCommand(sublime_plugin.TextCommand):
def run(self, edit, **args):
self.view.insert(edit, 0, MagentoThemer.Content)
MagentoThemer.AddContentView = None
MagentoThemer.Content = None
class MagentoThemerListener(sublime_plugin.EventListener):
def on_load(self, view):
if MagentoThemer.AddContentView and MagentoThemer.AddContentView.id() == view.id():
view.run_command("magento_themer_insert_conent")
class MagentoThemerCommand(sublime_plugin.WindowCommand):
def run(self):
project_name = self.window.project_file_name()
project_name = ntpath.basename(project_name)
project_name = re.sub('\.sublime-project$', '', project_name)
self.window.show_input_panel("Give me: <package name>/<theme name>:", "Simpleness/%s" % project_name, self.on_done, None, None)
def on_done(self, text):
view = self.window.active_view()
old_file = view.file_name()
MagentoThemer.Content = view.substr(sublime.Region(0, view.size()))
new_package_name = text.split('/')[0]
new_theme_name = text.split('/')[1]
root = re.match(r'(.*?)/vendor', old_file).group(1)
vendor_name = re.match(r'(.*)/vendor/(.*?)/', old_file).group(2).capitalize()
module_name = re.match(r'(.*)/vendor/(.*?)/(.*?)/', old_file).group(3).replace('module-', '').capitalize()
module_name = vendor_name + '_' + module_name
template_name = re.match(r'(.*)/templates/(.*)', old_file).group(2)
new_file = root + '/app/design/frontend/' + new_package_name + '/' + new_theme_name + '/' + module_name + '/templates/' + template_name
# Recursively create parent folder if it does not exist
if not os.path.exists(os.path.dirname(new_file)):
os.makedirs(os.path.dirname(new_file))
# Open the file
MagentoThemer.AddContentView = self.window.open_file(new_file)
if os.path.exists(new_file):
sublime.error_message('File already exists')