git: 1d899c1c6f - main - PackagesMacro: Extend the syntax to category/name@flavor[pkgname]

Li-Wen Hsu <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.doc
Message-ID <[email protected]>
The branch main has been updated by lwhsu:

URL: https://cgit.FreeBSD.org/doc/commit/?id=1d899c1c6fc6b000411cc45fc2823caefc5af7e2

commit 1d899c1c6fc6b000411cc45fc2823caefc5af7e2
Author:     Li-Wen Hsu <[email protected]>
AuthorDate: 2023-03-19 16:09:25 +0000
Commit:     Li-Wen Hsu <[email protected]>
CommitDate: 2023-03-19 16:09:25 +0000

    PackagesMacro: Extend the syntax to category/name@flavor[pkgname]
    
    The package macro creates a link to the web interface of the port's
    origin directory in the ports repository.  Extend its usage to cover the
    case when we want to refer to a speicifed flavor of a port.
    
    For example, if we want to refer the aarch64-gcc12 pacakge, in the past
    we can only specify its origin port, like `pacakge:devel/freebsd-gcc12`,
    and unable to add the `@aarch64` flavor suffix because it creates a
    broken link.  This change makes it strip the suffix after `@` and accept
    a parameter of package name as link text.  If not provided, use the origin
    as the original behavior.
    
    Thus we can have this kind of notation:
    
        package:devel/freebsd-gcc12@aarch64[aarch64-gcc12]
    
    which creates linkt to:
    
        https://cgit.freebsd.org/ports/tree/devel/freebsd-gcc12/
    
    with link text:
    
        aarch64-gcc12
    
    Reviewed by:    carlavilla, dbaio
    Differential Revision: https://reviews.freebsd.org/D39067
---
 shared/lib/PackagesMacro/extension.rb | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/shared/lib/PackagesMacro/extension.rb b/shared/lib/PackagesMacro/extension.rb
index 20969ca3c0..5476995c49 100644
--- a/shared/lib/PackagesMacro/extension.rb
+++ b/shared/lib/PackagesMacro/extension.rb
@@ -6,14 +6,23 @@ class PackagesMacro < Asciidoctor::Extensions::InlineMacroProcessor
   use_dsl
 
   named :package
+  name_positional_attributes 'pkgname'
 
   def process parent, target, attrs
-    packagename = target
+    pkgorigin = target
 
-    target = %(https://cgit.freebsd.org/ports/tree/#{target}/pkg-descr)
-    parent.document.register :links, target
+    if pkgorigin.include?("@")
+      pkgorigin = pkgorigin[0..pkgorigin.index("@")-1]
+    end
 
-    %(<a class="package" href="#{target}">#{packagename}</a>)
+    pkgname = if (pkgname = attrs['pkgname'])
+      "#{pkgname}"
+    else
+      "#{target}"
+    end
+
+    url = %(https://cgit.freebsd.org/ports/tree/#{pkgorigin}/)
+
+    %(<a class="package" href="#{url}">#{pkgname}</a>)
   end
 end
-
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.