Skip to content

Commit

Permalink
Merge pull request #80 from joegasewicz/Docs-for-options-#78
Browse files Browse the repository at this point in the history
#78 Docs for options
  • Loading branch information
joegasewicz authored Mar 6, 2024
2 parents aa5e813 + 17134e1 commit 2b39140
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pipenv install gunicorn
### Getting Started
An example of the smallest Bobtail app
```python
from typing import Tuple, Optional, Dict
from bobtail import BobTail, AbstractRoute, Request, Response

class Images:
Expand All @@ -33,20 +32,29 @@ routes = [
]

app = BobTail(routes=routes)

```

### Run
```
pipenv run gunicorn api:app
```
### Options
To define port, static directory, template directory etc. you can
create a concrete version of the BaseOptions abstract class. See the [docs](https://bobtail.readthedocs.io/en/latest/) for more info.
```python
from bobtail.options import BaseOptions

class Options(BaseOptions):
PORT = 8001

app = Bobtail(Options)
```
### Middleware
Bobtail middleware

#### Using third party middleware
```python
from bobttail_logger import BobtailLogger
from bobtail_logger import BobtailLogger

app = Bobtail(routes=routes)

Expand Down
18 changes: 18 additions & 0 deletions bobtail/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@


class BaseOptions(ABC):
"""
To define port, static directory, template directory etc. you can
create a concrete version of the BaseOptions abstract class.
For Example::
from bobtail.options import BaseOptions
class Options(BaseOptions):
PORT = 8001
app = Bobtail(Options)
"""
#: The port by default is set to `8000`
PORT = 8000

#: The static directory relative path is set by default to `static`
STATIC_DIR = "static"

#: The template directory relative path is set by default to `templates`
TEMPLATE_DIR = "templates"
11 changes: 8 additions & 3 deletions bobtail/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ class BobTail:
routes: List[Route]

#: Options (Optional). See :class:`~BaseOptions` for option list. Base options
#: can be overriden & or set on a concrete BaseOptions instance.
#: can be overridden & or set on a concrete BaseOptions instance.
#: For Example::
#:
#: from bobtail.options import BaseOptions
#:
#: class Options(BaseOptions):
#: STATIC_DIR = "app/static"
#: TEMPLATE_DIR = "app/templates"
#: PORT = 8000 # set by default
#: STATIC_DIR = "app/static" # set by default
#: TEMPLATE_DIR = "app/templates" # set by default
#:
#: app = Bobtail(Options, routes=[])
#:
options: BaseOptions

Expand Down
4 changes: 4 additions & 0 deletions docs/options.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Options
=======
.. automodule:: bobtail.options
:members:
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py310-dev, py311-dev
envlist = py310-dev, py311-dev, py312-dev

[pytest]

Expand Down

0 comments on commit 2b39140

Please sign in to comment.