-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert tabbed content to custom plugins
- Loading branch information
Showing
12 changed files
with
198 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.