| Line | |
|---|
| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2018 Ryan J Ollos <ryan.j.ollos@gmail.com> |
|---|
| 4 | # |
|---|
| 5 | # This software is licensed as described in the file COPYING, which |
|---|
| 6 | # you should have received as part of this distribution. |
|---|
| 7 | # |
|---|
| 8 | |
|---|
| 9 | from __future__ import absolute_import |
|---|
| 10 | |
|---|
| 11 | from trac.core import Component, implements |
|---|
| 12 | from wikiautocomplete.api import IWikiAutoCompleteStrategyProvider |
|---|
| 13 | |
|---|
| 14 | from tractags.api import TagSystem |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | class TagsWikiAutoComplete(Component): |
|---|
| 18 | |
|---|
| 19 | implements(IWikiAutoCompleteStrategyProvider) |
|---|
| 20 | |
|---|
| 21 | # IWikiAutoCompleteStrategyProvider |
|---|
| 22 | |
|---|
| 23 | def get_wiki_auto_complete_strategies(self): |
|---|
| 24 | return [( |
|---|
| 25 | { |
|---|
| 26 | 'name': 'tag', |
|---|
| 27 | 'match': ( |
|---|
| 28 | r'\b(tag:|tagged:)' # tag: or tagged: query |
|---|
| 29 | r'("(?:\S+ )*)?' # Optional: Quotes allow multiple OR-tags |
|---|
| 30 | r'(\S*)$' # tag-prefix to complete |
|---|
| 31 | ), |
|---|
| 32 | 'index': 3, |
|---|
| 33 | 'replace_prefix': '$1$2', |
|---|
| 34 | 'cache': True, |
|---|
| 35 | }, |
|---|
| 36 | self._suggest_tags, |
|---|
| 37 | )] |
|---|
| 38 | |
|---|
| 39 | def _suggest_tags(self, req): |
|---|
| 40 | all_tags = TagSystem(self.env).get_all_tags(req) |
|---|
| 41 | return [{'value': tag} for tag in sorted(all_tags)] |
|---|
Note: See
TracBrowser
for help on using the repository browser.