diff --git a/app/config/directory.py b/app/config/directory.py index 3228804..1d82c5b 100644 --- a/app/config/directory.py +++ b/app/config/directory.py @@ -1,24 +1,18 @@ -from bottle import Bottle, get, static_file +from core import template page = { 'public' :'pages/public', 'email' :'pages/email' } -app = Bottle() - -# Default staticdir - -@app.get("/css/") -def static(filepath): - return static_file(filepath, root="./static/css") - -@app.get("/js/") -def static(filepath): - return static_file(filepath, root="./static/js") - -# Template staticdir: plain - -@app.get("/templates/plain/css/") -def static(filepath): - return static_file(filepath, root="./templates/plain/static/css") +static = [ + { + "route" :"/css/", + "root" :"./static/css" + }, + { + "route" :"/js/", + "root" :"./static/js" + } +] +template.add(static, "templates") diff --git a/app/core/staticdir.py b/app/core/staticdir.py new file mode 100644 index 0000000..02df303 --- /dev/null +++ b/app/core/staticdir.py @@ -0,0 +1,7 @@ +from bottle import Bottle, static_file +from config import directory + +app = Bottle() + +for item in directory.static: + app.route(item['route'], "GET", lambda filepath, root=item['root']: static_file(filepath, root=root) ) diff --git a/app/core/template.py b/app/core/template.py new file mode 100644 index 0000000..9a0663a --- /dev/null +++ b/app/core/template.py @@ -0,0 +1,8 @@ +import os + +def add(dirconfig, template_directory): + template_list = [d for d in os.listdir(template_directory) if os.path.isdir(os.path.join(template_directory, d))] + for template_name in template_list: + template_module = __import__(f"{template_directory}.{template_name}.main", fromlist=["static"]) + for static in getattr(template_module, "static", []): + dirconfig.append(static) diff --git a/app/costa.py b/app/costa.py index cc6b19a..77dbdf3 100644 --- a/app/costa.py +++ b/app/costa.py @@ -5,19 +5,18 @@ # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/. -import sys from bottle import Bottle, run from beaker.middleware import SessionMiddleware import handler +from core import staticdir from config import server -from config import directory app = Bottle() app.merge(handler.app) -app.merge(directory.app) +app.merge(staticdir.app) app = SessionMiddleware(app, server.session_opts)