Path: blob/main/_plugins/jekyll-tool-tag.rb
1677 views
# frozen_string_literal: true12module Jekyll3##4# Tags are useful in liquid to process data and access internal functions. Ruby functions are *always* faster than liquid templates, so, when possible, consider writing a custom Ruby filter or tag.5#6#7# - Jekyll::Tags::BibTag - {% bibliography %}8# - Jekyll::Tags::CiteTag - {% cite hiltemann2023galaxy, %}9# - Jekyll::Tags::CiteUrlTag - {% cite_url Batut2018 %}10# - Jekyll::Tags::ColorPickerTag - {% color_picker #ff0000 %}11# - Jekyll::Tags::CustomLinkTag - {% link file.md %}12# - Jekyll::Tags::DumpSearchDataTag - {% dump_search_view testing %}13# - Jekyll::Tags::FileExistsTag - {% file_exists path.md %}14# - Jekyll::Tags::IconTag - {% icon email %}15# - Jekyll::Tags::IconTagVar - {% icon var1 %}16# - Jekyll::Tags::SnippetIncludeTag - {% snippet %}17# - Jekyll::Tags::ToolTag - {% tool [My Tool](Grouping1) %}18# - Jekyll::Tags::WorkflowTag - unused?19module Tags2021# The tool tag which allows us to do fancy tool links22class ToolTag < Liquid::Tag23def initialize(tag_name, text, tokens)24super25@text = text.strip26end2728##29# {% tool %} - the Tool rendering tag30#31# The first part should be any text, the last should be the tool_id/tool_version32#33# Examples:34#35# {% tool Group on Column %}36# {% tool [Group on Column](Grouping1) %}37# {% tool [Group on Column](Grouping1/1.0.0) %}38# {% tool [Group on Column](toolshed.g2.bx.psu.edu/repos/devteam/fastqc/fastqc/0.72+galaxy1) %}39def render(context)40format = /\[(.*)\]\((.*)\)/414243m = @text.match(format)4445if m46# check if a variable was provided for the tool id47tool = context[m[2].tr('{}', '')] || m[2]48version = tool.split('/').last4950if tool.count('/').zero?51"<span class=\"tool\" data-tool=\"#{tool}\" title=\"#{m[1]} tool\" aria-role=\"button\">" \52'<i class="fas fa-wrench" aria-hidden="true"></i> ' \53"<strong>#{m[1]}</strong>" \54'</span>'55else56"<span class=\"tool\" data-tool=\"#{tool}\" title=\"#{m[1]} tool\" aria-role=\"button\">" \57'<i class="fas fa-wrench" aria-hidden="true"></i> ' \58"<strong>#{m[1]}</strong> " \59'(' \60'<i class="fas fa-cubes" aria-hidden="true"></i> ' \61"Galaxy version #{version}" \62')' \63'</span>'64end65else66%(<span><strong>#{@text}</strong> <i class="fas fa-wrench" aria-hidden="true"></i></span>)67end68end69end7071##72# The (unused?) workflow rendering tag.73class WorkflowTag < Liquid::Tag74def initialize(tag_name, text, tokens)75super76@text = text.strip77end7879# Call the tag.80# It MUST be this format:81# {% workflow [Main Workflow](topics/x/tutorials/y/material/workflows/main.ga) %}82def render(_context)83format = /\[(?<title>.*)\]\((?<url>.*)\)/84m = @text.match(format)85# puts "Found #{@text} => #{m[:title]}, #{m[:url]}"8687"<span class=\"workflow\" data-workflow=\"#{m[:url]}\"><strong>#{m[:title]}</strong> " \88'<i class="fas fa-share-alt" aria-hidden="true"></i></span>'89end90end91end92end9394Liquid::Template.register_tag('tool', Jekyll::Tags::ToolTag)95Liquid::Template.register_tag('workflow', Jekyll::Tags::WorkflowTag)969798