Skip to content

Commit

Permalink
Merge df35923 into 1a416a4
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Sep 14, 2018
2 parents 1a416a4 + df35923 commit 199f289
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 119 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ language: python
python:
- '3.4'
- '3.5'
- '3.6'

matrix:
include:
- python: 3.7
dist: xenial
sudo: true
- python: 3.6
script: travis_retry coverage run -m pytest && coveralls

install:
- pip install masonite_cli
Expand All @@ -26,6 +27,3 @@ deploy:
on:
tags: true
python: 3.6

after_success:
coveralls
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include masonite/snippets/exceptions/css/*
include masonite/snippets/*
include masonite/snippets/scaffold/*
include masonite/snippets/auth/controllers/*
include masonite/snippets/auth/templates/auth/*
37 changes: 37 additions & 0 deletions masonite/commands/BaseScaffoldCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

from cleo import Command

from masonite.app import App
from masonite.helpers.filesystem import make_directory
from masonite.view import View


class BaseScaffoldCommand(Command):
"""
Creates a model
model
{name : Name of the model}
"""

scaffold_name = 'Example'
base_directory = 'app/example/'
template = '/masonite/snippets/scaffold/model'

def handle(self):
class_name = self.argument('name')
view = View(App())
class_directory = self.base_directory + '{}.py'.format(class_name)

if not make_directory(class_directory):
return self.error('{0} Already Exists!'.format(self.scaffold_name))

f = open(class_directory, 'w+')
if view.exists(self.template):
f.write(
view.render(self.template, {
'class': class_name.split('/')[-1]}).rendered_template
)
self.info('{} Created Successfully!'.format(self.scaffold_name))
return f.close()
24 changes: 5 additions & 19 deletions masonite/commands/CommandCommand.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
import os
from cleo import Command
from masonite.commands import BaseScaffoldCommand


class CommandCommand(Command):
class CommandCommand(BaseScaffoldCommand):
"""
Creates a new command
command
{name : Name of the command you would like to create}
"""

def handle(self):
command = self.argument('name')
if not os.path.isfile('app/commands/{0}.py'.format(command)):
if not os.path.exists(os.path.dirname('app/commands/{0}.py'.format(command))):
# Create the path to the command if it does not exist
os.makedirs(os.path.dirname('app/commands/{0}.py'.format(command)))

f = open('app/commands/{0}.py'.format(command), 'w+')

f.write('""" A {0} Command """\n'.format(command))
f.write('from cleo import Command\n\n\n')
f.write('class {0}(Command):\n """\n Description of command\n\n '.format(command))
f.write('command:name\n {argument : description}\n """\n\n ')
f.write('def handle(self):\n pass')

self.info('Command Created Successfully!')
else:
self.error('Command Already Exists!')
scaffold_name = 'Command'
template = '/masonite/snippets/scaffold/command'
base_directory = 'app/commands/'
42 changes: 19 additions & 23 deletions masonite/commands/ControllerCommand.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from cleo import Command
import os
from masonite.view import View
from masonite.app import App
from masonite.helpers.filesystem import make_directory


class ControllerCommand(Command):
Expand All @@ -14,32 +17,25 @@ class ControllerCommand(Command):

def handle(self):
controller = self.argument('name')
view = View(App())

if not self.option('exact'):
controller = controller + "Controller"

if os.path.isfile('app/http/controllers/{0}.py'.format(controller)):
self.error('{0} Controller Exists!'.format(controller))
else:
f = open('app/http/controllers/{0}.py'.format(controller), 'w+')
f.write("''' A Module Description '''\n\n")
f.write('class {0}:\n'.format(controller))
f.write(" ''' Class Docstring Description '''\n\n")
f.write(' def show(self):\n')
f.write(' pass\n')
if not make_directory('app/http/controllers/{0}.py'.format(controller)):
return self.error('{0} Controller Exists!'.format(controller))

f = open('app/http/controllers/{0}.py'.format(controller), 'w+')
if view.exists('/masonite/snippets/scaffold/controller'):
if self.option('resource'):
f.write('\n def index(self):\n')
f.write(' pass\n\n')
f.write(' def create(self):\n')
f.write(' pass\n\n')
f.write(' def store(self):\n')
f.write(' pass\n\n')
f.write(' def edit(self):\n')
f.write(' pass\n\n')
f.write(' def update(self):\n')
f.write(' pass\n\n')
f.write(' def destroy(self):\n')
f.write(' pass\n')

self.info('{0} Created Successfully!'.format(controller))
template = '/masonite/snippets/scaffold/controller_resource'
else:
template = '/masonite/snippets/scaffold/controller'

f.write(
view.render(
template, {'class': controller.split('/')[-1]}).rendered_template
)

self.info('Controller Created Successfully!')
return f.close()
24 changes: 6 additions & 18 deletions masonite/commands/JobCommand.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os

from cleo import Command

from masonite.commands import BaseScaffoldCommand


class JobCommand(Command):
"""
Expand All @@ -10,21 +13,6 @@ class JobCommand(Command):
{name : Name of the job you want to create}
"""

def handle(self):
job = self.argument('name')
if not os.path.isfile('app/jobs/{0}.py'.format(job)):
if not os.path.exists(os.path.dirname('app/jobs/{0}.py'.format(job))):
# Create the path to the job if it does not exist
os.makedirs(os.path.dirname('app/jobs/{0}.py'.format(job)))

f = open('app/jobs/{0}.py'.format(job), 'w+')

f.write("''' A {0} Queue Job '''\n\n".format(job))
f.write('from masonite.queues.Queueable import Queueable\n\n')
f.write("class {0}(Queueable):\n\n ".format(job))
f.write("def __init__(self):\n pass\n\n ")
f.write("def handle(self):\n pass\n")

self.info('Job Created Successfully!')
else:
self.comment('Job Already Exists!')
scaffold_name = 'Job'
template = '/masonite/snippets/scaffold/job'
base_directory = 'app/jobs/'
23 changes: 5 additions & 18 deletions masonite/commands/ModelCommand.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
import os
from cleo import Command
from masonite.commands import BaseScaffoldCommand


class ModelCommand(Command):
class ModelCommand(BaseScaffoldCommand):
"""
Creates a model
model
{name : Name of the model}
"""

def handle(self):
model = self.argument('name')
if not os.path.isfile('app/{0}.py'.format(model)):
if not os.path.exists(os.path.dirname('app/{0}.py'.format(model))):
# Create the path to the model if it does not exist
os.makedirs(os.path.dirname('app/{0}.py'.format(model)))

f = open('app/{0}.py'.format(model), 'w+')

f.write("''' A {0} Database Model '''\n".format(
model.split('/')[-1]))
f.write('from config.database import Model\n\n')
f.write("class {0}(Model):\n pass\n".format(model.split('/')[-1]))

self.info('Model Created Successfully!')
else:
self.error('Model Already Exists!')
scaffold_name = "Model"
template = '/masonite/snippets/scaffold/model'
base_directory = 'app/'
25 changes: 5 additions & 20 deletions masonite/commands/ProviderCommand.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
import os
from cleo import Command
from masonite.commands import BaseScaffoldCommand


class ProviderCommand(Command):
class ProviderCommand(BaseScaffoldCommand):
"""
Creates a new Service Provider
provider
{name : Name of the Service Provider you want to create}
"""

def handle(self):
provider = self.argument('name')

if not os.path.isfile('app/providers/{0}.py'.format(provider)):
if not os.path.exists(os.path.dirname('app/providers/{0}.py'.format(provider))):
# Create the path to the service provider if it does not exist
os.makedirs(os.path.dirname('app/providers/{0}.py'.format(provider)))

f = open('app/providers/{0}.py'.format(provider), 'w+')

f.write("''' A {0} Service Provider '''\n".format(provider))
f.write('from masonite.provider import ServiceProvider\n\n')
f.write("class {0}(ServiceProvider):\n\n ".format(provider))
f.write("def register(self):\n pass\n\n ")
f.write("def boot(self):\n pass\n")

self.info('Service Provider Created Successfully!')
else:
self.comment('Service Provider Already Exists!')
scaffold_name = 'Service Provider'
base_directory = 'app/providers/'
template = '/masonite/snippets/scaffold/provider'
22 changes: 5 additions & 17 deletions masonite/commands/ValidatorCommand.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import os
from cleo import Command
from masonite.commands import BaseScaffoldCommand


class ValidatorCommand(Command):
class ValidatorCommand(BaseScaffoldCommand):
"""
Creates a validator
validator
{name : Name of the validator}
"""

def handle(self):
validator = self.argument('name')
if not os.path.isfile('app/validators/{0}.py'.format(validator)):
if not os.path.exists(os.path.dirname('app/validators/{0}.py'.format(validator))):
# Create the path to the validator if it does not exists already
os.makedirs(os.path.dirname('app/validators/{0}.py'.format(validator)))

f = open('app/validators/{0}.py'.format(validator), 'w+')

f.write("''' A {0} Validator '''\n".format(validator.split('/')[-1]))
f.write('from masonite.validator import Validator\n\n')
f.write("class {0}Validator(Validator):\n pass\n".format(validator.split('/')[-1]))

self.info('Validator Created Successfully')
else:
self.error('Validator Already Exists!')
scaffold_name = 'Validator'
base_directory = 'app/validators/'
template = '/masonite/snippets/scaffold/validator'
1 change: 1 addition & 0 deletions masonite/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .AuthCommand import AuthCommand
from .BaseScaffoldCommand import BaseScaffoldCommand
from .CommandCommand import CommandCommand
from .ControllerCommand import ControllerCommand
from .InfoCommand import InfoCommand
Expand Down
12 changes: 12 additions & 0 deletions masonite/helpers/filesystem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os


def make_directory(directory):
if not os.path.isfile(directory):
if not os.path.exists(os.path.dirname(directory)):
# Create the path to the model if it does not exist
os.makedirs(os.path.dirname(directory))

return True

return False
14 changes: 14 additions & 0 deletions masonite/snippets/scaffold/command.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
""" A {{ class }} Command """
from cleo import Command


class {{ class }}(Command):
"""
Description of command

command:name
{argument : description}
"""

def handle(self):
pass
9 changes: 9 additions & 0 deletions masonite/snippets/scaffold/controller.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
""" A {{ class }} Module """


class {{ class }}:
"""{{ class }} Controller
"""

def show(self):
pass
48 changes: 48 additions & 0 deletions masonite/snippets/scaffold/controller_resource.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
""" A {{ class }} Module """


class {{ class }}:
"""Class Docstring Description
"""

def show(self):
"""Show several resource listings
"""

pass

def index(self):
"""Show a single resource listing
"""

pass

def create(self):
"""Show form to create new resource listings
"""

pass

def store(self):
"""Create a new resource listing
"""

pass

def edit(self):
"""Show form to edit an existing resource listing
"""

pass

def update(self):
"""Edit an existing resource listing
"""

pass

def destroy(self):
"""Delete an existing resource listing
"""

pass
Loading

0 comments on commit 199f289

Please sign in to comment.