From 9d06e0c442b3f87ced68fb6f4654d8ead838342f Mon Sep 17 00:00:00 2001 From: Severyn Kozak Date: Thu, 27 Mar 2014 19:49:51 -0400 Subject: [PATCH 1/2] Add skeleton dir-structure, content to files. Add: app.py -add boilerplate Flask source. bitshift/ -directory for all python source. templates/(layout, index).html -add global layout template, and placeholder home page. static/css/main.sass -add placeholder main SASS file. --- .gitignore | 3 +++ app.py | 14 ++++++++++++++ bitshift/__init__.py | 0 static/css/main.css | 2 ++ static/css/main.sass | 2 ++ templates/index.html | 9 +++++++++ templates/layout.html | 18 ++++++++++++++++++ 7 files changed, 48 insertions(+) create mode 100644 app.py create mode 100644 bitshift/__init__.py create mode 100644 static/css/main.css create mode 100644 static/css/main.sass create mode 100644 templates/index.html create mode 100644 templates/layout.html diff --git a/.gitignore b/.gitignore index ded6067..7663424 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +.sass-cache + +# github premade rules *.py[cod] # C extensions diff --git a/app.py b/app.py new file mode 100644 index 0000000..2e97560 --- /dev/null +++ b/app.py @@ -0,0 +1,14 @@ +from flask import Flask +from flask import render_template + +app = Flask(__name__) + +env = app.jinja_env +app.jinja_env.line_statement_prefix = "=" + +@app.route("/") +def index(): + return render_template("index.html") + +if __name__ == "__main__": + app.run() diff --git a/bitshift/__init__.py b/bitshift/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/static/css/main.css b/static/css/main.css new file mode 100644 index 0000000..11dbe5a --- /dev/null +++ b/static/css/main.css @@ -0,0 +1,2 @@ +p { + font-size: 1.5em; } diff --git a/static/css/main.sass b/static/css/main.sass new file mode 100644 index 0000000..e0b1994 --- /dev/null +++ b/static/css/main.sass @@ -0,0 +1,2 @@ +p + font-size: 1.5em diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..ba1165f --- /dev/null +++ b/templates/index.html @@ -0,0 +1,9 @@ += extends "layout.html" + += block title + Home += endblock + += block body +

Hello, world.

+= endblock diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..77be6ee --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,18 @@ + + + + + = block title + = endblock + + + = block head + + = endblock + + + = block body + = endblock + + From f24d2a6be20eaa23e36a40224d7e0659f67644e0 Mon Sep 17 00:00:00 2001 From: Severyn Kozak Date: Thu, 27 Mar 2014 21:32:55 -0400 Subject: [PATCH 2/2] Add assets/config module, SASS files, templates. Add: bitshift/assets.py -add module that contains functions to be called from inside the templates/ Jinja HTML files -- currently contains tag(), which generates an HTML asset tag based on a filename. bitshift/config.py -add Flask configuration module. static/(sass/main.sass, css/main.css) -create isolated directory for SASS files; compiled CSS files will be stored in static/css. static/css/_mixins.sass -add SASS partial to contain mixins (globally relevant to the project's styling). templates/layout.html -add various metadata. --- app.py | 14 +++++++++++--- bitshift/__init__.py | 1 + bitshift/assets.py | 22 ++++++++++++++++++++++ bitshift/config.py | 6 ++++++ static/css/main.css | 2 ++ static/css/main.sass | 2 -- static/sass/_mixins.sass | 11 +++++++++++ static/sass/main.sass | 7 +++++++ templates/layout.html | 13 +++++++++++-- 9 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 bitshift/assets.py create mode 100644 bitshift/config.py delete mode 100644 static/css/main.sass create mode 100644 static/sass/_mixins.sass create mode 100644 static/sass/main.sass diff --git a/app.py b/app.py index 2e97560..a7508c4 100644 --- a/app.py +++ b/app.py @@ -1,10 +1,18 @@ +""" +Module to contain all the project's Flask server plumbing. +""" + from flask import Flask -from flask import render_template +from flask import render_template, session + +from bitshift import * app = Flask(__name__) +app.config.from_object("bitshift.config") -env = app.jinja_env -app.jinja_env.line_statement_prefix = "=" +app_env = app.jinja_env +app_env.line_statement_prefix = "=" +app_env.globals.update(assets = assets) @app.route("/") def index(): diff --git a/bitshift/__init__.py b/bitshift/__init__.py index e69de29..d51957e 100644 --- a/bitshift/__init__.py +++ b/bitshift/__init__.py @@ -0,0 +1 @@ +__all__ = ["config", "assets"] diff --git a/bitshift/assets.py b/bitshift/assets.py new file mode 100644 index 0000000..4754036 --- /dev/null +++ b/bitshift/assets.py @@ -0,0 +1,22 @@ +""" +Module contains helper functions to be used inside the project's Jinja +templates. +""" + +from flask import Markup + +ASSET_HTML_TEMPLATES = { + 'css': "", + 'js': "" +} + +def tag(filename): + """ + Return HTML tag for asset named filename. + + Return either a