Skip to content

Commit 150f6f8

Browse files
committed
bootstra 3 +4 in parallel
1 parent cd94a76 commit 150f6f8

19 files changed

+195
-65
lines changed

HISTORY.rst renamed to CHANGES.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22
History
33
=======
44

5-
1.3.2 (unreleased)
5+
2.0.0 (unreleased)
66
------------------
77

8-
- No changes yet.
8+
- Factory configuration and macro registration is no longer done automatically due to the dual-theme feature.
9+
It must be configured in your code using `yafowil.bootstrap`.
10+
In order to do so do `from yafowil.bootstrap import configure_factory`.
11+
Next call it with the name of the desired theme `configure_factory('bootstrap3')`.
12+
[jensens]
13+
14+
- Add support for Bootstrap 4 using theme `bootstrap4`.
15+
The Bootstrap 3 theme is still available as `bootstrap3`.
16+
Latter is provided a fallback as `bootstrap` too (will be removed in future versions).
17+
[jensens, agitator]
918

1019
1.3.1 (2017-11-13)
1120
------------------

README.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
This is the **bootstrap styles integration** for for `YAFOWIL
1+
This is the **bootstrap styles integration** for for `YAFOWIL
22
<http://pypi.python.org/pypi/yafowil>`_ - Yet Another Form Widget Library.
33

4+
This package provides themes for `Bootstrap 3 <https://getbootstrap.com/docs/3.3/>`_ and `Bootstrap 4 <https://getbootstrap.com/>`_
5+
6+
In order to select one of the themes, `configure_factory` must be called with the desired theme name:
7+
8+
::
9+
10+
from yafowil.bootstrap import configure_factory
11+
12+
configure_factory('bootstrap4')
13+
414

515
Detailed Documentation
616
======================

setup.cfg

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[check-manifest]
2+
ignore =
3+
*.cfg
4+
.coveragerc
5+
.editorconfig
6+
.gitattributes
7+
8+
[isort]
9+
force_alphabetical_sort = True
10+
force_grid_wrap=0
11+
force_single_line = True
12+
include_trailing_comma=True
13+
line_length = 200
14+
lines_after_imports = 2
15+
multi_line_output=3
16+
not_skip = __init__.py
17+
use_parentheses=True
18+
19+
[flake8]
20+
exclude = bootstrap.py,docs,*.egg.,omelette
21+
max-complexity = 15
22+
23+
[zest.releaser]
24+
create-wheel = yes

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
version = '2.0.0.dev0'
77
shortdesc = 'Bootstrap Styles for YAFOWIL'
88
longdesc = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
9-
longdesc += open(os.path.join(os.path.dirname(__file__), 'HISTORY.rst')).read()
9+
longdesc += open(os.path.join(os.path.dirname(__file__), 'CHANGES.rst')).read()
1010
longdesc += open(os.path.join(os.path.dirname(__file__), 'LICENSE.rst')).read()
1111
tests_require = ['yafowil[test]']
1212

@@ -45,5 +45,4 @@
4545
entry_points="""
4646
[yafowil.plugin]
4747
register = yafowil.bootstrap:register
48-
configure = yafowil.bootstrap:configure
4948
""")

src/yafowil/bootstrap/__init__.py

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,62 @@
11
from yafowil.base import factory
2-
from yafowil.bootstrap.common import configure_factory
3-
from yafowil.bootstrap.common import register_macros
42
from yafowil.utils import entry_point
3+
4+
import bs3
5+
import bs4
56
import os
67

78

8-
resourcedir = os.path.join(os.path.dirname(__file__), "resources")
9-
js = [{"group": "bootstrap.dependencies", "resource": "js/bootstrap.js", "order": 20,}]
10-
css = [
9+
resourcedir_bs3 = os.path.join(os.path.dirname(__file__), "resources/bs3")
10+
resourcedir_bs4 = os.path.join(os.path.dirname(__file__), "resources/bs4")
11+
12+
js_bs3 = [
13+
{"group": "bootstrap.dependencies", "resource": "js/bootstrap.js", "order": 20,}
14+
]
15+
css_bs3 = [
16+
{"group": "bootstrap.dependencies", "resource": "css/bootstrap.css", "order": 10,},
1117
{
1218
"group": "bootstrap.dependencies",
13-
"resource": "css/bootstrap.css",
14-
"order": 10,
15-
# }, {
16-
# 'group': 'bootstrap.dependencies',
17-
# 'resource': 'css/bootstrap-theme.css',
18-
# 'order': 11,
19-
}
19+
"resource": "css/bootstrap-theme.css",
20+
"order": 11,
21+
},
22+
]
23+
24+
js_bs4 = [
25+
{"group": "bootstrap.dependencies", "resource": "js/bootstrap.js", "order": 20,}
26+
]
27+
css_bs4 = [
28+
{"group": "bootstrap.dependencies", "resource": "css/bootstrap.css", "order": 10,}
2029
]
2130

2231

2332
@entry_point(order=20)
2433
def register():
34+
# Bootstrap 3
2535
factory.register_theme(
26-
"bootstrap", "yafowil.bootstrap", resourcedir, js=js, css=css
36+
"bootstrap3", "yafowil.bootstrap", resourcedir_bs3, js=js_bs3, css=css_bs3
37+
)
38+
# BBB Bootstrap 3 - remove in next major release
39+
factory.register_theme(
40+
"bootstrap", "yafowil.bootstrap", resourcedir_bs3, js=js_bs3, css=css_bs3
41+
)
42+
# Bootstrap 4
43+
factory.register_theme(
44+
"bootstrap4", "yafowil.bootstrap", resourcedir_bs4, js=js_bs4, css=css_bs4
2745
)
2846

2947

30-
@entry_point(order=20)
31-
def configure():
32-
# only configure factory if not suppressed explicit
33-
if not os.environ.get("TESTRUN_MARKER"):
34-
configure_factory()
35-
register_macros()
48+
def configure_factory(theme):
49+
"""Configure the Yafowil factory with theme specific macros and defaults.
50+
"""
51+
if theme == "bootstrap3":
52+
baseline = bs3
53+
elif theme == "bootstrap4":
54+
baseline = bs4
55+
else:
56+
raise ValueError("'theme' parameter must be one of: bootstrap3, bootstrap4")
57+
if os.environ.get("TESTRUN_MARKER"):
58+
# skip for testing
59+
# only configure factory if not suppressed explicit
60+
return
61+
baseline.configure_factory()
62+
baseline.register_macros()

src/yafowil/bootstrap/bs3.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
from yafowil.base import factory
2+
3+
4+
def bs_field_class(widget, data):
5+
if data.errors:
6+
return "form-group has-error"
7+
return "form-group"
8+
9+
10+
def configure_factory():
11+
# set theme
12+
factory.theme = "bootstrap"
13+
14+
# common defaults
15+
factory.defaults["text.class"] = "text form-control"
16+
17+
factory.defaults["textarea.class"] = "textarea form-control"
18+
19+
factory.defaults["lines.class"] = "lines form-control"
20+
21+
factory.defaults["password.class"] = "password form-control"
22+
23+
factory.defaults["select.class"] = "select"
24+
factory.defaults["select.block_class"] = "form-control"
25+
factory.defaults["select.radio_wrapper_class"] = "radio"
26+
factory.defaults["select.checkbox_wrapper_class"] = "checkbox"
27+
28+
factory.defaults["submit.class"] = "btn btn-default"
29+
30+
factory.defaults["email.class"] = "email form-control"
31+
32+
factory.defaults["url.class"] = "url form-control"
33+
34+
factory.defaults["search.class"] = "search form-control"
35+
36+
factory.defaults["number.class"] = "number form-control"
37+
38+
factory.defaults["label.class"] = "control-label"
39+
40+
factory.defaults["field.class"] = bs_field_class
41+
42+
factory.defaults["error.position"] = "after"
43+
factory.defaults["error.tag"] = "span"
44+
factory.defaults["error.class"] = "help-block"
45+
factory.defaults["error.message_class"] = "text-danger"
46+
47+
factory.defaults["help.position"] = "after"
48+
factory.defaults["help.tag"] = "p"
49+
factory.defaults["help.class"] = "help-block"
50+
51+
# yafowil.widget.array
52+
factory.defaults["array.table_class"] = "table table-condensed"
53+
54+
# yafowil.widget.autocomplete
55+
factory.defaults["autocomplete.class"] = "autocomplete form-control"
56+
57+
# yafowil.widget.chosen
58+
factory.defaults["chosen.class"] = "chosen form-control"
59+
60+
# yafowil.widget.datetime
61+
factory.defaults["datetime.datepicker_class"] = "datepicker form-control"
62+
factory.defaults["datetime.timepicker_class"] = "timepicker form-control"
63+
factory.defaults["time.timepicker_class"] = "timepicker form-control"
64+
65+
# yafowil.widget.dict
66+
factory.defaults["dict.table_class"] = "dictwidget table table-condensed"
67+
factory.defaults["dict.key_class"] = "form-control"
68+
factory.defaults["dict.value_class"] = "form-control"
69+
70+
# yafowil.widget.wysihtml5
71+
factory.defaults["wysihtml5.class"] = "wysihtml5 form-control"
72+
73+
74+
def register_macros():
75+
# common
76+
factory.register_macro("form", "form", {"form.class": "form-horizontal",})
77+
factory.register_macro(
78+
"field",
79+
"field:label:div:help:error",
80+
{"label.class_add": "col-sm-2", "div.class_add": "col-sm-10",},
81+
)
82+
factory.register_macro(
83+
"button", "submit", {"submit.class": "btn", "submit.class_add": "btn-default",}
84+
)
85+
86+
# yafowil.widget.array
87+
factory.register_macro(
88+
"array",
89+
"field:label:help:error:array",
90+
{
91+
"array.label": " ",
92+
"field.class": bs_field_class,
93+
"label.class_add": "col-sm-2",
94+
"array.class_add": "col-sm-10",
95+
"help.class_add": "col-sm-offset-2 col-sm-10",
96+
"error.class_add": "col-sm-offset-2 col-sm-10",
97+
},
98+
)
99+
factory.register_macro("arrayfield", "field:label:help:error", {})

src/yafowil/bootstrap/common.py renamed to src/yafowil/bootstrap/bs4.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def bs_field_class(widget, data):
99

1010
def configure_factory():
1111
# set theme
12-
factory.theme = "bootstrap"
12+
factory.theme = "bootstrap4"
1313

1414
# common defaults
1515
factory.defaults["text.class"] = "text form-control"
@@ -76,17 +76,10 @@ def register_macros():
7676
# common
7777
factory.register_macro("form", "form", {})
7878

79-
factory.register_macro(
80-
"field", "field:label:help:error", {}
81-
)
79+
factory.register_macro("field", "field:label:help:error", {})
8280

8381
factory.register_macro(
84-
"button",
85-
"button",
86-
{
87-
"button.class": "btn",
88-
"button.class_add": "btn-primary",
89-
},
82+
"button", "button", {"button.class": "btn", "button.class_add": "btn-primary",},
9083
)
9184

9285
# yafowil.widget.array

src/yafowil/bootstrap/common.rst

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)