Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/_plugins/jekyll-tool-tag.rb
1677 views
1
# frozen_string_literal: true
2
3
module Jekyll
4
##
5
# 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.
6
#
7
#
8
# - Jekyll::Tags::BibTag - {% bibliography %}
9
# - Jekyll::Tags::CiteTag - {% cite hiltemann2023galaxy, %}
10
# - Jekyll::Tags::CiteUrlTag - {% cite_url Batut2018 %}
11
# - Jekyll::Tags::ColorPickerTag - {% color_picker #ff0000 %}
12
# - Jekyll::Tags::CustomLinkTag - {% link file.md %}
13
# - Jekyll::Tags::DumpSearchDataTag - {% dump_search_view testing %}
14
# - Jekyll::Tags::FileExistsTag - {% file_exists path.md %}
15
# - Jekyll::Tags::IconTag - {% icon email %}
16
# - Jekyll::Tags::IconTagVar - {% icon var1 %}
17
# - Jekyll::Tags::SnippetIncludeTag - {% snippet %}
18
# - Jekyll::Tags::ToolTag - {% tool [My Tool](Grouping1) %}
19
# - Jekyll::Tags::WorkflowTag - unused?
20
module Tags
21
22
# The tool tag which allows us to do fancy tool links
23
class ToolTag < Liquid::Tag
24
def initialize(tag_name, text, tokens)
25
super
26
@text = text.strip
27
end
28
29
##
30
# {% tool %} - the Tool rendering tag
31
#
32
# The first part should be any text, the last should be the tool_id/tool_version
33
#
34
# Examples:
35
#
36
# {% tool Group on Column %}
37
# {% tool [Group on Column](Grouping1) %}
38
# {% tool [Group on Column](Grouping1/1.0.0) %}
39
# {% tool [Group on Column](toolshed.g2.bx.psu.edu/repos/devteam/fastqc/fastqc/0.72+galaxy1) %}
40
def render(context)
41
format = /\[(.*)\]\((.*)\)/
42
43
44
m = @text.match(format)
45
46
if m
47
# check if a variable was provided for the tool id
48
tool = context[m[2].tr('{}', '')] || m[2]
49
version = tool.split('/').last
50
51
if tool.count('/').zero?
52
"<span class=\"tool\" data-tool=\"#{tool}\" title=\"#{m[1]} tool\" aria-role=\"button\">" \
53
'<i class="fas fa-wrench" aria-hidden="true"></i> ' \
54
"<strong>#{m[1]}</strong>" \
55
'</span>'
56
else
57
"<span class=\"tool\" data-tool=\"#{tool}\" title=\"#{m[1]} tool\" aria-role=\"button\">" \
58
'<i class="fas fa-wrench" aria-hidden="true"></i> ' \
59
"<strong>#{m[1]}</strong> " \
60
'(' \
61
'<i class="fas fa-cubes" aria-hidden="true"></i> ' \
62
"Galaxy version #{version}" \
63
')' \
64
'</span>'
65
end
66
else
67
%(<span><strong>#{@text}</strong> <i class="fas fa-wrench" aria-hidden="true"></i></span>)
68
end
69
end
70
end
71
72
##
73
# The (unused?) workflow rendering tag.
74
class WorkflowTag < Liquid::Tag
75
def initialize(tag_name, text, tokens)
76
super
77
@text = text.strip
78
end
79
80
# Call the tag.
81
# It MUST be this format:
82
# {% workflow [Main Workflow](topics/x/tutorials/y/material/workflows/main.ga) %}
83
def render(_context)
84
format = /\[(?<title>.*)\]\((?<url>.*)\)/
85
m = @text.match(format)
86
# puts "Found #{@text} => #{m[:title]}, #{m[:url]}"
87
88
"<span class=\"workflow\" data-workflow=\"#{m[:url]}\"><strong>#{m[:title]}</strong> " \
89
'<i class="fas fa-share-alt" aria-hidden="true"></i></span>'
90
end
91
end
92
end
93
end
94
95
Liquid::Template.register_tag('tool', Jekyll::Tags::ToolTag)
96
Liquid::Template.register_tag('workflow', Jekyll::Tags::WorkflowTag)
97
98