git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 11/12] doc: asciidoctor: split the format from the code

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jun 8, 2021, 09:00 UTC
Message-ID
<20210608090026.1737348-12-felipe.contreras@gmail.com>
In-Reply-To
<20210608090026.1737348-1-felipe.contreras@gmail.com>

This way we don't have to specify the block to execute on every conditional.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 Documentation/asciidoctor-extensions.rb | 26 ++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/Documentation/asciidoctor-extensions.rb b/Documentation/asciidoctor-extensions.rb
index 3282d59a48..51981af13c 100644
--- a/Documentation/asciidoctor-extensions.rb
+++ b/Documentation/asciidoctor-extensions.rb
@@ -6,22 +6,22 @@ Asciidoctor::Extensions.register do
 
   inline_macro :linkgit do
     if doc.doctype == 'book'
-      process do |parent, target, attrs|
-        '<ulink url="%1$s.html">%1$s(%2$s)</ulink>' % [target, attrs[1]]
-      end
+      format = '<ulink url="%1$s.html">%1$s(%2$s)</ulink>'
     elsif doc.basebackend? 'html'
       prefix = doc.attr('git-relative-html-prefix')
-      process do |parent, target, attrs|
-        %(<a href="#{prefix}%1$s.html">%1$s(%2$s)</a>) % [target, attrs[1]]
-      end
+      format = %(<a href="#{prefix}%1$s.html">%1$s(%2$s)</a>)
     elsif doc.basebackend? 'docbook'
-      process do |parent, target, attrs|
-        <<~EOF.chomp % [target, attrs[1]]
-        <citerefentry>
-        <refentrytitle>%s</refentrytitle><manvolnum>%s</manvolnum>
-        </citerefentry>
-        EOF
-      end
+      format = <<~EOF.chomp
+      <citerefentry>
+      <refentrytitle>%s</refentrytitle><manvolnum>%s</manvolnum>
+      </citerefentry>
+      EOF
+    else
+      return
+    end
+
+    process do |_, target, attrs|
+      format % [target, attrs[1]]
     end
   end
 
-- 
2.32.0.2.g41be0a4e50
Previous: Felipe ContrerasNext: Felipe Contreras
Message 12 of 13 in “doc: cleanup old cruft and asciidoctor revamp”
  1. 00/12 doc: cleanup old cruft and asciidoctor revampFelipe Contreras, Jun 8, 2021
  2. 02/12 doc: use --stringparam in xmltoFelipe Contreras, Jun 8, 2021
  3. 01/12 doc: remove GNU troff workaroundFelipe Contreras, Jun 8, 2021
  4. 04/12 doc: asciidoc: remove unnecessary attributeFelipe Contreras, Jun 8, 2021
  5. 05/12 doc: asciidoctor: remove unnecessary requireFelipe Contreras, Jun 8, 2021
  6. 07/12 doc: asciidoctor: reorganize extensionsFelipe Contreras, Jun 8, 2021
  7. 03/12 doc: simplify version passingFelipe Contreras, Jun 8, 2021
  8. 06/12 doc: asciidoctor: remove cruftFelipe Contreras, Jun 8, 2021
  9. 09/12 doc: asciidoctor: refactor macro registrationFelipe Contreras, Jun 8, 2021
  10. 12/12 doc: asciidoctor: specify name of our groupFelipe Contreras, Jun 8, 2021
  11. 08/12 doc: asciidoctor: use html-prefix only for htmlFelipe Contreras, Jun 8, 2021
  12. 11/12 doc: asciidoctor: split the format from the codeFelipe Contreras, Jun 8, 2021
  13. 10/12 doc: asciidoctor: improve string handlingFelipe Contreras, Jun 8, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.