Skip to content

Commit

Permalink
[dev] Started cleaner way to include JS libs.
Browse files Browse the repository at this point in the history
  • Loading branch information
oksome committed Jan 23, 2014
1 parent a9e6b64 commit 099f2c0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var
sdist
develop-eggs
.installed.cfg
lib
#lib
lib64

# Installer logs
Expand Down
40 changes: 40 additions & 0 deletions lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-

# This file is part of Tumulus.
#
# Copyright (C) 2013 OKso (http://okso.me)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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 Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from tumulus.plugins import inject_css, inject_js_footer, inject_js_head


known_js_libs = {
'd3': 'http://d3js.org/d3.v3.min.js',
'jquery': 'https//code.jquery.com/jquery-1.10.2.min.js',
}


def is_URL(name_or_URL):
return '//' in name_or_URL


def js(name_or_URL):
if is_URL(name_or_URL):
return inject_js_footer(name_or_URL)
elif name_or_URL.lower() in known_js_libs:
URL = known_js_libs[name_or_URL.lower()]
return inject_js_footer(URL)
else:
raise Exception
9 changes: 6 additions & 3 deletions samples/bottle_webapp/templates/index.tpl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from tumulus.tags import HTMLTags as t
from tumulus.plugins import inject_css, inject_js_footer, inject_js_head
import tumulus.lib as lib

page = t.html(
t.head(
Expand All @@ -8,8 +9,10 @@
t.body(
t.h1("A page"),
t.p("Yup, this is a page on the World Wild Web."),
inject_css('http://okso.me/static/style.css'),
inject_js_footer('//code.jquery.com/jquery-1.10.2.min.js'),
inject_js_head('http://d3js.org/d3.v3.min.js'),
# inject_css('http://okso.me/static/style.css'),

lib.js('d3'),
lib.js('jquery'),
lib.js('http://d3js.org/d3.v3.min.js'),
),
)

0 comments on commit 099f2c0

Please sign in to comment.