Conjunto de mudanças 6473 no repositório publico


Ignorar:
Timestamp:
10/06/2012 20:41:49 (9 anos atrás)
Autor:
mazza
Mensagem:

boxes: row_html

Localização:
PortalInterlegis/produtos/il.portalinterlegis/src/il/portalinterlegis
Arquivos:
3 editados

Legenda:

Não Modificado
Adicionado
Removido
  • PortalInterlegis/produtos/il.portalinterlegis/src/il/portalinterlegis/browser/boxes.py

    r6472 r6473  
    7474        dictionary[key] = value = PersistentDict()
    7575    return value
     76
     77# ROWS
     78
     79ROW_TEMPLATE = '''
     80  <div class="dt-row">%s
     81  </div>'''
     82
     83CELL_TEMPLATE = '''
     84    <div class="dt-cell dt-position-%s dt-width-%s">%s
     85    </div>'''
     86
     87def row_spec_to_cells(context, row_spec):
     88    """Iterates transforming each cell spec from
     89       (width, schema, number) to (position, width, html)"""
     90    position = 0
     91    for (width, schema, number) in row_spec:
     92        yield (position, width, BoxManager(schema).html(context, number))
     93        position += width
     94
     95def row_html(context, row_spec):
     96    return ROW_TEMPLATE % ''.join(
     97        [CELL_TEMPLATE % cell for cell in row_spec_to_cells(context, row_spec)])
     98
     99
  • PortalInterlegis/produtos/il.portalinterlegis/src/il/portalinterlegis/browser/interfaces.py

    r6472 r6473  
    3232# BOX INTERFACES
    3333
    34 @template(r'''
     34@template('''
    3535      <div class="simple-box">
    3636        <h2>%(title)s</h2>
     
    3939          %(text)s
    4040        </p>
    41       </div>
    42 ''')
     41      </div>''')
    4342class ISimpleBox(Interface):
    4443    title = schema.TextLine(title=u"Título", required=True)
  • PortalInterlegis/produtos/il.portalinterlegis/src/il/portalinterlegis/tests/testunitboxes.py

    r6472 r6473  
    33from mock import patch
    44
    5 from il.portalinterlegis.browser.boxes import BoxManager
     5from il.portalinterlegis.browser.boxes import BoxManager, row_html
    66from il.portalinterlegis.browser.interfaces import ISimpleBox
    77
     8_ = None # anything, doesn't really matter
    89
    910class TestUnitBoxes(unittest.TestCase):
     
    1617    def assertEqual(self, first, second, *args):
    1718        "ignores differences in leading and trailing whitespace in strings"
    18         super(TestUnitBoxes, self).assertEqual(
     19        super(TestUnitBoxes, self).assertMultiLineEqual(
    1920            isinstance(first, str) and first.strip() or first,
    2021            isinstance(second, str) and second.strip() or second, *args)
     
    3334        </p>
    3435      </div>
    35         ''', boxmanager.html(None, 1))
     36        ''', boxmanager.html(_, _))
     37
     38    def test_row(self):
     39        context = object()
     40        with patch.object(BoxManager, 'html') as mock:
     41            # TODO: this mock programming is too complicated... refactor
     42            values = ['\n      %s' % s for s in ['AAA', 'BBB', 'CCC', 'DDD']]
     43            values.reverse()
     44            def side_effect(c, n):
     45                self.assertIs(context, c)
     46                return values.pop()
     47            mock.side_effect = side_effect
     48
     49            self.assertEqual('''
     50  <div class="dt-row">
     51    <div class="dt-cell dt-position-0 dt-width-1">
     52      AAA
     53    </div>
     54    <div class="dt-cell dt-position-1 dt-width-2">
     55      BBB
     56    </div>
     57    <div class="dt-cell dt-position-3 dt-width-3">
     58      CCC
     59    </div>
     60    <div class="dt-cell dt-position-6 dt-width-1">
     61      DDD
     62    </div>
     63  </div>
     64''', row_html(context, [(1, _, _), (2, _, _), (3, _, _), (1, _, _)] ))
Note: Veja TracChangeset para ajuda no uso do visualizador de conjunto de mudanças.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.