Skip to content

Commit 0ce6342

Browse files
committed
Merge branch 'main' of github.com:S4NKALP/djinit
2 parents 0c7b007 + eaddc45 commit 0ce6342

7 files changed

Lines changed: 89 additions & 2 deletions

File tree

src/djinit/core/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class ProjectMetadata:
1515
nested_dir: str | None = None
1616
use_database_url: bool = False
1717
database_type: str = "postgresql"
18+
use_tailwind: bool = False
19+
use_htmx: bool = False
1820
predefined_structure: bool = False
1921
unified_structure: bool = False
2022
single_structure: bool = False
@@ -29,6 +31,8 @@ def to_dict(self) -> dict:
2931
"nested_dir": self.nested_dir,
3032
"use_database_url": self.use_database_url,
3133
"database_type": self.database_type,
34+
"use_tailwind": self.use_tailwind,
35+
"use_htmx": self.use_htmx,
3236
"predefined_structure": self.predefined_structure,
3337
"unified_structure": self.unified_structure,
3438
"single_structure": self.single_structure,

src/djinit/creators/files.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def _create_settings_package(self, settings_dir: str, base_context: dict, prefix
8888
for name in base_settings_context["app_names"]
8989
]
9090

91+
# Add Tailwind and HTMX to context
92+
base_settings_context["use_tailwind"] = self.metadata.get("use_tailwind", False)
93+
base_settings_context["use_htmx"] = self.metadata.get("use_htmx", False)
94+
9195
for filename, context in [
9296
("base.py", base_settings_context),
9397
("development.py", dev_context),
@@ -134,6 +138,8 @@ def create_requirements(self) -> None:
134138
context = {
135139
"use_database_url": self.metadata.get("use_database_url", True),
136140
"database_type": self.metadata.get("database_type", "postgresql"),
141+
"use_tailwind": self.metadata.get("use_tailwind", False),
142+
"use_htmx": self.metadata.get("use_htmx", False),
137143
}
138144
self._render_and_create_file(
139145
"requirements.txt",
@@ -413,6 +419,8 @@ def create_djinit_config(self) -> None:
413419
"settings": {
414420
"use_database_url": self.metadata.get("use_database_url", True),
415421
"database_type": self.metadata.get("database_type", "postgresql"),
422+
"use_tailwind": self.metadata.get("use_tailwind", False),
423+
"use_htmx": self.metadata.get("use_htmx", False),
416424
},
417425
"cicd": {
418426
"github": self.metadata.get("use_github_actions", False),

src/djinit/templates/config/settings/base.py-tpl

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ THIRD_PARTY_APPS = [
2626
"rest_framework_simplejwt.token_blacklist",
2727
"corsheaders",
2828
"drf_spectacular",
29+
"django_tailwind_cli", # @IF use_tailwind
30+
"django_htmx", # @IF use_htmx
2931
]
3032

3133
USER_DEFINED_APPS = [
@@ -56,6 +58,7 @@ MIDDLEWARE = [
5658
"django.contrib.auth.middleware.AuthenticationMiddleware",
5759
"django.contrib.messages.middleware.MessageMiddleware",
5860
"django.middleware.clickjacking.XFrameOptionsMiddleware",
61+
"django_htmx.middleware.HtmxMiddleware", # @IF use_htmx
5962
]
6063

6164
ROOT_URLCONF = "[[ project_name ]].urls"
@@ -106,10 +109,10 @@ USE_I18N = True
106109
USE_TZ = True
107110

108111
# Static files and media files
109-
STATIC_URL = "static/"
112+
STATIC_URL = "/static/"
110113
STATIC_ROOT = BASE_DIR / "staticfiles"
111114

112-
MEDIA_URL = "media/"
115+
MEDIA_URL = "/media/"
113116
MEDIA_ROOT = BASE_DIR / "media"
114117

115118
STORAGES = {
@@ -185,3 +188,40 @@ CORS_PREFLIGHT_MAX_AGE = 86400 # 24 hours
185188
SECURE_BROWSER_XSS_FILTER = True
186189
SECURE_CONTENT_TYPE_NOSNIFF = True
187190
X_FRAME_OPTIONS = "DENY"
191+
192+
# @IF use_tailwind
193+
# for tailwind
194+
STATICFILES_DIRS = [BASE_DIR / "static/"]
195+
TAILWIND_CLI_VERSION = "2.7.8"
196+
TAILWIND_CLI_USE_DAISY_UI = True
197+
TAILWIND_CLI_CONFIG = {
198+
"theme": {
199+
"extend": {
200+
"colors": {
201+
"primary": "#DC2626",
202+
"secondary": "#EF4444",
203+
"accent": "#FCFECC",
204+
}
205+
}
206+
},
207+
"daisyui": {
208+
"themes": [
209+
{
210+
"light": {
211+
"primary": "#DC2626",
212+
"secondary": "#EF4444",
213+
"accent": "#FCFECC",
214+
"neutral": "#1a1a2e",
215+
"base-100": "#ffffff",
216+
"base-200": "#f8fafc",
217+
"base-300": "#e2e8f0",
218+
"info": "#0E4D80",
219+
"success": "#16a34a",
220+
"warning": "#f59e0b",
221+
"error": "#DC2626",
222+
}
223+
}
224+
]
225+
},
226+
}
227+
# @ENDIF

src/djinit/templates/config/settings/production.py-tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,10 @@ CSRF_COOKIE_SECURE = True
6565

6666
# Static files
6767
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
68+
69+
# @IF use_tailwind
70+
## Tailwind
71+
TAILWIND_CLI_VERSION = "4.1.3" # Pin version
72+
TAILWIND_CLI_AUTOMATIC_DOWNLOAD = False # Use pre-installed CLI
73+
TAILWIND_CLI_DIST_CSS = "static/css/tailwind.min.css"
74+
# @ENDIF

src/djinit/templates/project/requirements-tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ djangorestframework_simplejwt
1010
drf-spectacular
1111
django-cors-headers
1212
whitenoise
13+
django-tailwind-cli # @IF use_tailwind
14+
django-htmx # @IF use_htmx
1315
# @IF database_type == 'mysql'
1416
mysqlclient
1517
# @ELSE

src/djinit/ui/input.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class StructureOptions(TypedDict):
2323
single_module_name: str | None
2424
database_type: str
2525
use_database_url: bool
26+
use_tailwind: bool
27+
use_htmx: bool
2628
use_github: bool
2729
use_gitlab: bool
2830

@@ -171,6 +173,12 @@ def get_database_type_choice(self) -> str:
171173

172174
return self._get_selection("Choose database:", choices, default="postgresql")
173175

176+
def get_tailwind_choice(self) -> bool:
177+
return UIFormatter.confirm("Include Tailwind CSS? (via django-tailwind-cli)", default=True)
178+
179+
def get_htmx_choice(self) -> bool:
180+
return UIFormatter.confirm("Include HTMX? (via django-htmx)", default=True)
181+
174182
def _get_structure_metadata(self, options: StructureOptions) -> Tuple[str, str, list[str], dict]:
175183
"""Helper method to generate metadata dictionary."""
176184
project_dir = options["project_dir"]
@@ -193,6 +201,8 @@ def _get_structure_metadata(self, options: StructureOptions) -> Tuple[str, str,
193201
nested_dir="apps" if not options["single"] else None,
194202
use_database_url=options["use_database_url"],
195203
database_type=options["database_type"],
204+
use_tailwind=options.get("use_tailwind", False),
205+
use_htmx=options.get("use_htmx", False),
196206
predefined_structure=options["predefined"],
197207
unified_structure=options["unified"],
198208
single_structure=options["single"],
@@ -250,6 +260,10 @@ def get_user_input() -> Tuple[str, str, str, list, dict]:
250260
database_type = collector.get_database_type_choice()
251261
use_database_url = collector.get_database_config_choice()
252262

263+
# Step 3: Tailwind and HTMX
264+
use_tailwind = collector.get_tailwind_choice()
265+
use_htmx = collector.get_htmx_choice()
266+
253267
# Step 3: Django Apps (Standard only)
254268
nested = False
255269
nested_dir = None
@@ -273,6 +287,8 @@ def get_user_input() -> Tuple[str, str, str, list, dict]:
273287
nested_dir=nested_dir,
274288
use_database_url=use_database_url,
275289
database_type=database_type,
290+
use_tailwind=use_tailwind,
291+
use_htmx=use_htmx,
276292
)
277293
return project_dir, project_name, app_names[0], app_names, metadata.to_dict()
278294
else:
@@ -284,6 +300,8 @@ def get_user_input() -> Tuple[str, str, str, list, dict]:
284300
single_module_name=single_module_name,
285301
database_type=database_type,
286302
use_database_url=use_database_url,
303+
use_tailwind=use_tailwind,
304+
use_htmx=use_htmx,
287305
use_github=use_github,
288306
use_gitlab=use_gitlab,
289307
)
@@ -316,6 +334,12 @@ def confirm_setup(project_dir: str, project_name: str, app_names: list, metadata
316334
db_type = metadata.get("database_type", "postgresql").capitalize()
317335
console.print(f"[{UIColors.HIGHLIGHT}]Database Type:[/{UIColors.HIGHLIGHT}] {db_type}")
318336

337+
use_tailwind = "Yes" if metadata.get("use_tailwind", False) else "No"
338+
console.print(f"[{UIColors.HIGHLIGHT}]Tailwind CSS:[/{UIColors.HIGHLIGHT}] {use_tailwind}")
339+
340+
use_htmx = "Yes" if metadata.get("use_htmx", False) else "No"
341+
console.print(f"[{UIColors.HIGHLIGHT}]HTMX:[/{UIColors.HIGHLIGHT}] {use_htmx}")
342+
319343
console.print()
320344
UIFormatter.print_separator()
321345
console.print()

src/djinit/utils/django.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def startproject(project_name: str, directory: str, unified: bool = False, metad
4444
"app_names": [],
4545
"use_database_url": metadata.get("use_database_url", True),
4646
"database_type": metadata.get("database_type", "postgresql"),
47+
"use_tailwind": metadata.get("use_tailwind", False),
48+
"use_htmx": metadata.get("use_htmx", False),
4749
}
4850

4951
dev_context = {"secret_key": secret_key}

0 commit comments

Comments
 (0)