commit 4201e1c6e8a028618ab4cb4c6e54af5c3990aa27 Author: Gabriel Arazas Date: Sat Feb 25 12:11:54 2023 +0800 Add custom Asciidoctor extensions to load path diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cecb3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,58 @@ + +### Ruby ### +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Used by dotenv library to load environment variables. +# .env + +# Ignore Byebug command history file. +.byebug_history + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# Used by RuboCop. Remote config files pulled in from inherit_from directive. +# .rubocop-https?--* + diff --git a/asciidoctor-foodogsquared-extensions.gemspec b/asciidoctor-foodogsquared-extensions.gemspec new file mode 100644 index 0000000..853ca0a --- /dev/null +++ b/asciidoctor-foodogsquared-extensions.gemspec @@ -0,0 +1,19 @@ +Gem::Specification.new do |s| + s.name = 'asciidoctor-foodogsquared-extensions' + s.version = '1.0.0' + s.licenses = ['MIT'] + s.summary = "foo-dogsquared's custom Asciidoctor extensions" + s.description = <<-EOF + foo-dogsquared's custom Asciidoctor extensions as a Gem. This is not meant + to be used in production or as a public Gem. This is used since Hugo + doesn't allow loading Asciidoctor extensions with path separators. + EOF + + s.authors = ["Gabriel Arazas"] + s.email = "foodogsquared@foodogsquared.one" + s.metadata = { "source_code_uri" => "https://github.com/foo-dogsquared/foo-dogsquared.github.io" } + + s.files = Dir["lib/**/*", "*.gemspec"] + + s.add_runtime_dependency 'asciidoctor', '~> 2.0' +end diff --git a/lib/asciidoctor-foodogsquared-extensions.rb b/lib/asciidoctor-foodogsquared-extensions.rb new file mode 100644 index 0000000..d2a571d --- /dev/null +++ b/lib/asciidoctor-foodogsquared-extensions.rb @@ -0,0 +1,2 @@ +# frozen_string_literal: true +require 'asciidoctor/foodogsquared-extensions' diff --git a/lib/asciidoctor/foodogsquared-extensions.rb b/lib/asciidoctor/foodogsquared-extensions.rb new file mode 100644 index 0000000..2b0afab --- /dev/null +++ b/lib/asciidoctor/foodogsquared-extensions.rb @@ -0,0 +1,7 @@ +require 'asciidoctor' +require 'asciidoctor/extensions' +require_relative 'man-inline-macro/extension' + +Asciidoctor::Extensions.register do + inline_macro ManInlineMacro +end diff --git a/lib/asciidoctor/man-inline-macro/extension.rb b/lib/asciidoctor/man-inline-macro/extension.rb new file mode 100644 index 0000000..807a017 --- /dev/null +++ b/lib/asciidoctor/man-inline-macro/extension.rb @@ -0,0 +1,22 @@ +class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor + use_dsl + + named :man + name_positional_attributes 'volnum' + + def process parent, target, attrs + doc = parent.document + text = manname = target + suffix = (volnum = attrs['volnum']) ? %((#{volnum})) : '' + if doc.basebackend? 'html' + target = %(#{manname}#{doc.outfilesuffix}) + doc.register :links, target + node = create_anchor parent, text, type: :link, target: target + elsif doc.backend == 'manpage' + node = create_inline parent, :quoted, manname, type: :strong + else + node = create_inline parent, :quoted, manname + end + create_inline parent, :quoted, %(#{node.convert}#{suffix}) + end +end