Skip to content

Commit

Permalink
ST2 version
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarula committed Mar 12, 2013
0 parents commit 161823f
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.pyc
50 changes: 50 additions & 0 deletions Default.sublime-commands
@@ -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"
}
}
]
25 changes: 25 additions & 0 deletions README.md
@@ -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*
43 changes: 43 additions & 0 deletions generate.py
@@ -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)

0 comments on commit 161823f

Please sign in to comment.