flask-tailwind-manager 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flask_tailwind_manager-0.0.1/LICENSE +21 -0
- flask_tailwind_manager-0.0.1/PKG-INFO +112 -0
- flask_tailwind_manager-0.0.1/README.md +76 -0
- flask_tailwind_manager-0.0.1/pyproject.toml +24 -0
- flask_tailwind_manager-0.0.1/setup.cfg +4 -0
- flask_tailwind_manager-0.0.1/setup.py +3 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind/__init__.py +3 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind/cli.py +88 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind/console.py +48 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind/py.typed +0 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind/tailwind.py +101 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind_manager.egg-info/PKG-INFO +112 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind_manager.egg-info/SOURCES.txt +14 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind_manager.egg-info/dependency_links.txt +1 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind_manager.egg-info/requires.txt +1 -0
- flask_tailwind_manager-0.0.1/src/flask_tailwind_manager.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Sebastian Salinas Del Rio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: flask-tailwind-manager
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Easily use tailwind css with Flask projects
|
|
5
|
+
Author-email: Sebastian Salinas <seba.salinas.delrio@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Sebastian Salinas Del Rio
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Project-URL: Homepage, https://github.com/sebasalinass/flask-tailwindcss
|
|
28
|
+
Keywords: flask,tailwind,tailwindcss
|
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
30
|
+
Classifier: Programming Language :: Python
|
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
|
32
|
+
Requires-Python: >=3.11
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: flask<4,>=3.0.0
|
|
36
|
+
|
|
37
|
+
# Flask-Tailwind-Manager
|
|
38
|
+
|
|
39
|
+
Flask-Tailwind-Manager provides a simple interface to use TailwindCSS with your Flask project. It will let you hide it in a folder called .tailwind so you dont have to see any node_modules or any other javascript. Even tho you DO need npm and npx to be available on your machine.
|
|
40
|
+
|
|
41
|
+
```{warning}
|
|
42
|
+
🚧 This package is under heavy development..
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
Install the extension with pip:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install flask-tailwind-manager
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
This are some of the settings available. All of the configurations are optional, and in most cases it should work without any configuration.
|
|
56
|
+
|
|
57
|
+
| Config | Description | Type | Default |
|
|
58
|
+
| ---------------------------------------- | --------------------------------------- | ---- | --------------- |
|
|
59
|
+
| TAILWIND_CWD | CWD for node_modules. | str | `.tailwind` |
|
|
60
|
+
| TAILWIND_OUTPUT_PATH | CSS file output path inside app static. | str | `css/style.css` |
|
|
61
|
+
| TAILWIND_NPM_BIN_PATH | Npm binary path. | str | `npm` |
|
|
62
|
+
| TAILWIND_NPX_BIN_PATH | Npx binary path. | str | `npx` |
|
|
63
|
+
| TAILWIND_TEMPLATE_FOLDER | Name of the templates folder. | str | `templates` |
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
Once installed Flask-TailwindCSS is easy to use. Let's walk through setting up a basic application. Also please note that this is a very basic guide: we will be taking shortcuts here that you should never take in a real application.
|
|
68
|
+
|
|
69
|
+
To begin we'll set up a Flask app:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from flask import Flask
|
|
73
|
+
from flask_tailwind import TailwindCSS
|
|
74
|
+
|
|
75
|
+
app = Flask(__name__)
|
|
76
|
+
|
|
77
|
+
tailwind = TailwindCSS()
|
|
78
|
+
tailwind.init_app(app)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Using the CLI tool.
|
|
82
|
+
|
|
83
|
+
Once you completed the extension configuration, you can access the Flask-TailwindCSS CLI tool. There is 4 useful commands you will use.
|
|
84
|
+
|
|
85
|
+
1. Installing Node and TailwindCSS basic configuration. By default this extension will generate a `tailwind.config.js` generic file, ready to use. If you need to futher customize you will need to edit this file accordingly.
|
|
86
|
+
```bash
|
|
87
|
+
flask tailwind init
|
|
88
|
+
```
|
|
89
|
+
2. Once installed all modules will be found on `.tailwind` folder (or CWD you define). The default configuration will look for changes at `{APP_NAME}/**/{TEMPLATES_FOLDER}/*{.html,.jinja,.j2}`. You can always modify `tailwind.config.js` file in order to customize it.
|
|
90
|
+
|
|
91
|
+
3. To start watching files and changes. use the `start` command as follows.
|
|
92
|
+
```bash
|
|
93
|
+
flask tailwind start
|
|
94
|
+
```
|
|
95
|
+
4. Almost every time you are using you will install plugins like Preline, Flowbite, daysiUI, etc... For this cases you can use the `npx` or `npm` commands. In the following example we will install the PrelineUI plugin as follows.
|
|
96
|
+
```bash
|
|
97
|
+
flask tailwind npm i preline
|
|
98
|
+
```
|
|
99
|
+
5. After the installation you will have to configure it manually.
|
|
100
|
+
|
|
101
|
+
This will ensure the plugins are installed in the correct CWD.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
## Load resources
|
|
105
|
+
|
|
106
|
+
Once the extension is set up, this will make available the `tailwind_css` function into the templates context so you could load the generated css like this.
|
|
107
|
+
|
|
108
|
+
```html
|
|
109
|
+
<head>
|
|
110
|
+
{{ tailwind_css() }}
|
|
111
|
+
</head>
|
|
112
|
+
```
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Flask-Tailwind-Manager
|
|
2
|
+
|
|
3
|
+
Flask-Tailwind-Manager provides a simple interface to use TailwindCSS with your Flask project. It will let you hide it in a folder called .tailwind so you dont have to see any node_modules or any other javascript. Even tho you DO need npm and npx to be available on your machine.
|
|
4
|
+
|
|
5
|
+
```{warning}
|
|
6
|
+
🚧 This package is under heavy development..
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Install the extension with pip:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install flask-tailwind-manager
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Configuration
|
|
18
|
+
|
|
19
|
+
This are some of the settings available. All of the configurations are optional, and in most cases it should work without any configuration.
|
|
20
|
+
|
|
21
|
+
| Config | Description | Type | Default |
|
|
22
|
+
| ---------------------------------------- | --------------------------------------- | ---- | --------------- |
|
|
23
|
+
| TAILWIND_CWD | CWD for node_modules. | str | `.tailwind` |
|
|
24
|
+
| TAILWIND_OUTPUT_PATH | CSS file output path inside app static. | str | `css/style.css` |
|
|
25
|
+
| TAILWIND_NPM_BIN_PATH | Npm binary path. | str | `npm` |
|
|
26
|
+
| TAILWIND_NPX_BIN_PATH | Npx binary path. | str | `npx` |
|
|
27
|
+
| TAILWIND_TEMPLATE_FOLDER | Name of the templates folder. | str | `templates` |
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
Once installed Flask-TailwindCSS is easy to use. Let's walk through setting up a basic application. Also please note that this is a very basic guide: we will be taking shortcuts here that you should never take in a real application.
|
|
32
|
+
|
|
33
|
+
To begin we'll set up a Flask app:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from flask import Flask
|
|
37
|
+
from flask_tailwind import TailwindCSS
|
|
38
|
+
|
|
39
|
+
app = Flask(__name__)
|
|
40
|
+
|
|
41
|
+
tailwind = TailwindCSS()
|
|
42
|
+
tailwind.init_app(app)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Using the CLI tool.
|
|
46
|
+
|
|
47
|
+
Once you completed the extension configuration, you can access the Flask-TailwindCSS CLI tool. There is 4 useful commands you will use.
|
|
48
|
+
|
|
49
|
+
1. Installing Node and TailwindCSS basic configuration. By default this extension will generate a `tailwind.config.js` generic file, ready to use. If you need to futher customize you will need to edit this file accordingly.
|
|
50
|
+
```bash
|
|
51
|
+
flask tailwind init
|
|
52
|
+
```
|
|
53
|
+
2. Once installed all modules will be found on `.tailwind` folder (or CWD you define). The default configuration will look for changes at `{APP_NAME}/**/{TEMPLATES_FOLDER}/*{.html,.jinja,.j2}`. You can always modify `tailwind.config.js` file in order to customize it.
|
|
54
|
+
|
|
55
|
+
3. To start watching files and changes. use the `start` command as follows.
|
|
56
|
+
```bash
|
|
57
|
+
flask tailwind start
|
|
58
|
+
```
|
|
59
|
+
4. Almost every time you are using you will install plugins like Preline, Flowbite, daysiUI, etc... For this cases you can use the `npx` or `npm` commands. In the following example we will install the PrelineUI plugin as follows.
|
|
60
|
+
```bash
|
|
61
|
+
flask tailwind npm i preline
|
|
62
|
+
```
|
|
63
|
+
5. After the installation you will have to configure it manually.
|
|
64
|
+
|
|
65
|
+
This will ensure the plugins are installed in the correct CWD.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Load resources
|
|
69
|
+
|
|
70
|
+
Once the extension is set up, this will make available the `tailwind_css` function into the templates context so you could load the generated css like this.
|
|
71
|
+
|
|
72
|
+
```html
|
|
73
|
+
<head>
|
|
74
|
+
{{ tailwind_css() }}
|
|
75
|
+
</head>
|
|
76
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "flask-tailwind-manager"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Easily use tailwind css with Flask projects"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{ name = "Sebastian Salinas", email = "seba.salinas.delrio@gmail.com" }]
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
classifiers = [
|
|
13
|
+
"License :: OSI Approved :: MIT License",
|
|
14
|
+
"Programming Language :: Python",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
]
|
|
17
|
+
keywords = ["flask", "tailwind", "tailwindcss"]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"flask >= 3.0.0, < 4",
|
|
20
|
+
]
|
|
21
|
+
requires-python = ">=3.11"
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
Homepage = "https://github.com/sebasalinass/flask-tailwindcss"
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Tuple
|
|
2
|
+
import shutil
|
|
3
|
+
import sys
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
from flask.cli import with_appcontext
|
|
8
|
+
from flask import current_app
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from .tailwind import TailwindCSS
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def install_if_needed(tailwind: "TailwindCSS"):
|
|
15
|
+
if not tailwind.node_destination_path().exists():
|
|
16
|
+
logging.info(
|
|
17
|
+
f"No {tailwind.node_destination_path()} directory found. Running 'npm install'."
|
|
18
|
+
)
|
|
19
|
+
init()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@click.group()
|
|
23
|
+
def tailwind():
|
|
24
|
+
"""Perform TailwindCSS operations."""
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@tailwind.command()
|
|
29
|
+
@with_appcontext
|
|
30
|
+
def init():
|
|
31
|
+
tailwind: "TailwindCSS" = current_app.extensions["tailwind"]
|
|
32
|
+
|
|
33
|
+
source_dir = tailwind.node_config_starter_path()
|
|
34
|
+
dest_dir = tailwind.node_destination_path()
|
|
35
|
+
|
|
36
|
+
if dest_dir.exists():
|
|
37
|
+
logging.info("🍃 Destination path already exists. Aborting")
|
|
38
|
+
sys.exit(1)
|
|
39
|
+
|
|
40
|
+
shutil.copytree(source_dir, dest_dir)
|
|
41
|
+
logging.info(f"🍃 Copying default configuration files into {dest_dir}")
|
|
42
|
+
|
|
43
|
+
with open(dest_dir / "package.json", "w") as file:
|
|
44
|
+
file.write(tailwind.package_json_str())
|
|
45
|
+
|
|
46
|
+
with open(dest_dir / "tailwind.config.js", "w") as file:
|
|
47
|
+
file.write(tailwind.tailwind_config_js_str())
|
|
48
|
+
|
|
49
|
+
logging.info(f"🍃 Installing dependencies in {tailwind.cwd}")
|
|
50
|
+
console = tailwind.get_console_interface()
|
|
51
|
+
console.npm_run("-D", "install", "tailwindcss")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@tailwind.command()
|
|
55
|
+
@with_appcontext
|
|
56
|
+
def start():
|
|
57
|
+
"""Start watching CSS changes for dev."""
|
|
58
|
+
tailwind: "TailwindCSS" = current_app.extensions["tailwind"]
|
|
59
|
+
install_if_needed(tailwind)
|
|
60
|
+
console = tailwind.get_console_interface()
|
|
61
|
+
console.npx_run(
|
|
62
|
+
"tailwindcss",
|
|
63
|
+
"-i",
|
|
64
|
+
"./src/input.css",
|
|
65
|
+
"-o",
|
|
66
|
+
"../" + str(tailwind.get_output_path()),
|
|
67
|
+
"--watch",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@tailwind.command()
|
|
72
|
+
@click.argument("args", nargs=-1)
|
|
73
|
+
@with_appcontext
|
|
74
|
+
def npm(args: Tuple[str]) -> None:
|
|
75
|
+
tailwind: "TailwindCSS" = current_app.extensions["tailwind"]
|
|
76
|
+
install_if_needed(tailwind)
|
|
77
|
+
console = tailwind.get_console_interface()
|
|
78
|
+
console.npm_run(*args)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@tailwind.command()
|
|
82
|
+
@click.argument("args", nargs=-1)
|
|
83
|
+
@with_appcontext
|
|
84
|
+
def npx(args: Tuple[str]) -> None:
|
|
85
|
+
tailwind: "TailwindCSS" = current_app.extensions["tailwind"]
|
|
86
|
+
install_if_needed(tailwind)
|
|
87
|
+
console = tailwind.get_console_interface()
|
|
88
|
+
console.npx_run(*args)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import logging
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
DEFAULT_NPM_BIN_PATH = "npm"
|
|
6
|
+
DEFAULT_NPX_BIN_PATH = "npx"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class NPMError(Exception):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NPXError(Exception):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ConsoleInterface:
|
|
18
|
+
cwd: str
|
|
19
|
+
npm_bin_path: str
|
|
20
|
+
npx_bin_path: str
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
cwd="",
|
|
25
|
+
npm_bin_path: Optional[str] = None,
|
|
26
|
+
npx_bin_path: Optional[str] = None,
|
|
27
|
+
):
|
|
28
|
+
self.npm_bin_path = npm_bin_path or DEFAULT_NPM_BIN_PATH
|
|
29
|
+
self.npx_bin_path = npx_bin_path or DEFAULT_NPX_BIN_PATH
|
|
30
|
+
self.cwd = cwd
|
|
31
|
+
|
|
32
|
+
def npm_run(self, *args: str) -> None:
|
|
33
|
+
try:
|
|
34
|
+
logging.debug(f"🍃 Running npm with args {' '.join(list(args))}")
|
|
35
|
+
subprocess.run([self.npm_bin_path] + list(args), cwd=self.cwd)
|
|
36
|
+
except OSError:
|
|
37
|
+
raise NPMError(
|
|
38
|
+
"It looks like node.js and/or npm is not installed or cannot be found. Visit https://nodejs.org to download and install node.js for your system."
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def npx_run(self, *args: str) -> None:
|
|
42
|
+
try:
|
|
43
|
+
logging.debug(f"🍃 Running npx with args {' '.join(list(args))}")
|
|
44
|
+
subprocess.run([self.npx_bin_path] + list(args), cwd=self.cwd)
|
|
45
|
+
except OSError:
|
|
46
|
+
raise NPXError(
|
|
47
|
+
"It looks like node.js and/or npx is not installed or cannot be found. Visit https://nodejs.org to download and install node.js for your system."
|
|
48
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from flask import Flask, Blueprint, render_template
|
|
4
|
+
from .console import ConsoleInterface, DEFAULT_NPM_BIN_PATH, DEFAULT_NPX_BIN_PATH
|
|
5
|
+
from .cli import tailwind
|
|
6
|
+
|
|
7
|
+
DEFAULT_CWD = ".tailwind"
|
|
8
|
+
DEFAULT_OUTPUT_PATH = "css/style.css"
|
|
9
|
+
DEFAULT_TEMPLATE_FOLDER = "templates"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TailwindCSS:
|
|
13
|
+
cwd: str = DEFAULT_CWD
|
|
14
|
+
npm_bin_path: str = DEFAULT_NPM_BIN_PATH
|
|
15
|
+
npx_bin_path: str = DEFAULT_NPX_BIN_PATH
|
|
16
|
+
output_css_path: str = DEFAULT_OUTPUT_PATH
|
|
17
|
+
template_folder: str = DEFAULT_TEMPLATE_FOLDER
|
|
18
|
+
app_static_folder: Optional[str] = None
|
|
19
|
+
|
|
20
|
+
def __init__(self, app: Optional[Flask] = None):
|
|
21
|
+
if app is not None:
|
|
22
|
+
self.init_app(app)
|
|
23
|
+
|
|
24
|
+
def init_app(self, app: Flask) -> None:
|
|
25
|
+
if "tailwind" in app.extensions:
|
|
26
|
+
raise RuntimeError(
|
|
27
|
+
"This extension is already registered on this Flask app."
|
|
28
|
+
)
|
|
29
|
+
app.extensions["tailwind"] = self
|
|
30
|
+
self.cwd = app.config.get("TAILWIND_CWD", DEFAULT_CWD)
|
|
31
|
+
self.output_css_path: str = app.config.get(
|
|
32
|
+
"TAILWIND_OUTPUT_PATH", DEFAULT_OUTPUT_PATH
|
|
33
|
+
)
|
|
34
|
+
self.npm_bin_path: str = app.config.get(
|
|
35
|
+
"TAILWIND_NPM_BIN_PATH", DEFAULT_NPM_BIN_PATH
|
|
36
|
+
)
|
|
37
|
+
self.npx_bin_path: str = app.config.get(
|
|
38
|
+
"TAILWIND_NPX_BIN_PATH", DEFAULT_NPX_BIN_PATH
|
|
39
|
+
)
|
|
40
|
+
self.template_folder: str = app.config.get(
|
|
41
|
+
"TAILWIND_TEMPLATE_FOLDER", DEFAULT_TEMPLATE_FOLDER
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if not app.static_folder:
|
|
45
|
+
raise AttributeError("Given app static_folder must be setted.")
|
|
46
|
+
|
|
47
|
+
self.app_static_folder = app.static_folder
|
|
48
|
+
self.app_name = app.name
|
|
49
|
+
self.__register_blueprint(app)
|
|
50
|
+
self.__register_app_global(app)
|
|
51
|
+
self.__register_tailwind_command(app)
|
|
52
|
+
|
|
53
|
+
def __register_tailwind_command(self, app: Flask) -> None:
|
|
54
|
+
app.cli.add_command(tailwind)
|
|
55
|
+
|
|
56
|
+
def get_console_interface(self) -> ConsoleInterface:
|
|
57
|
+
return ConsoleInterface(self.cwd, self.npm_bin_path, self.npx_bin_path)
|
|
58
|
+
|
|
59
|
+
def node_config_starter_path(self) -> Path:
|
|
60
|
+
return Path(__file__).parent / "starter"
|
|
61
|
+
|
|
62
|
+
def node_destination_path(self) -> Path:
|
|
63
|
+
return Path(self.cwd)
|
|
64
|
+
|
|
65
|
+
def get_output_path(self) -> Path:
|
|
66
|
+
if not self.app_static_folder:
|
|
67
|
+
raise AttributeError(
|
|
68
|
+
"There is no `app_static_folder` set. You must call `init_app` method or pass the app on extension creation."
|
|
69
|
+
)
|
|
70
|
+
static_path = Path(self.app_static_folder)
|
|
71
|
+
static_relative = static_path.relative_to(static_path.parent.parent)
|
|
72
|
+
output_path = static_relative / self.output_css_path
|
|
73
|
+
return output_path
|
|
74
|
+
|
|
75
|
+
def package_json_str(self) -> str:
|
|
76
|
+
app_name = self.app_name or "tailwind-app"
|
|
77
|
+
output_path = self.get_output_path()
|
|
78
|
+
return render_template(
|
|
79
|
+
"package.json.jinja", app_name=app_name, output_path=output_path
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
def tailwind_config_js_str(self) -> str:
|
|
83
|
+
app_name = self.app_name or "tailwind-app"
|
|
84
|
+
return render_template(
|
|
85
|
+
"tailwind.config.js.jinja",
|
|
86
|
+
app_name=app_name,
|
|
87
|
+
templates_folder=self.template_folder,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def __tailwind_css_tag(self) -> str:
|
|
91
|
+
return render_template("load.jinja", filename=self.output_css_path)
|
|
92
|
+
|
|
93
|
+
def __register_app_global(self, app: Flask) -> None:
|
|
94
|
+
app.add_template_global(self.__tailwind_css_tag, "tailwind_css")
|
|
95
|
+
|
|
96
|
+
def __register_blueprint(self, app: Flask) -> None:
|
|
97
|
+
app.register_blueprint(
|
|
98
|
+
Blueprint(
|
|
99
|
+
name="tailwind", import_name=__name__, template_folder="templates"
|
|
100
|
+
)
|
|
101
|
+
)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: flask-tailwind-manager
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Easily use tailwind css with Flask projects
|
|
5
|
+
Author-email: Sebastian Salinas <seba.salinas.delrio@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Sebastian Salinas Del Rio
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Project-URL: Homepage, https://github.com/sebasalinass/flask-tailwindcss
|
|
28
|
+
Keywords: flask,tailwind,tailwindcss
|
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
30
|
+
Classifier: Programming Language :: Python
|
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
|
32
|
+
Requires-Python: >=3.11
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: flask<4,>=3.0.0
|
|
36
|
+
|
|
37
|
+
# Flask-Tailwind-Manager
|
|
38
|
+
|
|
39
|
+
Flask-Tailwind-Manager provides a simple interface to use TailwindCSS with your Flask project. It will let you hide it in a folder called .tailwind so you dont have to see any node_modules or any other javascript. Even tho you DO need npm and npx to be available on your machine.
|
|
40
|
+
|
|
41
|
+
```{warning}
|
|
42
|
+
🚧 This package is under heavy development..
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
Install the extension with pip:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install flask-tailwind-manager
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
This are some of the settings available. All of the configurations are optional, and in most cases it should work without any configuration.
|
|
56
|
+
|
|
57
|
+
| Config | Description | Type | Default |
|
|
58
|
+
| ---------------------------------------- | --------------------------------------- | ---- | --------------- |
|
|
59
|
+
| TAILWIND_CWD | CWD for node_modules. | str | `.tailwind` |
|
|
60
|
+
| TAILWIND_OUTPUT_PATH | CSS file output path inside app static. | str | `css/style.css` |
|
|
61
|
+
| TAILWIND_NPM_BIN_PATH | Npm binary path. | str | `npm` |
|
|
62
|
+
| TAILWIND_NPX_BIN_PATH | Npx binary path. | str | `npx` |
|
|
63
|
+
| TAILWIND_TEMPLATE_FOLDER | Name of the templates folder. | str | `templates` |
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
Once installed Flask-TailwindCSS is easy to use. Let's walk through setting up a basic application. Also please note that this is a very basic guide: we will be taking shortcuts here that you should never take in a real application.
|
|
68
|
+
|
|
69
|
+
To begin we'll set up a Flask app:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from flask import Flask
|
|
73
|
+
from flask_tailwind import TailwindCSS
|
|
74
|
+
|
|
75
|
+
app = Flask(__name__)
|
|
76
|
+
|
|
77
|
+
tailwind = TailwindCSS()
|
|
78
|
+
tailwind.init_app(app)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Using the CLI tool.
|
|
82
|
+
|
|
83
|
+
Once you completed the extension configuration, you can access the Flask-TailwindCSS CLI tool. There is 4 useful commands you will use.
|
|
84
|
+
|
|
85
|
+
1. Installing Node and TailwindCSS basic configuration. By default this extension will generate a `tailwind.config.js` generic file, ready to use. If you need to futher customize you will need to edit this file accordingly.
|
|
86
|
+
```bash
|
|
87
|
+
flask tailwind init
|
|
88
|
+
```
|
|
89
|
+
2. Once installed all modules will be found on `.tailwind` folder (or CWD you define). The default configuration will look for changes at `{APP_NAME}/**/{TEMPLATES_FOLDER}/*{.html,.jinja,.j2}`. You can always modify `tailwind.config.js` file in order to customize it.
|
|
90
|
+
|
|
91
|
+
3. To start watching files and changes. use the `start` command as follows.
|
|
92
|
+
```bash
|
|
93
|
+
flask tailwind start
|
|
94
|
+
```
|
|
95
|
+
4. Almost every time you are using you will install plugins like Preline, Flowbite, daysiUI, etc... For this cases you can use the `npx` or `npm` commands. In the following example we will install the PrelineUI plugin as follows.
|
|
96
|
+
```bash
|
|
97
|
+
flask tailwind npm i preline
|
|
98
|
+
```
|
|
99
|
+
5. After the installation you will have to configure it manually.
|
|
100
|
+
|
|
101
|
+
This will ensure the plugins are installed in the correct CWD.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
## Load resources
|
|
105
|
+
|
|
106
|
+
Once the extension is set up, this will make available the `tailwind_css` function into the templates context so you could load the generated css like this.
|
|
107
|
+
|
|
108
|
+
```html
|
|
109
|
+
<head>
|
|
110
|
+
{{ tailwind_css() }}
|
|
111
|
+
</head>
|
|
112
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
src/flask_tailwind/__init__.py
|
|
6
|
+
src/flask_tailwind/cli.py
|
|
7
|
+
src/flask_tailwind/console.py
|
|
8
|
+
src/flask_tailwind/py.typed
|
|
9
|
+
src/flask_tailwind/tailwind.py
|
|
10
|
+
src/flask_tailwind_manager.egg-info/PKG-INFO
|
|
11
|
+
src/flask_tailwind_manager.egg-info/SOURCES.txt
|
|
12
|
+
src/flask_tailwind_manager.egg-info/dependency_links.txt
|
|
13
|
+
src/flask_tailwind_manager.egg-info/requires.txt
|
|
14
|
+
src/flask_tailwind_manager.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
flask<4,>=3.0.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
flask_tailwind
|