-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTabbedBuildscriptTag.rb
More file actions
45 lines (41 loc) · 1.47 KB
/
TabbedBuildscriptTag.rb
File metadata and controls
45 lines (41 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Ladysnake
##
# A tag that can generate HTML markup for a Gradle buildscript with each tab containing
# instructions for a specific format
#
# Usage:
# "{%- buildscript [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 -%}"
#
# By default, only the Minecraft versions relevant to the first mod in the list
# will be shown. You can add the show_all_versions parameter to the tag to make it
# so every Minecraft version that has at least one mod version for it gets displayed.
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)]
show_all_versions = @input.include? "show_all_versions"
context["groovy"] = tabs["groovy"]
context["kts"] = tabs["kts"]
context["catalogue"] = tabs["catalogue"]
context["mods"] = mods
context["show_all_versions"] = show_all_versions
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)