From 86a1afa51214302cf73e2940b44184a302ab4be2 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Mon, 3 Apr 2023 23:34:59 +0800 Subject: [PATCH] Create a helper file for the Asciidoctor extension --- lib/asciidoctor/foodogsquared-extensions.rb | 3 +++ lib/asciidoctor/helpers.rb | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 lib/asciidoctor/helpers.rb diff --git a/lib/asciidoctor/foodogsquared-extensions.rb b/lib/asciidoctor/foodogsquared-extensions.rb index af6de49..73dc9e4 100644 --- a/lib/asciidoctor/foodogsquared-extensions.rb +++ b/lib/asciidoctor/foodogsquared-extensions.rb @@ -2,6 +2,9 @@ require 'asciidoctor' require 'asciidoctor/extensions' + +require_relative 'helpers' + require_relative 'man-inline-macro/extension' require_relative 'swhid-inline-macro/extension' require_relative 'swhid-include-processor/extension' diff --git a/lib/asciidoctor/helpers.rb b/lib/asciidoctor/helpers.rb new file mode 100644 index 0000000..e2e7351 --- /dev/null +++ b/lib/asciidoctor/helpers.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Code copied from https://gist.github.com/komasaru/b3f22d5bcb8555deea1707b84d294045. +class String + def to_snake + self.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .downcase + end +end