Skip to content

Commit 99a4c6d

Browse files
authored
docs: unfold development in containers (#979)
1 parent 5b68d95 commit 99a4c6d

File tree

3 files changed

+95
-63
lines changed

3 files changed

+95
-63
lines changed

docs/development/devcontainer.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: VS Code devcontainers
3+
order: 1
4+
description: Learn how to set up and use VS Code devcontainers for efficient Unfold theme development, including Tailwind compilation and development server configuration.
5+
---
6+
7+
# Using VS Code with containers
8+
9+
Unfold already contains prepared support for VS Code development. After cloning the project locally, open the main folder in VS Code (in terminal using `code .`). You will immediately see a message from VS Code stating **Folder contains a Dev Container configuration file. Reopen folder to develop in a container**. This indicates that container support is ready. Click on **Reopen in Container** to proceed. If you don't see this message, you can still manually open the project in a container by running the command **Dev Containers: Reopen in Container**.
10+
11+
## Development server
12+
13+
VS Code will build an image and install Python dependencies. After the installation is complete, VS Code will start a container where you can develop directly. Unfold contains an example development application with basic Unfold configuration available in the `tests/server` directory. To start a development Django server, navigate to the `tests/server` folder and run `python manage.py runserver 0.0.0.0:8000`. Make sure to run this command from the VS Code terminal that is connected to the running container.
14+
15+
**Note:** This is not a production-ready server. Use it only for running tests or developing features & fixes.
16+
17+
## Compiling Tailwind in devcontainer
18+
19+
Before building the styles, you need to install node dependencies since the current Docker image only contains Python dependencies. To enable node in the container, update the `.devcontainer/devcontainer.json` file by adding the following:
20+
21+
```json
22+
// .devcontainer/devcontainer.json
23+
24+
"features": {
25+
"ghcr.io/devcontainers/features/node:1": {
26+
"version": "latest"
27+
}
28+
}
29+
```
30+
31+
This modification is necessary because the `features` are not functioning correctly in Cursor. This approach ensures compatibility with both Cursor and VS Code. Please note that after this change, the container will only work in VS Code and will require more time to start. After making this change, you must rebuild the container by running `Dev Containers: Rebuild Container` in VS Code.
32+
33+
Open the terminal and run `npm install` to install all dependencies and create the `node_modules` folder. You can then use the following npm commands for Tailwind:
34+
35+
```bash
36+
# Run during development to watch for changes
37+
npm run tailwind:watch
38+
39+
# Run for a one-time build
40+
npm run tailwind:build
41+
```
42+
43+
## Running without VS Code
44+
45+
If you prefer to run the project without VS Code, you can use `docker compose up` from the `.devcontainer` folder. This will automatically start a container and run the migrations and development server.

docs/development/index.md

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,4 @@
11
---
22
title: Development
33
order: 12
4-
description: Development guide and best practices for Unfold.
54
---
6-
7-
# Development
8-
9-
## Pre-commit
10-
11-
Before adding any source code, it is recommended to have pre-commit installed on your local computer to check for all potential issues when committing the code.
12-
13-
```bash
14-
pip install pre-commit
15-
pre-commit install
16-
pre-commit install --hook-type commit-msg
17-
pre-commit run --all-files # Check if everything is okay
18-
```
19-
20-
## Poetry configuration
21-
22-
To add a new feature or fix the easiest approach is to use django-unfold in combination with Poetry. The process looks like:
23-
24-
- Install django-unfold via `poetry add django-unfold`
25-
- After that it is needed to git clone the repository somewhere on local computer.
26-
- Edit _pyproject.toml_ and update django-unfold line `django-unfold = { path = "../django-unfold", develop = true}`
27-
- Lock and update via `poetry lock && poetry update`
28-
29-
## Compiling Tailwind
30-
31-
At the moment project contains package.json with all dependencies required to compile new CSS file. Tailwind configuration file is set to check all html, js and py files for Tailwind's classes occurrences.
32-
33-
```bash
34-
npm install
35-
npx tailwindcss -i src/unfold/styles.css -o src/unfold/static/unfold/css/styles.css --watch --minify
36-
37-
npm run tailwind:watch # run after each change in code
38-
npm run tailwind:build # run once
39-
```
40-
41-
Some components like datepickers, calendars or selectors in admin was not possible to style by overriding html templates so their default styles are overridden in **styles.css**.
42-
43-
**Note:** most of the custom styles located in style.css are created via `@apply some-tailwind-class;` as is not possible to manually add CSS class to element which are for example created via jQuery.
44-
45-
## Design system
46-
47-
| Component | Classes |
48-
| --------------------------------- | ------------------------------------------------------ |
49-
| Regular text | text-base-600 dark:text-base-300 |
50-
| Hover regular text | text-base-700 dark:text-base-200 |
51-
| Headings | font-semibold text-base-900 dark:text-base-100 |
52-
| Icon | text-base-400 dark:text-base-500 |
53-
| Hover icon | hover:text-base-500 dark:hover:text-base-400 |
54-
55-
## Using VS Code with containers
56-
57-
Unfold already contains prepared support for VS Code development. After cloning the project locally, open the main folder in VS Code (in terminal `code .`). Immediately, you would see a message from VS Code **Folder contains a Dev Container configuration file. Reopen folder to develop in a container** which will inform you that the support for containers is prepared. Confirm the message by clicking on **Reopen in Container**. If the message is not there, you can still manually open the project in a container by running the command **Dev Containers: Reopen in Container**.
58-
59-
### Development server
60-
61-
Now the VS Code will build an image and install Python dependencies. After successful installation is completed, VS Code will spin a container and from now it is possible to directly develop in the container. Unfold contains an example development application with the basic Unfold configuration available under `tests/server`. Run `python manage.py runserver` within a `tests/server` folder to start a development Django server. Note that you have to run the command from VS Code terminal which is already connected to the running container.
62-
63-
**Note:** this is not a production ready server. Use it just for running tests or developing features & fixes.
64-
65-
### Compiling Tailwind in devcontainer
66-
67-
The container has already a node preinstalled so it is possible to compile a new CSS. Open the terminal and run `npm install` which will install all dependencies and will create `node_modules` folder. Now, you can run npm commands for Tailwind as described in the previous chapter.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Poetry dependecy path
3+
order: 0
4+
description: Learn how to set up pre-commit hooks, configure Poetry for development, and compile Tailwind CSS styles for Unfold theme development.
5+
---
6+
7+
# Developing with changed Poetry path
8+
9+
The easiest way how to develop new features or fixes for Unfold is to directly implement them in existing project which you are working on. The prerequisite is to have django-unfold installed and the same time use Poetry for dependency management.
10+
11+
## Poetry configuration
12+
13+
To add a new feature or fix an issue, the easiest approach is to use django-unfold with Poetry. The process looks like this:
14+
15+
- Install django-unfold via `poetry add django-unfold`
16+
- Clone the repository to your local computer
17+
- Edit _pyproject.toml_ and update the django-unfold line to: `django-unfold = { path = "../django-unfold", develop = true}`
18+
- Lock and update via `poetry lock && poetry update`
19+
20+
## Compiling Tailwind
21+
22+
The project contains a package.json with all dependencies required to compile the CSS file. The Tailwind configuration file is set to check all HTML, JS and Python files for Tailwind class occurrences. The prerequisite is to have Node.js installed on your computer.
23+
24+
```bash
25+
# Install dependencies
26+
npm install
27+
28+
# Manually run tailwindcss command
29+
npx tailwindcss -i src/unfold/styles.css -o src/unfold/static/unfold/css/styles.css --watch --minify
30+
31+
# run after each change in code
32+
npm run tailwind:watch
33+
# run once
34+
npm run tailwind:build
35+
```
36+
37+
Some components like datepickers, calendars or selectors in the admin interface cannot be styled by overriding HTML templates, so their default styles are overridden in **styles.css**.
38+
39+
**Note:** Most of the custom styles in styles.css are created via `@apply some-tailwind-class;` as it is not possible to manually add CSS classes to elements that are created via jQuery.
40+
41+
## Pre-commit
42+
43+
Before adding any source code, it is recommended to have pre-commit installed on your local computer to check for potential issues when committing code.
44+
45+
```bash
46+
pip install pre-commit
47+
pre-commit install
48+
pre-commit install --hook-type commit-msg
49+
pre-commit run --all-files # Check if everything is okay
50+
```

0 commit comments

Comments
 (0)