| | 714 | |
| | 715 | |
| | 716 | class ResourceMacro(WikiMacroBase): |
| | 717 | """Display a link to the specified resource |
| | 718 | |
| | 719 | A resource is specified using `realm`, `id` and optionally `version`. |
| | 720 | The `format` of the resulting link can also be specified: default, |
| | 721 | compact or summary (or a combination of formats separated by the | |
| | 722 | character. |
| | 723 | """ |
| | 724 | |
| | 725 | def expand_macro(self, formatter, name, args): |
| | 726 | args, kw = parse_args(args) |
| | 727 | |
| | 728 | args = dict( |
| | 729 | zip(('realm', 'id', 'version', 'format'), args)) |
| | 730 | args.update(kw) |
| | 731 | |
| | 732 | realm = args.get('realm', '').strip() or formatter.resource.realm |
| | 733 | res_id = args.get('id', '').strip() |
| | 734 | |
| | 735 | if not res_id: |
| | 736 | raise TracError('Resource Macro requires a resource ID') |
| | 737 | |
| | 738 | formats = [f.strip() for f in args.get('format', 'default').split('|')] |
| | 739 | |
| | 740 | version = args.get('version', False) |
| | 741 | if version: |
| | 742 | version.strip() |
| | 743 | |
| | 744 | res = Resource(realm, res_id, version) |
| | 745 | |
| | 746 | links = [] |
| | 747 | for format in formats: |
| | 748 | # insert a space before every part except the first |
| | 749 | if links: |
| | 750 | links.append(" ") |
| | 751 | links.append( |
| | 752 | render_resource_link(self.env, formatter, res, format)) |
| | 753 | |
| | 754 | return tag.span(links) |