| | 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 hte resulting link can also be specified: default, |
| | 721 | compact or complete. |
| | 722 | """ |
| | 723 | |
| | 724 | def expand_macro(self, formatter, name, args): |
| | 725 | args, kw = parse_args(args) |
| | 726 | |
| | 727 | args = dict( |
| | 728 | zip(('realm', 'id', 'version', 'format'), args)) |
| | 729 | args.update(kw) |
| | 730 | |
| | 731 | realm = args.get('realm', '').strip() or formatter.resource.realm |
| | 732 | res_id = args.get('id', '').strip() |
| | 733 | |
| | 734 | if not res_id: |
| | 735 | raise TracError('Resource Macro requires a resource ID') |
| | 736 | |
| | 737 | format = args.get('format', 'default').strip() |
| | 738 | version = args.get('version', False) |
| | 739 | if version: |
| | 740 | version.strip() |
| | 741 | |
| | 742 | res = Resource(realm, res_id, version) |
| | 743 | |
| | 744 | return render_resource_link(self.env, formatter, res, format) |