""" Populates a text-only template variable $abstract from an entries body which is made available in story templates. To install: 1) Put abstract.py in your plugin directory. 2) In config.py add abstract to py['load_plugins'] 3) Add the following optional variable to config.py: py['abstract_words'] = 20 # this is the default Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Copyright 2004 Steven Armstrong $Id: abstract.py,v 1.2 2005/03/01 00:50:04 sar Exp $ """ __author__ = "Steven Armstrong " __version__ = "$Revision: 1.2 $ $Date: 2005/03/01 00:50:04 $" __url__ = "http://www.c-area.ch/code/" __description__ = "Abstract plugin" from xml.sax.saxutils import unescape from Pyblosxom.tools import Stripper _words_default = 20 def verify_installation(request): config = request.getConfiguration() if not config.has_key("abstract_words"): print "missing optional config property 'abstract_words'" print "using the default of %d" % _words_default return 1 class Abstract(object): def __init__(self, entry, config): self._entry = entry self._words = int(config.get("abstract_words", _words_default)) self._abstract = None self._generateAbstract() def __str__(self): if not self._abstract: self._generateAbstract() return self._abstract def _generateAbstract(self): html = unescape(self._entry['body']) parser = Stripper() parser.feed(html) str = parser.gettext() frag = str.split() if len(frag) > self._words: frag = frag[:self._words] frag.append('...') self._abstract = ' '.join(frag) def cb_story(args): request = args["request"] entry = args['entry'] config = request.getConfiguration() entry["abstract"] = Abstract(entry, config)