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'])
File renamed without changes.
File renamed without changes.

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
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)