Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 161823f
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"caption": "Generate: Model", | ||
"command": "generate", | ||
"args": { | ||
"generate": "model", | ||
"fill_in": "modelName" | ||
} | ||
}, | ||
{ | ||
"caption": "Generate: Seed", | ||
"command": "generate", | ||
"args": { | ||
"generate": "seed", | ||
"fill_in": "tableName" | ||
} | ||
}, | ||
{ | ||
"caption": "Generate: Test", | ||
"command": "generate", | ||
"args": { | ||
"generate": "test", | ||
"fill_in": "fileName" | ||
} | ||
}, | ||
{ | ||
"caption": "Generate: View", | ||
"command": "generate", | ||
"args": { | ||
"generate": "view", | ||
"fill_in": "viewName" | ||
} | ||
}, | ||
{ | ||
"caption": "Generate: Migration", | ||
"command": "generate", | ||
"args": { | ||
"generate": "migration", | ||
"fill_in": "migrationName --fields=\"fields\"" | ||
} | ||
}, | ||
{ | ||
"caption": "Generate: Resource", | ||
"command": "generate", | ||
"args": { | ||
"generate": "resource", | ||
"fill_in": "resourceName" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
## sublime-laravelgenerator | ||
|
||
A Sublime Text Plugin which allows using [Laravel 4 | ||
Generators](https://github.com/JeffreyWay/Laravel-4-Generators) by [Jeffrey | ||
Way](https://github.com/JeffreyWay) via the command pallete. | ||
|
||
|
||
## Usage | ||
|
||
* Open a Laravel Project | ||
* Open the command pallete (Ctrl+Shift+P) | ||
* Execute any of the available Generate commands | ||
|
||
*Note*: `artisan` needs to be in the project root. | ||
|
||
## Customization | ||
|
||
The plugin is quite extensible. Interested users can extend the plugin for more | ||
artisan commands by adding the appropriate entries in | ||
`Default.sublime-commands`. | ||
|
||
*** | ||
|
||
*This is a work in progress. Feedback is appreciated. Feel free to report any | ||
issues you come across* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import time | ||
import shlex | ||
import subprocess | ||
import sublime | ||
import sublime_plugin | ||
|
||
class GenerateCommand(sublime_plugin.WindowCommand): | ||
def run(self, *args, **kwargs): | ||
self.command = kwargs.get('generate', None) | ||
self.fill_in = kwargs.get('fill_in', '') | ||
|
||
try: | ||
# The first folder needs to be the Laravel Project | ||
self.PROJECT_PATH = self.window.folders()[0] | ||
|
||
if os.path.isfile("%s/artisan" % self.PROJECT_PATH): | ||
if self.command in ['model', 'seed', 'test', 'view', 'migration', 'resource']: | ||
# call function to do the work | ||
self.window.show_input_panel('Enter the resource name with parameters if any', self.fill_in, self.call_artisan, None, None) | ||
else: | ||
sublime.status_message("Generator command not supported") | ||
else: | ||
print "Artisan not found" | ||
sublime.status_message("Artisan not found") | ||
except IndexError: | ||
print "Please open a Laravel Project" | ||
sublime.status_message("Please open a Laravel Project") | ||
|
||
def call_artisan(self, resource_name): | ||
command_str = "php %s/artisan generate:%s %s" % (self.PROJECT_PATH, self.command, resource_name) | ||
args = shlex.split(str(command_str)) | ||
self.proc = subprocess.Popen(args, shell=False) | ||
self.proc_status(resource_name) | ||
|
||
def proc_status(self, resource_name): | ||
if self.proc.poll() is None: | ||
sublime.set_timeout(lambda: self.proc_status(resource_name), 200) | ||
else: | ||
if self.proc.returncode == 0: | ||
sublime.status_message("%s %s generated!" % (self.command, resource_name)) | ||
else: | ||
sublime.status_message("%s failed" % command_str) |