diff --git a/_config.yml b/_config.yml index e49def7f..f4ff7281 100644 --- a/_config.yml +++ b/_config.yml @@ -1,5 +1,6 @@ title: Ladysnake's Website -source: "public" +source: ./public +plugins_dir: ./jekyll_plugins markdown: kramdown sass: style: compressed diff --git a/jekyll_plugins/TabbedBuildscriptTag.rb b/jekyll_plugins/TabbedBuildscriptTag.rb new file mode 100644 index 00000000..6b26d2aa --- /dev/null +++ b/jekyll_plugins/TabbedBuildscriptTag.rb @@ -0,0 +1,39 @@ +module Ladysnake + ## + # A tag that can generate HTML markup for a Gradle buildscript with each tab containing + # instructions for a specific format + # + # Usage: + # "{%- buildscript dependencies={key1: value1, key2: value2} -%} + # [build.gradle] + # Instructions for Groovy build.gradle + # + # [build.gradle.kts] + # Instructions for Kotlin build.gradle.kts + # + # [catalogue] + # Instructions for `libs.versions.toml` + # {%- endbuildscript -%}" + class TabbedBuildScriptTag < Liquid::Block + def initialize(tag_name, text, tokens) + super + @input = text + end + + def render(context) + body = super + mods = Hash[@input.scan(/\[(\w+):(\w+)\]/)] + tabs = Hash[TabbedTag.parse_tabs(body)] + + context["groovy"] = tabs["groovy"] + context["kts"] = tabs["kts"] + context["catalogue"] = tabs["catalogue"] + context["mods"] = mods + + include = "{% include tabbed_buildscript.liquid mods=mods groovy=groovy kts=kts catalogue=catalogue %}" + + Liquid::Template.parse(include).render(context) + end + end +end +Liquid::Template.register_tag('buildscript', Ladysnake::TabbedBuildScriptTag) diff --git a/jekyll_plugins/TabbedTag.rb b/jekyll_plugins/TabbedTag.rb new file mode 100644 index 00000000..561449c4 --- /dev/null +++ b/jekyll_plugins/TabbedTag.rb @@ -0,0 +1,42 @@ +module Ladysnake + ## + # A tag that can generate HTML markup for a section split in multiple toggleable tabs + # + # Usage: + # "{%- tabbed my_key -%} + # [- Tab 1 -] + # Tab 1 content + # + # [- Tab 2 -] + # Tab 2 content + # + # [- Tab 3 -] + # Tab 3 content + # {%- endtabbed %}" + class TabbedTag < Liquid::Block + ## + # Parses a markup string into pairs of [name, content] + # + # "[- Tab 1 -]\nContent" => [["Tab 1", "Content"], ...] + def self.parse_tabs(markup) + markup.scan(/^\[-\s*(.*?)\s*-\]\n(.*?)(?=\n\[-|\Z)/m) + end + + def initialize(tag_name, markup, options) + super + @input = markup + end + + def render(context) + body = super + tabs = TabbedTag.parse_tabs(body) + tab_names, tab_contents = tabs.transpose + context["key"] = @input + context["tab_names"] = tab_names + context["tab_contents"] = tab_contents + Liquid::Template.parse("{% include tabbed.liquid key=key tab_names=tab_names tabs=tab_contents %}").render(context) + end + end +end + +Liquid::Template.register_tag('tabbed', Ladysnake::TabbedTag) diff --git a/jekyll_plugins/TestTag.rb b/jekyll_plugins/TestTag.rb new file mode 100644 index 00000000..a307b270 --- /dev/null +++ b/jekyll_plugins/TestTag.rb @@ -0,0 +1,22 @@ +module Ladysnake + class TestTag < Liquid::Block + def render(context) + + puts @markup + puts "Hello" + puts super + + dependencies = Hash[@markup.scan(/\[(\w+):(\w+)\]/)] + puts dependencies + + # Extract the block content from the @markup variable + content = super + + # Do something with the parameters and content... + + # Return the rendered output + "Rendered output" + end + end +end +Liquid::Template.register_tag('test_tag', Ladysnake::TestTag) diff --git a/public/_includes/tabbed_builscript.liquid b/public/_includes/tabbed_buildscript.liquid similarity index 67% rename from public/_includes/tabbed_builscript.liquid rename to public/_includes/tabbed_buildscript.liquid index 7e2ef606..33574231 100644 --- a/public/_includes/tabbed_builscript.liquid +++ b/public/_includes/tabbed_buildscript.liquid @@ -1,3 +1,4 @@ +{%- comment -%}Prepare tab content{%- endcomment -%} {%- capture groovy_title %} {% include svg/groovy-logo.svg %} build.gradle {%- endcapture %} @@ -9,31 +10,18 @@ {% endcapture %} {%- assign tab_names = "" | split: "," | push: groovy_title | push: kts_title | push: catalogue_title %} {%- assign tabs = "" | split: "," | push: include.groovy | push: include.kts | push: include.catalogue %} -{%- if include.mods %} -{%- assign mods = include.mods %} -{%- else %} -{%- assign mod1 = include.mod1 | split: ":" %} -{%- assign mods = "" | split: "," | push: mod1 %} -{%- if include.mod2 %} -{%- assign mod2 = include.mod2 | split: ":" %} -{%- assign mods = mods | push: mod2 %} -{%- endif %} -{%- if include.mod3 %} -{%- assign mod3 = include.mod3 | split: ":" %} -{%- assign mods = mods | push: mod3 %} -{%- endif %} -{%- endif %} {%- capture result %} {%- include tabbed.liquid key="buildscript" tab_names=tab_names tabs=tabs %} {%- endcapture %} -{% for mod in mods %} +{%- comment -%}Render tabs and version selector{%- endcomment -%} +{% for mod in include.mods %} {%- capture result %} -{%- capture replacement_key %}<{% if mods.size > 1 %}{{ mod[0] | upcase }}_{% endif %}VERSION>{% endcapture %} +{%- capture replacement_key %}<{% if include.mods.size > 1 %}{{ mod[0] | upcase }}_{% endif %}VERSION>{% endcapture %} {%- capture replacement %}{{ replacement_key }}{% endcapture %} {{ result | replace: replacement_key, replacement }} {%- endcapture %} {% endfor %} -{% if mods.size > 0 and mods[0].size > 1 %} +{% if include.mods %}