Class: Jekyll::Ett::ToolTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/elixir-toolkit-theme-plugins/tool_tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(tagName, content, tokens) ⇒ ToolTag

Returns a new instance of ToolTag.



7
8
9
10
11
# File 'lib/elixir-toolkit-theme-plugins/tool_tag.rb', line 7

def initialize(tagName, content, tokens)
    super
    @content = content
    load_tools
end

Instance Method Details

#create_tag(url, icon, label) ⇒ Object



71
72
73
# File 'lib/elixir-toolkit-theme-plugins/tool_tag.rb', line 71

def create_tag(url, icon, label)
    "<a href='#{url}' target='_blank' rel='noopener' class='mt-2 me-2'><span class='badge bg-dark text-white hover-primary'><i class='fa-solid #{icon} me-2'></i>#{label}</span></a>"
end

#create_tags(tool) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/elixir-toolkit-theme-plugins/tool_tag.rb', line 41

def create_tags(tool)
    tags = ""
    tags << create_tag("#{tool["url"]}", "fa-link", "Website")
    if tool["registry"]
        registry = tool["registry"]

        if registry["biotools"]
            tags << create_tag("https://bio.tools/#{registry["biotools"]}", "fa-info", "Tool info")
        end

        if registry["fairsharing"]
            tags << create_tag("https://fairsharing.org/FAIRsharing.#{registry["fairsharing"]}", "fa-database", "Standards/Databases")
        end

        if registry["fairsharing-coll"]
            tags << create_tag("https://fairsharing.org/#{registry["fairsharing-coll"]}", "fa-database", "Standards/Databases")
        end

        if registry["tess"]
            tags << create_tag("https://tess.elixir-europe.org/search?q=#{registry["tess"]}", "fa-graduation-cap", "Training")
        end

        if registry["europmc"]
            tags << create_tag("https://europepmc.org/article/MED/#{registry["europmc"]}", "fa-book", "Publication")
        end

    end
    tags
end

#find_tool(tool_id) ⇒ Object



34
35
36
37
38
39
# File 'lib/elixir-toolkit-theme-plugins/tool_tag.rb', line 34

def find_tool(tool_id)
    tool = @tools.find { |t| t["id"] == tool_id.strip }
    return tool if tool
    
    raise Exception.new "Undefined tool ID: #{tool_id}"
end

#load_toolsObject



13
14
15
16
# File 'lib/elixir-toolkit-theme-plugins/tool_tag.rb', line 13

def load_tools
    tools_path = File.join(Dir.pwd, "_data", "tool_and_resource_list.yml")
    @tools = YAML.load(File.read(tools_path))
end

#render(context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/elixir-toolkit-theme-plugins/tool_tag.rb', line 18

def render(context)
    tool = find_tool(context[@content.strip])
    tags = create_tags(tool)
    %Q{<a
        tabindex="0"
        class="tool"
        aria-description="#{tool["description"]}"
        data-bs-toggle="popover"
        data-bs-placement="bottom"
        data-bs-trigger="focus"
        data-bs-content="<h5>#{tool["name"]}</h5><div class='mb-2'>#{tool["description"]}</div>#{tags}"
        data-bs-template="<div class='popover popover-tool' role='tooltip'><div class='popover-arrow'></div><h3 class='popover-header'></h3><div class='popover-body'></div></div>"
        data-bs-html="true"
        ><i class="fa-solid fa-wrench me-2"></i>#{ tool["name"] }</a>}
end