Skip to content

Commit

Permalink
When creating a blueprint chain with a factory, allow blueprints defi…
Browse files Browse the repository at this point in the history
…ned after blueprints based in ``generic_input_renderer``.
  • Loading branch information
thet committed Feb 23, 2017
1 parent 7e63328 commit 637b4f1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ History
2.2.1 (unreleased)
------------------

- No chnages yet.
- When creating a blueprint chain with a factory, allow blueprints defined after blueprints based in ``generic_input_renderer``.
[thet]


2.2 (2016-10-06)
Expand Down
14 changes: 10 additions & 4 deletions src/yafowil/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,17 @@ def input_attributes_full(widget, data, value=None):


@managedprops(*css_managed_props)
def input_generic_renderer(widget, data, custom_attrs={}):
def input_generic_renderer(widget, data, pos='before', custom_attrs={}):
"""Generic HTML ``input`` tag render.
"""
input_attrs = input_attributes_full(widget, data)
input_attrs.update(custom_attrs)
return data.tag('input', **input_attrs)
rendered = data.tag('input', **input_attrs)
if pos == 'before':
rendered = rendered + (data.rendered or u'')
else:
rendered = (data.rendered or u'') + rendered
return rendered


# multivalued is not documented, because its only valid for specific blueprints
Expand All @@ -333,7 +338,7 @@ def display_proxy_renderer(widget, data):
input_attrs = input_attributes_full(widget, data, value=val)
rendered += data.tag('input', **input_attrs)
else:
rendered += input_generic_renderer(widget, data)
rendered = input_generic_renderer(widget, data, pos='after')
if orgin_type:
widget.attrs['type'] = orgin_type
else:
Expand Down Expand Up @@ -389,10 +394,11 @@ def generic_positional_rendering_helper(tagname, message, attrs, rendered, pos,
pos
position how to place the newtag relative to the prior rendered:
'before'='<newtag>message</newtag>rendered',
'after' ='<newtag>message</newtag>'
'after' ='rendered<newtag>message</newtag>'
'inner-before'= <newtag>message rendered</newtag>
'inner-after'= <newtag>rendered message</newtag>
"""
rendered = rendered or u''
if pos not in ['before', 'after', 'inner-before', 'inner-after']:
raise ValueError('Invalid value for position "{0}"'.format(pos))
if pos.startswith('inner'):
Expand Down
20 changes: 18 additions & 2 deletions src/yafowil/common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,7 @@ hidden field::
>>> wrapped_pxml(widget())
<div>
<div class="display-text" id="display-DISPLAY">lorem ipsum</div>
<input class="text" id="input-DISPLAY" name="DISPLAY" type="hidden"
value="lorem ipsum"/>
<input class="text" id="input-DISPLAY" name="DISPLAY" type="hidden" value="lorem ipsum"/>
</div>
<BLANKLINE>

Expand All @@ -470,6 +469,23 @@ Skip mode renders empty string.::
>>> widget()
u''

Multiple blueprints::

>>> widget = factory(
... 'label:text:help',
... name="textinput",
... props={
... 'label': 'label before input',
... 'help': 'help after input',
... }
... )
>>> wrapped_pxml(widget())
<div>
<label for="input-textinput">label before input</label>
<input class="text" id="input-textinput" name="textinput" type="text" value=""/>
<div class="help">help after input</div>
</div>
<BLANKLINE>

Datatype extraction
-------------------
Expand Down

0 comments on commit 637b4f1

Please sign in to comment.