class Jekyll::CompetencyTag

Public Class Methods

new(tag_name, text, tokens) click to toggle source
Calls superclass method
# File lib/dsm-portfolio-plugin.rb, line 116
def initialize(tag_name, text, tokens)
    super

    # Store competency id for later.
    @competencyId = text.strip.split(" ")[0]
end

Public Instance Methods

render(context) click to toggle source
# File lib/dsm-portfolio-plugin.rb, line 123
def render(context)
    # Find the correct competency.
    competency = context.registers[:site].data['competencies'].select {|c| c['id'] == @competencyId} [0]
    
    # Add it to vignette if one exists.
    if context['active_vignette']
        # Find out if the current competency has already been logged.
        competencyTally = context['active_vignette'][:competencies].select {|c| c[:id] == competency['id']} [0]

        if competencyTally
            # Increment tally.
            competencyTally[:count] += 1
        else
            # Add entry.
            if competency
                context['active_vignette'][:competencies].push({
                    'id': competency['id'],
                    'count': 1,
                    'linked': true
                })
            else
                context['active_vignette'][:competencies].push({
                    'id': @competencyId,
                    'count': 1,
                    'linked': false
                })
            end
        end
    end

    # Render if available.
    if competency
        # <a href="#" class="badge badge-primary">Primary</a>
        " <a href=\"#{context.registers[:site].baseurl}/competencies##{competency['id']}\" class=\"badge badge-primary\">#{competency['id']}</a>"
    else
        " <span class=\"badge badge-danger\">#{@competencyId} undefined</span>"
    end
end