Commits

Luke Plant committed 8aae9d6

Fixed bug in extract_presentation

Comments (0)

Files changed (2)

semanticeditor/tests.py

         pres2, html2 = extract_presentation(combined)
         self.assertEqual(presentation, pres2)
         self.assertEqual(html, html2)
+
+    def test_extract_2(self):
+        html = """
+<div class="row3col"><div class="col"><div><h1>Hello Jane</h1><p>Some fancy content, entered using WYMeditor</p><p>Another paragraph</p><p>Hello</p></div></div><div class="col"><div><h1>Another &lt;heading&gt;</h1><div><h2>this is a test</h2></div><div><h2>hello1</h2><div><h3>hello2</h3></div><div><h3>hello3</h3></div><div><h3>hello4</h3></div></div></div></div><div class="col"><div><h1>hello5</h1><div><h2>hello6</h2><p>asdasd</p><p>asdxx</p></div></div></div></div>
+"""
+        pres = {'Hello Jane':set([NEWROW]),
+                'Another <heading>':set([NEWCOL]),
+                'this is a test':set(),
+                'hello1':set(),
+                'hello2':set(),
+                'hello3':set(),
+                'hello4':set(),
+                'hello5':set([NEWCOL]),
+                'hello6':set()
+                }
+
+        pres2, html2 = extract_presentation(html)
+        self.assertEqual(pres, pres2)
+

semanticeditor/utils/presentation.py

 
 MAXCOLS = 4
 COLUMNCLASS = 'col'
+ROWCLASSPREFIX = 'row'
+ROWCLASS = ROWCLASSPREFIX + '%dcol'
 
 ### Parsing ###
 
 
 ## General utilities
 
+def any(seq):
+    for i in seq:
+        if i:
+            return True
+    return False
+
 def _invert_dict(d):
     return dict((v,k) for (k,v) in d.items())
 
 def _apply_row_col_divs(parent, start_idx, stop_idx, columns):
     # Add the row
     newrow = wrap_elements_in_tag(parent, start_idx, stop_idx, 'div')
-    newrow.set('class', 'row%dcol' % len(columns))
+    newrow.set('class', ROWCLASS % len(columns))
 
     # Add the columns
     if len(columns) > MAXCOLS:
                 pres[name].add(NEWCOL)
             gp = get_parent(root, p)
             if gp is not None and gp.tag == 'div':
-                # Could add a redundant check for a 'rowXcol'
-                # class. If it's not there, we probably want to assume
-                # it, otherwise we have to cancel the columns we have
-                # found.
-                if get_index(gp, p) == 0:
-                    # This is the first child, therefore the beginning
-                    # of the row.
+                if any(c.startswith(ROWCLASSPREFIX) for c in _get_classes_for_node(gp)) \
+                        and get_index(gp, p) == 0:
                     pres[name].add(NEWROW)
                     pres[name].discard(NEWCOL) # not technically necessary
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.