Part 2 - List of Pyroes *********************** Editing the name of a *Pyro* and having it automatically (or is it auto-magically?) in other elements is already a great thing. But a single *Pyro* would probably neither save the planet nor him/herself. That's why the other *Pyroes* come to the rescue and we need to be able to display a list with all the names to be able to choose which one will be edited. Copy the ``top1`` folder to ``top2`` and enter it. For example, with:: cp -r top1 top2 cd top2 .. note:: Under *Windows* and unless you have a proper shell installed (*Cygwin*, *MSYS*, *GitBash*, ...) you are probably better off using the *Windows Explorer* to make a copy of the directory) The List of Pyroes ================== To simplify our approach, we start by adding a ``mock_pyroes.html`` file to our project layout, where we will be holding our list, which will be acting as a database. The file structure and the new database-like Python code look like this. .. tabs:: .. code-tab:: bash File Layout ├── app │   ├── pyroes │   │   ├── __init__.py │   │   ├── pyroes_component.css │   │   ├── pyroes_component.html │   │   └── pyroes_component.py │   ├── __init__.py │   ├── app_component.css │   ├── app_component.html │   ├── app_component.py │   ├── app_module.py │   ├── mock_pyroes.py │   └── pyro.py ├── anpylar.js ├── index.html ├── package.json └── styles.css .. code-tab:: python mock_pyroes.py from .pyro import Pyro Pyroes = [Pyro(**x) for x in [ {'pyd': 11, 'name': 'Pyro Nakamura'}, {'pyd': 12, 'name': 'Mopynder Shuresh'}, {'pyd': 13, 'name': 'Pyter Pytrelli'}, {'pyd': 14, 'name': 'Angela Pytrelli'}, {'pyd': 15, 'name': 'Claire Pynnet'}, {'pyd': 16, 'name': 'Noah Pynnet'}, {'pyd': 17, 'name': 'Pysaac Mendez'}, {'pyd': 18, 'name': 'Pyki Sanders'}, {'pyd': 19, 'name': 'The Pytian'}, {'pyd': 20, 'name': 'Pylar'}] ] And here the new appearance of the ``PyroesComponent`` parts .. tabs:: .. code-tab:: html pyroes_component.html

My Pyroes

{name} Details

pyd: {}
.. code-tab:: python pyroes_component.py from anpylar import Component, html from app.pyro import Pyro from app.mock_pyroes import Pyroes class PyroesComponent(Component): bindings = { 'selected': Pyro(), } def render(self, node): with node.select('ul'): # find the node where to display the list for pyro in Pyroes: with html.li() as li: # create a list item per Pyro # if the selected pyro is this pyro ... set a class attr li._class.selected(self.selected_.pyd_ == pyro.pyd) # bind a click to do self.selected_(pyro) li._bindx.click(self.selected_, pyro) # show the pyd in a as a badge (child of list item) html.span(pyro.pyd, Class='badge') # show the name as text inside the list item html.txt(' {name}')._fmt(name=pyro.name_) .. code-tab:: css pyroes_component.css /* PyroesComponent's private CSS styles */ .selected { background-color: #CFD8DC !important; color: white; } .pyroes { margin: 0 0 2em 0; list-style-type: none; padding: 0; width: 15em; } .pyroes li { cursor: pointer; position: relative; left: 0; background-color: #EEE; margin: .5em; padding: .3em 0; height: 1.6em; border-radius: 4px; } .pyroes li.selected:hover { background-color: #BBD8DC !important; color: white; } .pyroes li:hover { color: #607D8B; background-color: #DDD; left: .1em; } .pyroes .text { position: relative; top: -3px; } .pyroes .badge { display: inline-block; font-size: small; color: white; padding: 0.8em 0.7em 0 0.7em; background-color: #607D8B; line-height: 1em; position: relative; left: -1px; top: -4px; height: 1.8em; margin-right: .8em; border-radius: 4px 0 0 4px; There have been several changes. Let's detail some of them: - A stylesheet which is only applicable to the ``PyroesComponent`` - The HTML code has been extended to: - Add the placeholder for the list (a ``