git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: "Martin Ågren" <martin.agren@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Bagas Sanjaya" <bagasdotme@gmail.com>,
	"Jeff King" <peff@peff.net>, "Junio C Hamano" <gitster@pobox.com>,
	"brian m . carlson" <sandals@crustytoothpaste.net>,
	"Felipe Contreras" <felipe.contreras@gmail.com>
Subject: [PATCH 09/23] doc: asciidoctor: refactor macro registration
Date: Mon, 21 Jun 2021 11:30:56 -0500	[thread overview]
Message-ID: <20210621163110.1074145-10-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20210621163110.1074145-1-felipe.contreras@gmail.com>

There is no need to execute extra code every time the process block is
called.

In Ruby the lexical scope is shared, so we can define variables in the
register block scope, and all the rest will inherit those variables.

Based on the doctype and basebackend one of three blocks is selected for
the inline_macro. However, the conditionals will be run only once.

In the end Ruby will only run the code between `process do end`, nothing
else.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 Documentation/asciidoctor-extensions.rb | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/Documentation/asciidoctor-extensions.rb b/Documentation/asciidoctor-extensions.rb
index c77b6de350..a678704e17 100644
--- a/Documentation/asciidoctor-extensions.rb
+++ b/Documentation/asciidoctor-extensions.rb
@@ -2,15 +2,21 @@ require 'asciidoctor/extensions'
 
 Asciidoctor::Extensions.register do
 
+  doc = document
+
   inline_macro :linkgit do
-    process do |parent, target, attrs|
-      if parent.document.doctype == 'book'
+    if doc.doctype == 'book'
+      process do |parent, target, attrs|
         "<ulink url=\"#{target}.html\">" \
         "#{target}(#{attrs[1]})</ulink>"
-      elsif parent.document.basebackend? 'html'
-        prefix = parent.document.attr('git-relative-html-prefix')
+      end
+    elsif doc.basebackend? 'html'
+      prefix = doc.attr('git-relative-html-prefix')
+      process do |parent, target, attrs|
         %(<a href="#{prefix}#{target}.html">#{target}(#{attrs[1]})</a>)
-      elsif parent.document.basebackend? 'docbook'
+      end
+    elsif doc.basebackend? 'docbook'
+      process do |parent, target, attrs|
         "<citerefentry>\n" \
           "<refentrytitle>#{target}</refentrytitle>" \
           "<manvolnum>#{attrs[1]}</manvolnum>\n" \
-- 
2.32.0


  parent reply	other threads:[~2021-06-21 16:59 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 16:30 [PATCH 00/23] doc: cleanups and asciidoctor direct man pages Felipe Contreras
2021-06-21 16:30 ` [PATCH 01/23] doc: remove GNU troff workaround Felipe Contreras
2021-06-21 16:30 ` [PATCH 02/23] doc: use --stringparam in xmlto Felipe Contreras
2021-06-21 16:30 ` [PATCH 03/23] doc: simplify version passing Felipe Contreras
2021-06-21 16:30 ` [PATCH 04/23] doc: asciidoc: remove unnecessary attribute Felipe Contreras
2021-06-21 16:30 ` [PATCH 05/23] doc: asciidoctor: remove unnecessary require Felipe Contreras
2021-06-21 16:30 ` [PATCH 06/23] doc: asciidoctor: remove cruft Felipe Contreras
2021-06-21 16:30 ` [PATCH 07/23] doc: asciidoctor: reorganize extensions Felipe Contreras
2021-06-21 16:30 ` [PATCH 08/23] doc: asciidoctor: use html-prefix only for html Felipe Contreras
2021-06-21 16:30 ` Felipe Contreras [this message]
2021-06-21 16:30 ` [PATCH 10/23] doc: asciidoctor: improve string handling Felipe Contreras
2021-06-21 16:30 ` [PATCH 11/23] doc: asciidoctor: split the format from the code Felipe Contreras
2021-06-21 16:30 ` [PATCH 12/23] doc: asciidoctor: specify name of our group Felipe Contreras
2021-06-21 16:31 ` [PATCH 13/23] doc: doc-diff: set docdate manually Felipe Contreras
2021-06-21 16:31 ` [PATCH 14/23] doc-diff: drop --cut-footer switch Felipe Contreras
2021-06-21 16:31 ` [PATCH 15/23] doc: use asciidoctor to build man pages directly Felipe Contreras
2021-06-22  5:23   ` Bagas Sanjaya
2021-06-23  1:35     ` Felipe Contreras
2021-06-21 16:31 ` [PATCH 16/23] doc-diff: support asciidoctor man pages Felipe Contreras
2021-06-21 16:31 ` [PATCH 17/23] doc: asciidoctor: add linkgit macros in " Felipe Contreras
2021-06-21 16:31 ` [PATCH 18/23] doc: add man pages workaround for asciidoctor Felipe Contreras
2021-06-21 16:31 ` [PATCH 19/23] doc: asciidoctor: add hack for xrefs Felipe Contreras
2021-06-21 16:31 ` [PATCH 20/23] doc: asciidoctor: add hack to improve links Felipe Contreras
2021-06-21 16:31 ` [PATCH 21/23] doc: asciidoctor: add support for baseurl Felipe Contreras
2021-06-21 16:31 ` [PATCH 22/23] doc: asciidoctor: cleanup man page hack Felipe Contreras
2021-06-21 16:31 ` [PATCH 23/23] doc: asciidoctor: add hack for old versions Felipe Contreras
2021-06-22  5:35 ` [PATCH 00/23] doc: cleanups and asciidoctor direct man pages Bagas Sanjaya
2021-06-23  1:37   ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210621163110.1074145-10-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=avarab@gmail.com \
    --cc=bagasdotme@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.agren@gmail.com \
    --cc=peff@peff.net \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).