aboutsummaryrefslogtreecommitdiffstats
path: root/docbook/asciidoctor-macros
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2018-06-23 14:03:49 +0200
committerAnders Broman <a.broman58@gmail.com>2018-06-27 17:01:18 +0000
commite4e0488da93d6eb43731d14f96544ab33928a005 (patch)
tree4b970a81437b6352cc197ac716f566038a7eeb97 /docbook/asciidoctor-macros
parent622b17a475a81aa3af5cc743b831d01233b99c31 (diff)
downloadwireshark-e4e0488da93d6eb43731d14f96544ab33928a005.tar.gz
wireshark-e4e0488da93d6eb43731d14f96544ab33928a005.tar.bz2
wireshark-e4e0488da93d6eb43731d14f96544ab33928a005.zip
docbook: reduce ruby code duplication by introducing utils module.
Change-Id: I7e436db3cb86f5ebd0f5827c6da630303bc3f538 Reviewed-on: https://code.wireshark.org/review/28400 Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'docbook/asciidoctor-macros')
-rw-r--r--docbook/asciidoctor-macros/commaize-block/extension.rb1
-rw-r--r--docbook/asciidoctor-macros/cveidlink-inline-macro/extension.rb11
-rw-r--r--docbook/asciidoctor-macros/ws_utils.rb13
-rw-r--r--docbook/asciidoctor-macros/wsbuglink-inline-macro/extension.rb10
-rw-r--r--docbook/asciidoctor-macros/wssalink-inline-macro/extension.rb10
5 files changed, 20 insertions, 25 deletions
diff --git a/docbook/asciidoctor-macros/commaize-block/extension.rb b/docbook/asciidoctor-macros/commaize-block/extension.rb
index 5cf765a22e..4b2b776b97 100644
--- a/docbook/asciidoctor-macros/commaize-block/extension.rb
+++ b/docbook/asciidoctor-macros/commaize-block/extension.rb
@@ -15,6 +15,7 @@ include Asciidoctor
# --
#
class CommaizeBlock < Extensions::BlockProcessor
+ include WsUtils
use_dsl
named :commaize
diff --git a/docbook/asciidoctor-macros/cveidlink-inline-macro/extension.rb b/docbook/asciidoctor-macros/cveidlink-inline-macro/extension.rb
index 8e2b741a25..0c07233018 100644
--- a/docbook/asciidoctor-macros/cveidlink-inline-macro/extension.rb
+++ b/docbook/asciidoctor-macros/cveidlink-inline-macro/extension.rb
@@ -10,21 +10,14 @@ include ::Asciidoctor
# cveidlink:<cve-number>[]
#
class CVEIdLinkInlineMacro < Extensions::InlineMacroProcessor
+ include WsUtils
use_dsl
named :cveidlink
def process(parent, cvenum, _attrs)
cvename = "CVE-#{cvenum}"
- suffix = ''
target = %(https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-#{cvenum})
- if parent.document.basebackend? 'html'
- parent.document.register :links, target
- %(#{(create_anchor parent, cvename, type: :link, target: target).render})
- elsif parent.document.backend == 'manpage'
- %(\\fB#{cvename})
- else
- %(#{cvename})
- end
+ create_doc_links(parent, target, cvename)
end
end
diff --git a/docbook/asciidoctor-macros/ws_utils.rb b/docbook/asciidoctor-macros/ws_utils.rb
new file mode 100644
index 0000000000..cff181cb15
--- /dev/null
+++ b/docbook/asciidoctor-macros/ws_utils.rb
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: MIT
+module WsUtils
+ def create_doc_links(parent, target, text)
+ if parent.document.basebackend? 'html'
+ parent.document.register :links, target
+ create_anchor(parent, text, type: :link, target: target).render.to_s
+ elsif parent.document.backend == 'manpage'
+ "\\fB#{text}"
+ else
+ bugtext
+ end
+ end
+end
diff --git a/docbook/asciidoctor-macros/wsbuglink-inline-macro/extension.rb b/docbook/asciidoctor-macros/wsbuglink-inline-macro/extension.rb
index ddb1fbf188..86df251285 100644
--- a/docbook/asciidoctor-macros/wsbuglink-inline-macro/extension.rb
+++ b/docbook/asciidoctor-macros/wsbuglink-inline-macro/extension.rb
@@ -11,6 +11,7 @@ include ::Asciidoctor
# Default bug text is "Bug".
#
class WSBugLinkInlineMacro < Extensions::InlineMacroProcessor
+ include WsUtils
use_dsl
named :wsbuglink
@@ -20,13 +21,6 @@ class WSBugLinkInlineMacro < Extensions::InlineMacroProcessor
def process(parent, bugnum, attrs)
bugtext = attrs['bugtext'] || %(Bug #{bugnum})
target = %(https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=#{bugnum})
- if parent.document.basebackend? 'html'
- parent.document.register :links, target
- %(#{(create_anchor parent, bugtext, type: :link, target: target).render})
- elsif parent.document.backend == 'manpage'
- %(\\fB#{bugtext})
- else
- %(#{bugtext})
- end
+ create_doc_links(parent, target, bugtext)
end
end
diff --git a/docbook/asciidoctor-macros/wssalink-inline-macro/extension.rb b/docbook/asciidoctor-macros/wssalink-inline-macro/extension.rb
index b2c3caf077..62e7612fab 100644
--- a/docbook/asciidoctor-macros/wssalink-inline-macro/extension.rb
+++ b/docbook/asciidoctor-macros/wssalink-inline-macro/extension.rb
@@ -10,6 +10,7 @@ include ::Asciidoctor
# wssalink:<dddd>[]
#
class WSSALinkInlineMacro < Extensions::InlineMacroProcessor
+ include WsUtils
use_dsl
named :'wssalink'
@@ -17,13 +18,6 @@ class WSSALinkInlineMacro < Extensions::InlineMacroProcessor
def process(parent, sanum, attrs)
satext = "wnpa-sec-#{sanum}"
target = %(https://www.wireshark.org/security/wnpa-sec-#{sanum})
- if parent.document.basebackend? 'html'
- parent.document.register :links, target
- %(#{(create_anchor parent, satext, type: :link, target: target).render})
- elsif parent.document.backend == 'manpage'
- %(\\fB#{satext})
- else
- %(#{satext})
- end
+ create_doc_links(parent, target, satext)
end
end