Skip to content

Commit

Permalink
Convert tabbed content to custom plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Mar 10, 2024
1 parent 5b0e7ac commit 9255fa4
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 105 deletions.
3 changes: 2 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
title: Ladysnake's Website
source: "public"
source: ./public
plugins_dir: ./jekyll_plugins
markdown: kramdown
sass:
style: compressed
Expand Down
39 changes: 39 additions & 0 deletions jekyll_plugins/TabbedBuildscriptTag.rb
Original file line number Diff line number Diff line change
@@ -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)
42 changes: 42 additions & 0 deletions jekyll_plugins/TabbedTag.rb
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions jekyll_plugins/TestTag.rb
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{%- comment -%}Prepare tab content{%- endcomment -%}
{%- capture groovy_title %}
{% include svg/groovy-logo.svg %} build.gradle
{%- endcapture %}
Expand All @@ -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 %}&lt;{% if mods.size > 1 %}{{ mod[0] | upcase }}_{% endif %}VERSION&gt;{% endcapture %}
{%- capture replacement_key %}&lt;{% if include.mods.size > 1 %}{{ mod[0] | upcase }}_{% endif %}VERSION&gt;{% endcapture %}
{%- capture replacement %}<span class="mod-version-{{ mod[0] }}">{{ replacement_key }}</span>{% endcapture %}
{{ result | replace: replacement_key, replacement }}
{%- endcapture %}
{% endfor %}
{% if mods.size > 0 and mods[0].size > 1 %}
{% if include.mods %}
<label for="select-mcversion">Select a Minecraft Version:</label>
<select id="select-mcversion" class="mc-version-select" name="select-mcversion" disabled>
<option>Loading...</option>
Expand Down
2 changes: 1 addition & 1 deletion public/_includes/wip.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>
<div>
{% if include.message %}
{{ include.message }}
{{ include.message | markdownify }}
{% else %}
Some things may not display correctly, and some information may be inaccurate or missing.<br/>
Please come back later for the finished product :&gt;
Expand Down
53 changes: 25 additions & 28 deletions public/tools/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The version strings may be invalid maven identifiers, as they are currently pull
- [Fabric dependency helper](https://fabricmc.net/develop/)
- [Quilt dependency helper](https://lambdaurora.dev/tools/import_quilt.html)

{% capture kts %}
{% capture gradleproperties %}
`gradle.properties`:
```properties
# Blabber (dialogues)
Expand Down Expand Up @@ -39,7 +39,28 @@ sodium_version = <SODIUM_VERSION>
trinkets_version = <TRINKETS_VERSION>
```
{% endcapture %}
{% capture catalogue %}

{%- buildscript
[blabber:2oRMVFgd],
[cca:K01OU20C],
[cloth:9s6osm5g],
[emi:fRiHVvU7],
[geckolib:8BmcQJ2H],
[iris:YL57xq9U],
[midnight:codAaoxh],
[modmenu:mOgUt4GM],
[rei:nfn13YXA],
[satin:fRbqPLg4],
[sodium:AANobbMI],
[trinkets:5aaWibi9],
-%}
[- groovy -]
{{ gradleproperties }}

[- kts -]
{{ gradleproperties }}

[- catalogue -]
`libs.versions.toml`:
```toml
[versions]
Expand Down Expand Up @@ -83,29 +104,5 @@ satin = { module = "org.ladysnake:satin", version.ref = "satin" }
sodium = { module = "maven.modrinth:sodium", version.ref = "sodium" }
trinkets = { module = "dev.emi:trinkets", version.ref = "trinkets" }
```
{% endcapture %}
{%- assign blabber = "blabber:2oRMVFgd" | split: ":" %}
{%- assign mods = "" | split: "," | push: blabber %}
{%- assign cca = "cca:K01OU20C" | split: ":" %}
{%- assign mods = mods | push: cca %}
{%- assign cloth = "cloth:9s6osm5g" | split: ":" %}
{%- assign mods = mods | push: cloth %}
{%- assign emi = "emi:fRiHVvU7" | split: ":" %}
{%- assign mods = mods | push: emi %}
{%- assign geckolib = "geckolib:8BmcQJ2H" | split: ":" %}
{%- assign mods = mods | push: geckolib %}
{%- assign iris = "iris:YL57xq9U" | split: ":" %}
{%- assign mods = mods | push: iris %}
{%- assign midnight = "midnight:codAaoxh" | split: ":" %}
{%- assign mods = mods | push: midnight %}
{%- assign modmenu = "modmenu:mOgUt4GM" | split: ":" %}
{%- assign mods = mods | push: modmenu %}
{%- assign rei = "rei:nfn13YXA" | split: ":" %}
{%- assign mods = mods | push: rei %}
{%- assign satin = "satin:fRbqPLg4" | split: ":" %}
{%- assign mods = mods | push: satin %}
{%- assign sodium = "sodium:AANobbMI" | split: ":" %}
{%- assign mods = mods | push: sodium %}
{%- assign trinkets = "trinkets:5aaWibi9" | split: ":" %}
{%- assign mods = mods | push: trinkets %}
{%- include tabbed_builscript.liquid mods=mods groovy=kts kts=kts catalogue=catalogue %}

{% endbuildscript %}
15 changes: 8 additions & 7 deletions public/wiki/blabber/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ If you are a developer, you can use Blabber as a library for your own project by

You can then add the library version to your `gradle.properties`file:

{% capture groovy %}
{%- buildscript %}
[- groovy -]
`gradle.properties`:
```properties
# Blabber
Expand Down Expand Up @@ -334,8 +335,8 @@ dependencies {
include "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${cca_version}"
}
```
{% endcapture %}
{% capture kts %}

[- kts -]
`gradle.properties`:
```properties
# Blabber
Expand Down Expand Up @@ -376,8 +377,8 @@ dependencies {
include("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${cca_version}")
}
```
{% endcapture %}
{% capture catalogue %}

[- catalogue -]
`libs.versions.toml`:
```toml
[versions]
Expand Down Expand Up @@ -420,8 +421,8 @@ dependencies {
include(libs.bundles.blabber)
}
```
{% endcapture %}
{%- include tabbed_builscript.liquid mod1="blabber:2oRMVFgd" mod2="cca:K01OU20C" groovy=groovy kts=kts catalogue=catalogue %}

{%- endbuildscript [blabber:2oRMVFgd], [cca:K01OU20C] -%}


You can find the current version of Blabber in the [releases](https://github.com/Ladysnake/Blabber/releases) tab of the repository on Github,
Expand Down
15 changes: 7 additions & 8 deletions public/wiki/cardinal-components-api/dev-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ mechanism provided by the Fabric toolchain to include Cardinal Components in you

Unless specified otherwise, the following block must be added to your `build.gradle` **after** the relevant `repositories` block:

{% capture groovy %}
{% buildscript [cca:K01OU20C] %}
[- groovy -]
`gradle.properties`:
```properties
cca_version = <VERSION>
Expand All @@ -26,8 +27,8 @@ dependencies {
include "dev.onyxstudios.cardinal-components-api:<MODULE>:${project.cca_version}"
}
```
{% endcapture %}
{% capture kts %}

[- kts -]
`gradle.properties`:
```properties
cca_version = <VERSION>
Expand All @@ -43,8 +44,8 @@ dependencies {
include("dev.onyxstudios.cardinal-components-api:<MODULE>:$ccaVersion")
}
```
{% endcapture %}
{% capture catalogue %}

[- catalogue -]
`libs.versions.toml`:
```toml
[versions]
Expand All @@ -67,9 +68,7 @@ dependencies {
include(libs.bundles.cca)
}
```
{% endcapture %}
{%- include tabbed_builscript.liquid mod1="cca:K01OU20C" groovy=groovy kts=kts catalogue=catalogue %}

{% endbuildscript %}

## Ladysnake Reposilite

Expand Down
Loading

0 comments on commit 9255fa4

Please sign in to comment.