├── Default.sublime-keymap
├── .gitignore
├── Context.sublime-menu
├── Default.sublime-commands
├── MagentoCreateModuleCommand.py
├── MagentoInsertClassCommand.py
├── MagentoOpenCommand.py
├── MagentoOpenFromMagentoPath.py
├── MagentoOpenParentCommand.py
├── README.md
├── helper.sublime-snippet
├── magento-config-init.sublime-snippet
├── magento-frontend-config.sublime-snippet
├── magento-module-admin.sublime-snippet
├── magento-module-init.sublime-snippet
├── magento-module-layout-update.sublime-snippet
├── magento-module-registration.sublime-snippet
├── model.sublime-snippet
├── resource.sublime-snippet
└── singleton.sublime-snippet
/ Default.sublime-keymap:
--------------------------------------------------------------------------------
1 | [
2 |
3 | { "keys": ["ctrl+i"], "command": "magento_insert_class", "args": {} },
4 |
5 |
6 | { "keys": ["alt+shift+o"], "command": "magento_open_from_magento_path", "args": {} },
7 |
8 |
9 | { "keys": ["alt+shift+m"], "command": "magento_create_module", "args": {} }
10 |
11 | ]
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 |
--------------------------------------------------------------------------------
/Context.sublime-menu:
--------------------------------------------------------------------------------
1 | [
2 | {"caption":"-"},
3 | {
4 | "command": "magento_open",
5 | "id":"magento-open",
6 | "caption":"Magento: Open File for Class"
7 | },
8 | {
9 | "command": "magento_open_parent",
10 | "id":"magento-open-parent",
11 | "caption":"Magento: Open Parent Class"
12 | },
13 | {"caption":"-"}
14 | ]
15 |
--------------------------------------------------------------------------------
/Default.sublime-commands:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "caption": "Magento: Open Class",
4 | "command": "magento_open"
5 | },
6 |
7 | {
8 | "caption": "Magento: Open Parent Class",
9 | "command": "magento_open_parent"
10 | },
11 |
12 | // copy text to "goto", like ("module/class_name") -> "module class name"
13 | {
14 | "caption": "Magento: Open From Path",
15 | "command": "magento_open_from_magento_path"
16 | },
17 |
18 | // creates folder structure for a module
19 | {
20 | "caption": "Magento: Create Module",
21 | "command": "magento_create_module"
22 | },
23 |
24 | // Inserts class name with regards to folder structure
25 | {
26 | "caption": "Magento: Insert Class Name",
27 | "command": "magento_insert_class"
28 | },
29 |
30 | ]
--------------------------------------------------------------------------------
/MagentoCreateModuleCommand.py:
--------------------------------------------------------------------------------
1 | import sublime, sublime_plugin
2 | import os
3 | import re
4 |
5 | class MagentoCreateModuleCommand(sublime_plugin.WindowCommand):
6 |
7 | def run(self):
8 | self.window.show_input_panel("New Module:", "", self.on_done, None, None)
9 | pass
10 |
11 | def on_done(self, text):
12 | regex = re.compile("([a-zA-Z0-9]*)_([a-zA-Z0-9]*)")
13 | folder_path = self.window.active_view().window().folders();
14 | if (regex.match(text) != None):
15 | text_split = text.split("_");
16 | namespace = text_split[0];
17 | moduleName = text_split[1];
18 | path = os.path.join(folder_path[0], 'app', 'code', 'local', namespace, moduleName );
19 | etc_modules_path = os.path.join(folder_path[0], 'app', 'etc', 'modules', text + ".xml")
20 |
21 | # Create folder structure
22 | os.makedirs(path)
23 | os.makedirs(os.path.join(path, 'Model'))
24 | os.makedirs(os.path.join(path, 'Block'))
25 | os.makedirs(os.path.join(path, 'controllers'))
26 | os.makedirs(os.path.join(path, 'sql'))
27 |
28 | self.create_config_xml(path, namespace, moduleName)
29 | self.create_etc_modules_xml(etc_modules_path, namespace, moduleName)
30 |
31 | self.create_helper(path, namespace, moduleName)
32 | pass
33 |
34 | def create_config_xml(self, path, namespace, moduleName):
35 | template = """
36 |
37 |
38 | <{namespace}_{moduleName}>
39 | 0.0.1
40 | {namespace}_{moduleName}>
41 |
42 |
43 | """
44 | data = {"namespace" : namespace,
45 | "moduleName" : moduleName}
46 | os.makedirs(os.path.join(path, 'etc'))
47 | file = open(os.path.join(path, 'etc', 'config.xml'), 'w+')
48 | file.write(template.format(**data))
49 |
50 |
51 | def create_etc_modules_xml(self, path, namespace, moduleName):
52 | template = """
53 |
54 |
55 | <{namespace}_{moduleName}>
56 | true
57 | local
58 |
59 | {namespace}_{moduleName}>
60 |
61 |
62 | """
63 | data = {"namespace" : namespace,
64 | "moduleName" : moduleName}
65 | file = open(path, 'w+')
66 | file.write(template.format(**data))
67 | pass
68 |
69 | def create_helper(self, path, namespace, moduleName):
70 | template = """ 0)
35 | return value
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/MagentoOpenFromMagentoPath.py:
--------------------------------------------------------------------------------
1 | # DISCLAIMER:
2 | #
3 | # Parts of this code were taken from the "Expand Selection to Quotes" plugin at
4 | # https://github.com/kek/sublime-expand-selection-to-quotes
5 | #
6 | # Expands selection to quotes and opens 'GO TO' prompt with the selection in it already
7 |
8 | import sublime, sublime_plugin
9 | import os
10 | import re
11 |
12 | class MagentoOpenFromMagentoPathCommand(sublime_plugin.WindowCommand):
13 | def run(self):
14 |
15 | d_quotes = list(map(lambda x: x.begin(), self.window.active_view().find_all('"')))
16 | s_quotes = list(map(lambda x: x.begin(), self.window.active_view().find_all("'")))
17 |
18 | for sel in self.window.active_view().sel():
19 | def search_for_quotes(q_type, quotes):
20 | q_size, before, after = False, False, False
21 |
22 | if len(quotes) - self.window.active_view().substr(sel).count('"') >= 2:
23 | all_before = list(filter(lambda x: x < sel.begin(), quotes))
24 | all_after = list(filter(lambda x: x >= sel.end(), quotes))
25 |
26 | if all_before: before = all_before[-1]
27 | if all_after: after = all_after[0]
28 |
29 | if all_before and all_after: q_size = after - before
30 |
31 | return q_size, before, after
32 |
33 | d_size, d_before, d_after = search_for_quotes('"', d_quotes)
34 | s_size, s_before, s_after = search_for_quotes("'", s_quotes)
35 |
36 | def replace_region(start, end):
37 | if sel.size() < end-start-2:
38 | start += 1; end -= 1
39 | self.window.active_view().sel().subtract(sel)
40 | self.window.active_view().sel().add(sublime.Region(start, end))
41 |
42 | if d_size and (not s_size or d_size < s_size):
43 | replace_region(d_before, d_after+1)
44 | elif s_size and (not d_size or s_size < d_size):
45 | replace_region(s_before, s_after+1)
46 |
47 | text = self.window.active_view().substr(self.window.active_view().sel()[0]).replace("_", " ").replace("/", " ")
48 | self.window.run_command("show_overlay", {"overlay": "goto", "text": text, "show_files": "true"})
49 |
50 |
--------------------------------------------------------------------------------
/MagentoOpenParentCommand.py:
--------------------------------------------------------------------------------
1 | import sublime, sublime_plugin
2 | import os.path
3 | import re
4 |
5 | class MagentoOpenParentCommand(sublime_plugin.TextCommand):
6 | def run(self, edit):
7 | text = self.view.substr(sublime.Region(0,self.view.size()))
8 | result = re.search("class\s+?(?:(?:[A-Z][a-zA-Z0-9]+_?)+)\s+?extends\s+?((?:[A-Z][a-zA-Z0-9]+_?)+)", text, re.M | re.U)
9 |
10 | if result != None:
11 | parentClass = result.group(1)
12 |
13 | if len(parentClass):
14 | self.open(self.get_file(parentClass))
15 |
16 | def get_file(self, text):
17 | return text.strip().replace('_', '/') + '.php'
18 |
19 | def open(self, filePath):
20 | rootDirectories = ['/app/code/core/', '/app/code/community/', '/app/code/local/', '/lib/']
21 |
22 | for folder in sublime.active_window().folders():
23 | for root in rootDirectories:
24 | print (folder+root+filePath)
25 | if os.path.isfile(folder+root+filePath):
26 | sublime.active_window().open_file(folder+root+filePath)
27 | return
28 |
29 | def is_visible(self):
30 | value = False
31 | for region in self.view.sel():
32 | if region.empty():
33 | continue
34 | if self.view.score_selector(region.a, 'source.php') <= 0:
35 | return False
36 | else:
37 | value = True
38 | return value or self.view.score_selector(sublime.Region(0, 100).a, 'source.php') > 0
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ##sublime-magento
2 | Sublime text 2 plugin for easier magento development. It contains code snippets for faster module creation (code within standard module files - mostly XML).
3 |
4 | **Commands**
5 |
6 | * **InsertClass command** (original work @serpentblade)
7 |
8 | Used to insert class name -> works for all classes except controllers (unless you are willing to delete 'controllers' word)
9 | ```
10 | { "keys": ["ctrl+i"], "command": "magento_insert_class"}
11 | ```
12 |
13 | * **OpenFromMagentoPath command**
14 |
15 | On keypress fills the "goto" panel with the text between the nearest quotation marks (single or double). Useful for file paths. Also useful for 'magento-like' paths like ('core/input_filter_maliciousCode') where the command removes the '_' and '/' characters and also populates the "goto" panel.
16 | ```
17 | { "keys": ["alt+shift+p"], "command": "magento_open_from_magento_path"}
18 | ```
19 |
20 | * **CreateModule command**
21 |
22 | On keypress opens up a dialog for new module name. Name should be entered in the format of "Namespace_ModuleName". Newly created module will be located in the local/Namespace/ModuleName, and it will have few things created already (Model, Helper, Helper/Data.php, Block, controllers, etc, etc/config.xml, controllers), and also will be registered in "/app/etc/Modules/Namespace_Modulename.xml".
23 | New module will have the default version of 0.0.1.
24 | ```
25 | { "keys": ["alt+shift+m"], "command": "magento_create_module"}
26 | ```
27 |
28 | **Snippets**
29 | ```php
30 | // (original work @serpentblade)
31 | model => Mage::getModel('module/model');
32 | helper => Mage::helper('module/helper');
33 | resource => Mage::getResourceModel('module/model');
34 | singleton => Mage::getSingleton('module/model');
35 |
36 | ```
37 |
38 | **mag-modreg**
39 | * **magento module registration** in app/etc/modules/Namespace_Modulename
40 | * creates the following snippet with your module name already in place, and cursor on codePool
41 | ```xml
42 |
43 |
44 |
45 | true
46 |
47 |
48 |
49 |
50 | ```
51 |
52 | **mag-confinit**
53 | * **magento module configuration initialization** in app/code/[codePool]/Namespace/Modulename/etc/config.xml
54 | * creates the following snippet with the cursor placed to insert your Namespace_Modulename, autopopulating the closing tag. Tabbing moves you to version.
55 | ```xml
56 |
57 |
58 | <>
59 |
60 | >
61 |
62 |
63 | ```
64 |
65 | **mag-frontend**
66 | * **magento module configuration frontend** in app/code/[codePool]/Namespace/Modulename/etc/config.xml
67 | * creates the following snippet with the cursor placed to insert your router tag, autopopulating the closing tag. Tabbing moves you to module.
68 | ```xml
69 |
70 |
71 | <>
72 |
73 |
74 |
75 |
76 |
77 | >
78 |
79 |
80 | ```
81 |
82 | **mag-modinit**
83 | * **magento module configuration of models, helpers and blocks** in app/code/[codePool]/Namespace/Modulename/etc/config.xml
84 | * Extends the **mag-confinit** adding few new things
85 | * creates the following snippet with the cursor placed to insert your module name. When you insert it, everything else is autopopulated. Tabbing moves you to version tag.
86 | ```xml
87 |
88 |
89 | <>
90 |
91 | >
92 |
93 |
94 |
95 | <>
96 | _Model
97 | >
98 |
99 |
100 | <>
101 | _Helper
102 | >
103 |
104 |
105 | <>
106 | _Block
107 | >
108 |
109 |
110 |
111 | ```
112 | **mag-mod-admin**
113 | * creates admin routers xml code
114 | ```xml
115 |
116 |
117 |
118 |
119 |
120 |
121 | < before="Mage_Adminhtml">_Adminhtml>
122 |
123 |
124 |
125 |
126 |
127 | ```
128 |
--------------------------------------------------------------------------------
/helper.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | helper
7 |
8 | source.php
9 |
10 |
--------------------------------------------------------------------------------
/magento-config-init.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | <${1:}>
6 | ${3:}
7 | ${2:}>
8 |
9 |
10 | ]]>
11 |
12 | mag-confinit
13 |
14 |
15 | text.xml
16 |
17 |
--------------------------------------------------------------------------------
/magento-frontend-config.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | <$1>
6 |
7 |
8 | ${2:}
9 | ${3:$1}
10 |
11 | $1>
12 |
13 |
14 | ]]>
15 |
16 | mag-frontend
17 |
18 | text.xml
19 |
20 |
--------------------------------------------------------------------------------
/magento-module-admin.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 | <${1:} before="Mage_Adminhtml">$1_Adminhtml$1>
10 |
11 |
12 |
13 |
14 |
15 | ]]>
16 |
17 | mag-mod-admin-
18 |
19 | text.xml
20 |
21 |
--------------------------------------------------------------------------------
/magento-module-init.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | <$1>
6 | ${2:}
7 | $1>
8 |
9 |
10 |
11 | <${1/(.+)_(.+)/\L$0/}>
12 | $1_Model
13 | ${1/(.+)_(.+)/\L$0/}>
14 |
15 |
16 | <${1/(.+)_(.+)/\L$0/}>
17 | $1_Helper
18 | ${1/(.+)_(.+)/\L$0/}>
19 |
20 |
21 | <${1/(.+)_(.+)/\L$0/}>
22 | $1_Block
23 | ${1/(.+)_(.+)/\L$0/}>
24 |
25 |
26 |
27 | ]]>
28 | mag-modinit->
29 | text.xml
30 |
--------------------------------------------------------------------------------
/magento-module-layout-update.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | <${1:}>
6 | ${2:}
7 | $1>
8 |
9 |
10 | ]]>
11 |
12 | mag-frontend-layout-update
13 |
14 | text.xml
15 |
16 |
--------------------------------------------------------------------------------
/magento-module-registration.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | <${TM_FILENAME/(.+)\..+/$1/}>
6 | true
7 | ${1:}
8 | ${TM_FILENAME/(.+)\..+/$1/}>
9 |
10 |
11 | ]]>
12 |
13 | mag-modreg
14 |
15 |
16 | text.xml
17 |
18 |
--------------------------------------------------------------------------------
/model.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | model
7 |
8 | source.php
9 |
--------------------------------------------------------------------------------
/resource.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | resmodel
7 |
8 | source.php
9 |
10 |
--------------------------------------------------------------------------------
/singleton.sublime-snippet:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | singleton
7 |
8 | source.php
9 |
10 |
--------------------------------------------------------------------------------