Exemple #1
0
 def testCropText(self):
     view = Plone(self.portal, self.app.REQUEST)
     self.assertEqual(view.cropText('Hello world', 7), 'Hello ...')
     self.assertEqual(view.cropText('Hello world', 99), 'Hello world')
     self.assertEqual(view.cropText('Hello world', 10), 'Hello worl...')
     self.assertEqual(view.cropText(u'Hello world', 10), u'Hello worl...')
     self.assertEqual(view.cropText(u'Koko\u0159\xedn', 5), u'Koko\u0159...')
     # Test utf encoded string Kokorin with 'r' and 'i' accented
     # Must return 6 characters, because 5th character is two byte
     text = u'Koko\u0159\xedn'.encode('utf8')
     self.assertEqual(view.cropText(text, 5), 'Koko\xc5\x99...')
 def testCropText(self):
     view = Plone(self.portal, self.app.REQUEST)
     self.assertEqual(view.cropText('Hello world', 7), 'Hello ...')
     self.assertEqual(view.cropText('Hello world', 99), 'Hello world')
     self.assertEqual(view.cropText('Hello world', 10), 'Hello worl...')
     self.assertEqual(view.cropText(u'Hello world', 10), u'Hello worl...')
     self.assertEqual(view.cropText(u'Koko\u0159\xedn', 5), u'Koko\u0159...')
     # Test utf encoded string Kokorin with 'r' and 'i' accented
     # Must return 6 characters, because 5th character is two byte
     text = u'Koko\u0159\xedn'.encode('utf8')
     self.assertEqual(view.cropText(text, 5), 'Koko\xc5\x99...')
 def CroppedDescription(self):
     registry = getUtility(IRegistry)
     length = registry.get("plone.search_results_description_length")
     plone_view = PloneView(None, None)
     if not length or not isinstance(length, int):
         # fallback if registry key is None
         length = 160
     return plone_view.cropText(self.flare.Description, length)
 def CroppedDescription(self):
     registry = getUtility(IRegistry)
     length = registry.get('plone.search_results_description_length')
     plone_view = PloneView(None, None)
     if not length or not isinstance(length, int):
         # fallback if registry key is None
         length = 160
     return plone_view.cropText(self.flare.Description, length)
Exemple #5
0
def _strip_text(item, length=500, ellipsis='...'):
    transformer = ITransformer(item)
    transformedValue = transformer(item.text, 'text/plain')
    return Plone.cropText(transformedValue, length=length, ellipsis=ellipsis)