Edgewall Software

Opened 16 years ago

Last modified 7 years ago

#192 new enhancement

Allow a `.join` on a genshi.builder.tag

Reported by: palgarvio Owned by: cmlenz
Priority: major Milestone: 0.9
Component: General Version: devel
Keywords: Fragment join Cc: martin@…

Description

One should be able to do something like:

tag.p(tag.br.join([tag.span(l) for l in doc.split()]))

Attachments (3)

tag-join.patch (1.8 KB) - added by Carsten Klein <carsten.klein@…> 14 years ago.
Initial patch for this feature
fragment_join__genshi_0.6.patch (679 bytes) - added by Martin Scharrer <martin@…> 14 years ago.
Patch to add join method for Genshi fragments (patch is against Genshi 0.6 stable)
join_unit_tests.patch (2.0 KB) - added by Martin Scharrer <martin@…> 14 years ago.
Some unit tests for patch attachment:fragment_join__genshi_0.6.patch

Download all attachments as: .zip

Change History (11)

comment:1 Changed 16 years ago by cmlenz

  • Milestone changed from 0.5 to 0.6

Postponing… need to 0.5 out.

comment:2 Changed 14 years ago by cmlenz

  • Milestone changed from 0.6 to 0.7

Again.

Changed 14 years ago by Carsten Klein <carsten.klein@…>

Initial patch for this feature

Changed 14 years ago by Martin Scharrer <martin@…>

Patch to add join method for Genshi fragments (patch is against Genshi 0.6 stable)

comment:3 Changed 14 years ago by Martin Scharrer <martin@…>

  • Cc martin@… added
  • Keywords join added

Hi, I just ran into this by myself. Technically the join method belongs to the Fragment class, not to the tag method. I wrote my own patch before I found this ticket and added it as attachment:fragment_join__genshi_0.6.patch. It is against Genshi 0.6 stable and does not require any other changes to the Fragment class.

Would be great if something like this could be added in the next release of Genshi.

comment:4 Changed 14 years ago by cboos

  • Keywords Fragment added

This would be nice, yes. I know of a couple of places in Trac where I could use this.

If you could add some unit tests for this feature, the patch will have more changes to get integrated.

Changed 14 years ago by Martin Scharrer <martin@…>

comment:5 follow-up: Changed 14 years ago by Martin Scharrer <martin@…>

Hi cboos, here you go: attachment:join_unit_tests.patch

But I'm not sure at all if I wrote the tests the way you want them. I just had a little look on the other tests and wrote it as similar as possible. I'm not sure if

self.assertEqual( unicode( tag( xxx ).generate() ),  unicode( tag( yyy ).generate() ) )

is the optimal way to compare them, but I couldn't think about anything better. I don't know the Genshi internal good enough for that.

The tests include:

  • Join with Fragment (tag(xx).join( [...] ))
  • Join with Element (tag.eee(xx).join( [...] ))
  • Join a empty list (tag(xxx).join([]), tag.eee(xxx).join([]))
  • Join a list with only one element (tag(xxx).join([a]), tag.eee(xxx).join([a]))

comment:6 in reply to: ↑ 5 ; follow-up: Changed 14 years ago by cboos

Replying to Martin Scharrer <martin@…>:

Hi cboos, here you go: attachment:join_unit_tests.patch

But I'm not sure at all if I wrote the tests the way you want them.

Note that I won't integrate the patches myself, as this is not my project, I just gave you some tips as I'm interested in seeing this feature in Genshi 0.7.

I just had a little look on the other tests and wrote it as similar as possible.

The other tests in this file seem to check for the sequence of events themselves?

comment:7 in reply to: ↑ 6 Changed 14 years ago by Martin Scharrer <martin@…>

Replying to cboos:

Replying to Martin Scharrer <martin@…>:

Hi cboos, here you go: attachment:join_unit_tests.patch

But I'm not sure at all if I wrote the tests the way you want them.

Note that I won't integrate the patches myself, as this is not my project, I just gave you some tips as I'm interested in seeing this feature in Genshi 0.7.

No problem, I wasn't suggesting that you are supposed to integrate them.

I just had a little look on the other tests and wrote it as similar as possible.

The other tests in this file seem to check for the sequence of events themselves?

Sorry, my formulation was not very good. I meant the overall structure, the test case class etc., not the details of the test.

The other tests are about the element factory and test the lower-level events. But I took the join more like a higher level operation, so I just test if the manual join generates the same result as the join method. The last two tests are more to see if the [-1] index doesn't do any harm on a empty or single-element list and if the single element is returned correctly. As I said, this is my first try with Genshi unit tests.

comment:8 Changed 7 years ago by hodgestar

  • Milestone changed from 0.7 to 0.9

Moved to milestone 0.9.

Note: See TracTickets for help on using tickets.