Skip to content

Commit 0a6801a

Browse files
committed
CLeanup.
1 parent 3a17066 commit 0a6801a

25 files changed

+100
-90
lines changed

Pipfile.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,34 @@
1010

1111
![Flask Assets Tutorial](https://github.com/hackersandslackers/flask-assets-tutorial/.github/[email protected])
1212

13-
Structure your Flask apps in a scalable and intelligent way using Blueprints. This repository contains source code for the accompanying tutorial on Hackers and Slackers: https://hackersandslackers.com/flask-blueprints/
13+
Build and code-split your frontend assets across Blueprints using Flask-Assets. Accompanying tutorial on Hackers and Slackers here: https://hackersandslackers.com/flask-assets/
1414

15-
## Getting Started
15+
## Installation
1616

17-
Installation is recommended with Pipenv:
17+
**Installation via `requirements.txt`**:
1818

1919
```shell
20-
$ git clone https://github.com/hackersandslackers/flask-assets-tutorial.git
20+
$ git clone https://github.com/hackersandslackers/fflask-assets-tutorial.git
2121
$ cd flask-assets-tutorial
22-
$ pipenv shell
23-
$ pipenv update
24-
$ pip install lesscpy cssmin jsmin
25-
$ python3 main.py
22+
$ python3 -m venv myenv
23+
$ source myenv/bin/activate
24+
$ pip3 install -r requirements.txt
25+
$ flask run
2626
```
2727

28-
Alternatively, try installing via **setup.py**:
28+
**Installation via [Pipenv](https://pipenv-fork.readthedocs.io/en/latest/)**:
2929

3030
```shell
3131
$ git clone https://github.com/hackersandslackers/flask-assets-tutorial.git
3232
$ cd flask-assets-tutorial
33-
$ python3 setup.py install
34-
$ pip install lesscpy cssmin jsmin
35-
$ python3 main.py
33+
$ pipenv shell
34+
$ pipenv update
35+
$ flask run
3636
```
3737
-----
3838

3939
**Hackers and Slackers** tutorials are free of charge. If you found this tutorial helpful, a [small donation](https://www.buymeacoffee.com/hackersslackers) would be greatly appreciated to keep us in business. All proceeds go towards coffee, and all coffee goes towards more content.
40+
-----
41+
42+
**Hackers and Slackers** tutorials are free of charge. If you found this tutorial helpful, a [small donation](https://www.buymeacoffee.com/hackersslackers) would be greatly appreciated to keep us in business. All proceeds go towards coffee, and all coffee goes towards more content.
4043

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
"""Initialize app."""
22
from flask import Flask
33
from flask_assets import Environment
4-
from .assets import compile_assets
5-
6-
assets = Environment()
74

85

96
def create_app():
10-
"""Construct the core flask_assets_tutorial."""
7+
"""Construct the core application."""
118
app = Flask(__name__, instance_relative_config=False)
129
app.config.from_object('config.Config')
10+
assets = Environment()
11+
assets.init_app(app)
1312

1413
# Initialize plugins
1514
assets.init_app(app)
1615

1716
with app.app_context():
18-
# Import parts of our flask_assets_tutorial
17+
# Import parts of our application
1918
from .admin import admin_routes
2019
from .main import main_routes
20+
from .assets import compile_static_assets
21+
22+
# Register Blueprints
2123
app.register_blueprint(admin_routes.admin_bp)
2224
app.register_blueprint(main_routes.main_bp)
23-
compile_assets(assets)
25+
26+
# Compile static assets
27+
compile_static_assets(assets)
2428

2529
return app

flask_assets_tutorial/admin/admin_routes.py renamed to application/admin/admin_routes.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
from flask import Blueprint, render_template
33

44

5-
admin_bp = Blueprint('admin_bp', __name__, template_folder='templates', static_folder='static') # Blueprint Configuration
5+
admin_bp = Blueprint(
6+
'admin_bp',
7+
__name__,
8+
template_folder='templates',
9+
static_folder='static'
10+
) # Blueprint Configuration
611

712

813
@admin_bp.route('/dashboard', methods=['GET'])

flask_assets_tutorial/assets.py renamed to application/assets.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Compile static assets."""
2+
from flask import current_app as app
23
from flask_assets import Bundle
34

45

5-
def compile_assets(assets):
6+
def compile_static_assets(assets):
67
"""Configure and build asset bundles."""
78
main_style_bundle = Bundle('src/less/*.less',
89
'main_bp/homepage.less',
@@ -20,6 +21,8 @@ def compile_assets(assets):
2021
assets.register('main_styles', main_style_bundle)
2122
assets.register('main_js', main_js_bundle)
2223
assets.register('admin_styles', admin_style_bundle)
23-
main_style_bundle.build()
24-
main_js_bundle.build()
25-
admin_style_bundle.build()
24+
if app.config['FLASK_ENV'] == 'development': # Only rebuild bundles in development
25+
main_style_bundle.build()
26+
main_js_bundle.build()
27+
admin_style_bundle.build()
28+
return assets

config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Flask configuration variables."""
2-
from os import environ
2+
from os import environ, path
33
from dotenv import load_dotenv
44

5-
6-
load_dotenv()
5+
basedir = path.abspath(path.dirname(__file__))
6+
load_dotenv(path.join(basedir, '.env'))
77

88

99
class Config:

pyproject.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[tool.poetry]
2+
name = "Flask Assets Tutorial"
3+
version = "0.1.0"
4+
description = "Flask application which compiles ands serves frontend assets with Flask-Assets."
5+
authors = ["Todd Birchard <[email protected]>"]
6+
maintainers = ["Todd Birchard <[email protected]>"]
7+
license = "MIT"
8+
readme = "README.md"
9+
homepage = "https://hackersandslackers.com/flask-assets/"
10+
repository = "https://github.com/hackersandslackers/flask-assets-tutorial/"
11+
documentation = "https://hackersandslackers.com/flask-assets/"
12+
keywords = ["Flask",
13+
"Flask-Assets",
14+
"Bundles",
15+
"MVC",
16+
"Tutorial"]
17+
18+
[tool.poetry.dependencies]
19+
python = "^3.8"
20+
flask = "*"
21+
flask-assets = "*"
22+
python-dotenv = "*"
23+
24+
[tool.poetry.dev-dependencies]
25+
lesscpy = "*"
26+
cssmin = "*"
27+
jsmin = "*"
28+
pytest = "*"
29+
30+
[build-system]
31+
requires = ["poetry>=0.12"]
32+
build-backend = "poetry.masonry.api"
33+
34+
[tool.poetry.scripts]
35+
run = "wsgi:app"
36+
37+
[tool.poetry.urls]
38+
issues = "https://github.com/hackersandslackers/fflask-assets-tutorial/issues"

requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
click==7.1.1
1+
click==7.1.2
22
cssmin==0.2.0
3-
Flask==1.1.1
3+
Flask==1.1.2
44
Flask-Assets==2.0
55
itsdangerous==1.1.0
6-
Jinja2==2.11.1
6+
Jinja2==2.11.2
77
jsmin==2.2.2
88
lesscpy==0.14.0
99
MarkupSafe==1.1.1
1010
ply==3.11
11-
python-dotenv==0.12.0
11+
python-dotenv==0.13.0
1212
six==1.14.0
1313
webassets==2.0
14-
Werkzeug==1.0.0
14+
Werkzeug==1.0.1

setup.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Application entry point."""
2-
from flask_assets_tutorial import create_app
2+
from application import create_app
33

44
app = create_app()
55

0 commit comments

Comments
 (0)