From 6d0fd81a7bff1dd020bbdca6b50c927eb1cd61f7 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 6 Jul 2024 10:16:47 -0700 Subject: [PATCH] Implement a ruby shortcode, with ruby/t to make elements --- layouts/shortcodes/ruby.html | 1 + layouts/shortcodes/ruby/t.html | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 layouts/shortcodes/ruby.html create mode 100644 layouts/shortcodes/ruby/t.html diff --git a/layouts/shortcodes/ruby.html b/layouts/shortcodes/ruby.html new file mode 100644 index 0000000..b21e64b --- /dev/null +++ b/layouts/shortcodes/ruby.html @@ -0,0 +1 @@ +{{- .Inner -}}{{- "" -}} diff --git a/layouts/shortcodes/ruby/t.html b/layouts/shortcodes/ruby/t.html new file mode 100644 index 0000000..2da9c3a --- /dev/null +++ b/layouts/shortcodes/ruby/t.html @@ -0,0 +1,31 @@ +{{- $lang := "" -}} +{{- $text := "" -}} + +{{- if eq (len .Params) 2 -}} + {{- $lang = .Get 0 -}} + {{- $text = .Get 1 -}} +{{- else if eq (len .Params) 1 -}} + {{- $text = .Get 0 -}} +{{- else -}} + {{ + errorf "%s: Invalid number of parameters to %s: Expected 1 or 2, got %d." + .Position .Name (len .Params) + }} +{{- end -}} + +{{- with $parent := .Parent -}} + {{- "" -}} + ( + {{- "" -}} + {{ $text }} + {{- "" -}} + ) + {{- "" -}} +{{- else -}} + {{ + errorf "%s: The %q shortcode is not meant to be called outside of a parent ruby shortcode." + .Position .Name + }} +{{- end -}}