|
1 | 1 | --- |
2 | 2 | title: Development |
3 | 3 | order: 12 |
4 | | -description: Development guide and best practices for Unfold. |
5 | 4 | --- |
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. |
0 commit comments