From e1f2ea4a1e3ca52037b6e3265d2ea94aaa2f72c8 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 25 Feb 2023 12:11:54 +0800 Subject: [PATCH] Add custom Asciidoctor extensions to load path --- Gemfile | 4 + Gemfile.lock | 31 ++++++ config.toml | 6 + flake.lock | 103 +++++++++++++++++- flake.nix | 19 +++- gems/.gitignore | 58 ++++++++++ ...ciidoctor-foodogsquared-extensions.gemspec | 19 ++++ .../asciidoctor-foodogsquared-extensions.rb | 2 + .../asciidoctor/foodogsquared-extensions.rb | 7 ++ .../asciidoctor/man-inline-macro/extension.rb | 22 ++++ gemset.nix | 76 +++++++++++++ shell.nix | 23 +++- 12 files changed, 361 insertions(+), 9 deletions(-) create mode 100644 Gemfile.lock create mode 100644 gems/.gitignore create mode 100644 gems/asciidoctor-foodogsquared-extensions.gemspec create mode 100644 gems/lib/asciidoctor-foodogsquared-extensions.rb create mode 100644 gems/lib/asciidoctor/foodogsquared-extensions.rb create mode 100644 gems/lib/asciidoctor/man-inline-macro/extension.rb create mode 100644 gemset.nix diff --git a/Gemfile b/Gemfile index a093b98..0aef2c6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,6 @@ source 'https://rubygems.org' gem 'asciidoctor' +gem 'asciidoctor-html5s' +gem 'asciidoctor-rouge' +gem 'rouge' +gem 'asciidoctor-foodogsquared-extensions', :path => './gems' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..58a40d1 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,31 @@ +PATH + remote: gems + specs: + asciidoctor-foodogsquared-extensions (1.0.0) + asciidoctor (~> 2.0) + +GEM + remote: https://rubygems.org/ + specs: + asciidoctor (2.0.18) + asciidoctor-html5s (0.5.1) + asciidoctor (>= 1.5.7, < 3.0) + thread_safe (~> 0.3.4) + asciidoctor-rouge (0.4.0) + asciidoctor (>= 1.5.6, < 2.1) + rouge (>= 2.2, < 4) + rouge (3.30.0) + thread_safe (0.3.6) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + asciidoctor + asciidoctor-foodogsquared-extensions! + asciidoctor-html5s + asciidoctor-rouge + rouge + +BUNDLED WITH + 2.4.6 diff --git a/config.toml b/config.toml index fcf4e11..daf4a57 100644 --- a/config.toml +++ b/config.toml @@ -13,6 +13,12 @@ path = "github.com/foo-dogsquared/hugo-theme-more-contentful" [[module.imports]] path = "github.com/foo-dogsquared/hugo-mod-web-feeds" +[markup.asciidocExt] +extensions = [ + "asciidoctor-foodogsquared-extensions" +] +workingFolderCurrent = true + [markup.asciidocExt.attributes] toc = true sectanchors = true diff --git a/flake.lock b/flake.lock index 5a809fa..71bf546 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,41 @@ { "nodes": { + "bundix": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1673616892, + "narHash": "sha256-KDKdesIUpyM6YnGsZMOxN34NhTNCsXvd03qsHNtUdWc=", + "owner": "sagittaros", + "repo": "bundix", + "rev": "4e0d18ad1954bc447540e4f890c3efdf3c53b3a2", + "type": "github" + }, + "original": { + "owner": "sagittaros", + "repo": "bundix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1676283394, @@ -15,6 +51,21 @@ "type": "github" } }, + "flake-utils_2": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1676150441, @@ -31,10 +82,60 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1673525234, + "narHash": "sha256-fMP37VTeqSzC8JYoQJinLOnHfjriE5uKInLWJRz5K3E=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "92f9580a4c369b4b51a7b6a5e77da43720134c9f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1674361931, + "narHash": "sha256-lUIZItHbW+LmJAz9V9puLq2rHlewcUgg1RPehkQIkzc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ef479383e13698c8d5ccf8a608485dc8ce1d4f80", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "ruby-nix": "ruby-nix" + } + }, + "ruby-nix": { + "inputs": { + "bundix": "bundix", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1676983063, + "narHash": "sha256-VvBdc1KnNHD7Q5SKtMAvC9iLV7ferwv6lIACYdmUxas=", + "owner": "sagittaros", + "repo": "ruby-nix", + "rev": "e4a9f70e4f2785ebcfb14891f3017fdb0016fb40", + "type": "github" + }, + "original": { + "owner": "sagittaros", + "repo": "ruby-nix", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index e81e095..2d1287c 100644 --- a/flake.nix +++ b/flake.nix @@ -4,14 +4,25 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; + ruby-nix.url = "github:sagittaros/ruby-nix"; }; outputs = inputs@{ self, nixpkgs, ... }: - let systems = inputs.flake-utils.lib.defaultSystems; + let + systems = inputs.flake-utils.lib.defaultSystems; + overlays = [ inputs.ruby-nix.overlays.ruby ]; in inputs.flake-utils.lib.eachSystem systems (system: - let pkgs = import nixpkgs { inherit system; }; + let + pkgs = import nixpkgs { + inherit system; + overlays = overlays ++ [ + (final: prev: { + ruby-nix = inputs.ruby-nix.lib prev; + }) + ]; + }; in { - devShell = - import ./shell.nix { inherit pkgs; }; + devShells.default = import ./shell.nix { inherit pkgs; }; + }); } diff --git a/gems/.gitignore b/gems/.gitignore new file mode 100644 index 0000000..0cecb3e --- /dev/null +++ b/gems/.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/gems/asciidoctor-foodogsquared-extensions.gemspec b/gems/asciidoctor-foodogsquared-extensions.gemspec new file mode 100644 index 0000000..853ca0a --- /dev/null +++ b/gems/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/gems/lib/asciidoctor-foodogsquared-extensions.rb b/gems/lib/asciidoctor-foodogsquared-extensions.rb new file mode 100644 index 0000000..d2a571d --- /dev/null +++ b/gems/lib/asciidoctor-foodogsquared-extensions.rb @@ -0,0 +1,2 @@ +# frozen_string_literal: true +require 'asciidoctor/foodogsquared-extensions' diff --git a/gems/lib/asciidoctor/foodogsquared-extensions.rb b/gems/lib/asciidoctor/foodogsquared-extensions.rb new file mode 100644 index 0000000..2b0afab --- /dev/null +++ b/gems/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/gems/lib/asciidoctor/man-inline-macro/extension.rb b/gems/lib/asciidoctor/man-inline-macro/extension.rb new file mode 100644 index 0000000..807a017 --- /dev/null +++ b/gems/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 diff --git a/gemset.nix b/gemset.nix new file mode 100644 index 0000000..4080536 --- /dev/null +++ b/gemset.nix @@ -0,0 +1,76 @@ +{ + asciidoctor = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "11z3vnd8vh3ny1vx69bjrbck5b2g8zsbj94npyadpn7fdp8y3ldv"; + target = "ruby"; + type = "gem"; + }; + targets = []; + version = "2.0.18"; + }; + asciidoctor-foodogsquared-extensions = { + dependencies = ["asciidoctor"]; + groups = ["default"]; + platforms = []; + source = { + path = "gems"; + target = "ruby"; + type = "path"; + }; + targets = []; + version = "1.0.0"; + }; + asciidoctor-html5s = { + dependencies = ["asciidoctor" "thread_safe"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1zfbfcqyrsk8bnd526ang3b4j3m5pbns7x3fdxarrm8vv1qplss1"; + target = "ruby"; + type = "gem"; + }; + targets = []; + version = "0.5.1"; + }; + asciidoctor-rouge = { + dependencies = ["asciidoctor" "rouge"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "197sbzs9km58pgfqdnnglhqr7anhb0m330cv1vxfc3s2qz106zjz"; + target = "ruby"; + type = "gem"; + }; + targets = []; + version = "0.4.0"; + }; + rouge = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1dnfkrk8xx2m8r3r9m2p5xcq57viznyc09k7r3i4jbm758i57lx3"; + target = "ruby"; + type = "gem"; + }; + targets = []; + version = "3.30.0"; + }; + thread_safe = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "0nmhcgq6cgz44srylra07bmaw99f5271l0dpsvl5f75m44l0gmwy"; + target = "ruby"; + type = "gem"; + }; + targets = []; + version = "0.3.6"; + }; +} \ No newline at end of file diff --git a/shell.nix b/shell.nix index cfb9e16..a6e43d4 100644 --- a/shell.nix +++ b/shell.nix @@ -2,18 +2,33 @@ with pkgs; +let + localGem = ruby-nix { + name = "asciidoctor-foodogsquared-extensions"; + ruby = ruby_3_1; + gemset = ./gemset.nix; + }; +in mkShell { + buildInputs = [ + localGem.env + localGem.ruby + ]; + packages = [ - curl - cacert - asciidoctor - entr + bundix git go hugo jq openring gnumake + tree-sitter + + # Formatters... + rufo # ...for Ruby. + nixpkgs-fmt # ...for Nix. + nodePackages.prettier # ...for the web files. ]; shellHook = ''