Skip to content

Commit

Permalink
update docs (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadavidthomas authored Oct 4, 2024
1 parent c557a83 commit 1bc9d2b
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We adhere to Django's Code of Conduct in all interactions and expect all contrib

## Setup

The following setup steps assume you are using a Unix-like operating system, such as Linux or macOS, and that you have a [supported](README.md#requirements) version of Python installed. If you are using Windows, you will need to adjust the commands accordingly. If you do not have Python installed, you can visit [python.org](https://www.python.org/) for instructions on how to install it for your operating system.
The following setup steps assume you are using a Unix-like operating system, such as Linux or macOS, and that you have a [supported](https://django-bird.readthedocs.io/#requirements) version of Python installed. If you are using Windows, you will need to adjust the commands accordingly. If you do not have Python installed, you can visit [python.org](https://www.python.org/) for instructions on how to install it for your operating system.

1. Fork the repository and clone it locally.
2. Create a virtual environment and activate it. You can use whatever tool you prefer for this. Below is an example using the Python standard library's `venv` module:
Expand Down
59 changes: 18 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- docs-intro-begin -->
# django-bird

[![PyPI](https://img.shields.io/pypi/v/django-bird)](https://pypi.org/project/django-bird/)
Expand All @@ -9,9 +10,11 @@

High-flying components for perfectionists with deadlines.

<!-- docs-intro-end -->
> [!CAUTION]
> This is an experimental, pre-alpha attempt at a different approach to defining components in Django templates. It is not suitable for production use yet.
> This is an experimental, alpha attempt at a different approach to defining components in Django templates. It is not suitable for production use yet.
<!-- docs-content-begin -->
## Requirements

- Python 3.10, 3.11, 3.12, 3.13
Expand Down Expand Up @@ -40,42 +43,11 @@ High-flying components for perfectionists with deadlines.
]
```
3. django-bird requires two settings in your `settings.TEMPLATES` to be configured to work properly:
3. django-bird will automatically configure the necessary settings in your project. No further action is required for most use cases.
- `django_bird.templatetags.django_bird` in the `builtins`
- `django_bird.loader.BirdLoader` in the innermost list of `loaders`, before `django.template.loaders.filesystem.Loader` and `django.template.loaders.app_directories.Loader`
If you need to customize the configuration or prefer to set up django-bird manually, you can set `DJANGO_BIRD["ENABLE_AUTO_CONFIG"] = False` in your settings.
By default, these should be configured for you automatically. If you would like to disable this behavior and set this up yourself, you will need to set `DJANGO_BIRD["ENABLE_AUTO_CONFIG"] = False`.
```python
# settings.py
DJANGO_BIRD = {
"ENABLE_AUTO_CONFIG": False,
}
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [...],
"OPTIONS": {
"builtins": [
"django_bird.templatetags.django_bird",
],
"loaders": [
(
"django.template.loaders.cached.Loader",
[
"django_bird.loader.BirdLoader",
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
),
],
},
}
]
```
For detailed instructions, please refer to the [Manual Setup](https://django-bird.readthedocs.io/configuration.html#manual-setup) section within the Configuration documentation.
## Getting Started
Expand Down Expand Up @@ -121,7 +93,8 @@ django-bird automatically recognizes components in the bird directory, so no man
</button>
```
You now a button component that can be easily reused across your Django project.
You now have a button component that can be easily reused across your Django project.
<!-- docs-content-end -->
## Documentation
Expand All @@ -131,15 +104,19 @@ django-bird includes features for creating flexible components, including:
- Named slots for organizing content within components
- Subcomponents for building complex component structures
For a full overview of the features and configuration options, please refer to the [documentation](https://bird.readthedocs.io/).
For a full overview of the features and configuration options, please refer to the [documentation](https://bird.readthedocs.io).
## Motivation and Roadmap
### Roadmap
## Roadmap
#### Static Asset Collection
### Custom HTML Tag
#### Component Islands
### Component Islands
#### Custom HTML Tag
### Scoped CSS Styles
#### Scoped CSS Styles
## License
Expand Down
9 changes: 6 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

# -- Project information -----------------------------------------------------

project = "bird"
copyright = "2023, Josh Thomas"
project = "django-bird"
copyright = "2024, Josh Thomas"
author = "Josh Thomas"


Expand Down Expand Up @@ -60,6 +60,9 @@
myst_heading_anchors = 3

# -- Options for autodoc2 -----------------------------------------------------
autodoc2_docstring_parser_regexes = [
(r".*", "myst"),
]
autodoc2_packages = [f"../src/{project.replace('-', '_')}"]
autodoc2_render_plugin = "myst"

Expand Down Expand Up @@ -89,7 +92,7 @@
"footer_icons": [
{
"name": "GitHub",
"url": "https://github.com/joshuadavidthomas/bird",
"url": "https://github.com/joshuadavidthomas/django-bird",
"html": """
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
Expand Down
112 changes: 112 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Configuration

Configuration of django-bird is done through a `DJANGO_BIRD` dictionary in your Django settings.

All settings are optional. Here is an example configuration with the types and default values shown:

```{code-block} python
:caption: settings.py
from pathlib import Path
DJANGO_BIRD = {
"COMPONENT_DIRS": list[Path | str] = [],
"ENABLE_AUTO_CONFIG": bool = True,
}
```

## `COMPONENT_DIRS`

Additional directories to scan for components. Takes a list of paths relative to the base directory of your project's templates directory. A path can either be a `str` or `Path`.

By default, django-bird will look for components in a `bird` directory. Any directories specified here will take precedence and take priority when performing template resolution for components.

### Example

Suppose you want to store your components in a `components` directory, you're using a third-party library that provides its own bird components, and you have an alternate templates directory.

You can configure django-bird to look in all these locations:

```{code-block} python
:caption: settings.py
from pathlib import Path
BASE_DIR = Path(__file__).resolve(strict=True).parent
DJANGO_BIRD = {
"COMPONENT_DIRS": [
"components",
Path("third_party_library/components"),
BASE_DIR / "alternate_templates" / "bird",
]
}
```

In this configuration:

- `"components"` is a string path relative to your project's templates directory.
- `Path("third_party_library/components")` uses the `Path` object for the third-party library's components.
- `BASE_DIR / "alternate_templates" / "bird"` constructs a path using Django's `BASE_DIR` setting, similar to how other Django settings can be configured.

With this setup, django-bird will search for components in the following order:

1. `components`
2. `third_party_library/components`
3. `alternate_templates/bird`
4. The default `bird` directory

The default `bird` directory will always be checked last, ensuring that your custom directories take precedence in template resolution.

## `ENABLE_AUTO_CONFIG`

django-bird requires a few settings to be setup in your project's `DJANGO_SETTINGS_MODULE` before it will work properly. django-bird will automatically take care of this, during the app's initialization in `django_bird.apps.AppConfig.ready`.

If you would like to disable this behavior and perform the setup manually, setting `ENABLE_AUTO_CONFIG` to `False` will allow you to do so.

### Manual Setup

When `ENABLE_AUTO_CONFIG` is set to `False`, you need to manually configure the following:

1. Add django-bird's template tags to Django's built-ins.
2. Include django-bird's loader in your template loaders, ensuring it comes before Django's default filesystem and app directories loaders.

The complete setup in your settings file should look like this:

```{code-block} python
:caption: settings.py
from pathlib import Path
BASE_DIR = Path(__file__).resolve(strict=True).parent
DJANGO_BIRD = {
"ENABLE_AUTO_CONFIG": False,
}
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
BASE_DIR / "templates",
],
"OPTIONS": {
"builtins": [
"django_bird.templatetags.django_bird",
],
"loaders": [
(
"django.template.loaders.cached.Loader",
[
"django_bird.loader.BirdLoader",
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
),
],
},
}
]
```

This configuration ensures that django-bird's templatetags are available globally and that its loader is used to compile bird component templates before the standard Django loaders.
16 changes: 14 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
```{include} ../README.md
:start-after: '<!-- docs-intro-begin -->'
:end-before: '<!-- docs-intro-end -->'
```

```{include} ../README.md
:start-after: '<!-- docs-content-begin -->'
:end-before: '<!-- docs-content-end -->'
```

```{toctree}
:hidden:
:maxdepth: 3
configuration
```

```{toctree}
:hidden:
:maxdepth: 3
:caption: API Reference
apidocs/bird/bird.rst
apidocs/django_bird/django_bird.rst
```

```{toctree}
:hidden:
:maxdepth: 3
:maxdepth: 2
:caption: Development
development/contributing.md
Expand Down

0 comments on commit 1bc9d2b

Please sign in to comment.