Class: Jekyll::Archimate::MatrixTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll/archimate/matrix_tag.rb

Overview

Insert a diagram from the ArchiMate model.

{% matrix plateau:"Today" | caption: "Today's Application Interaction" }

Constant Summary collapse

EMPTY_CELL =
"<td></td>"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ MatrixTag

Returns a new instance of MatrixTag.



17
18
19
20
21
22
23
# File 'lib/jekyll/archimate/matrix_tag.rb', line 17

def initialize(tag_name, markup, tokens)
  @markup = markup
  @context = nil
  @caption = nil
  @plateau = []
  super
end

Instance Attribute Details

#captionObject (readonly)

Returns the value of attribute caption.



13
14
15
# File 'lib/jekyll/archimate/matrix_tag.rb', line 13

def caption
  @caption
end

#contextObject (readonly)

Returns the value of attribute context.



12
13
14
# File 'lib/jekyll/archimate/matrix_tag.rb', line 12

def context
  @context
end

#element_typesObject (readonly)

Returns the value of attribute element_types.



14
15
16
# File 'lib/jekyll/archimate/matrix_tag.rb', line 14

def element_types
  @element_types
end

#markupObject (readonly)

Returns the value of attribute markup.



15
16
17
# File 'lib/jekyll/archimate/matrix_tag.rb', line 15

def markup
  @markup
end

Instance Method Details

#cell_content(caller, callee) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/jekyll/archimate/matrix_tag.rb', line 65

def cell_content(caller, callee)
  rels = @all_rels.select { |rel| rel.source == caller && rel.target == callee }
  return EMPTY_CELL if rels.empty?
  derived = rels.all?(&:derived)
  span_class = derived ? "text-danger" : "text-primary"
  tooltip = "#{caller.name} &rarr; #{callee.name} #{'(derived)' if derived}"
  <<~TABLE_CELL
    <td>
    <a href="#" data-toggle="tooltip" data-placement="top" title="#{tooltip}">
    <span class="#{span_class}">&crarr; calls</span>
    </a>
    </td>
  TABLE_CELL
end

#render(context) ⇒ Object



25
26
27
28
29
30
# File 'lib/jekyll/archimate/matrix_tag.rb', line 25

def render(context)
  @context = context
  scan_attributes(context)
  application_interaction
  render_table
end

#render_rowsObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jekyll/archimate/matrix_tag.rb', line 53

def render_rows
  return "<tr><td>No Items</td></tr>" if @callees.empty?
  @callees.map do |callee|
    <<~TABLE_ROW
      <tr>
      <th class="info" scope="row">#{callee.name}</th>
      #{@callers.map { |caller| cell_content(caller, callee) }.join('')}
      </tr>
    TABLE_ROW
  end.join("")
end

#render_tableObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jekyll/archimate/matrix_tag.rb', line 32

def render_table
  <<~TABLE
    <table class="table table-condensed table-hover table-striped">
    <caption>#{caption}</caption>
    <thead>
    <tr>
    <th>&nbsp;</th>
    <th class="success" scope="col" colspan="#{@callers.size}">Callers</th>
    </tr>
    <tr>
    <th class="info" scope="col">Callees</th>
    #{@callers.map { |ac| "<th class=\"success\" scope=\"col\" style=\"text-transform: capitalize\">#{ac.name}</th>" }.join("\n")}
    </tr>
    </thead>
    <tbody>
    #{render_rows.strip}
    </tbody>
    </table>
  TABLE
end

#scan_attributes(context) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/jekyll/archimate/matrix_tag.rb', line 80

def scan_attributes(context)
  # Render any liquid variables
  markup = Liquid::Template.parse(@markup).render(context)

  # Extract tag attributes
  attributes = {}
  markup.scan(Liquid::TagAttributes) do |key, value|
    attributes[key] = value
  end
  @caption = attributes['caption']&.gsub!(/\A"|"\Z/, '')
  element_type = attributes['type']
  element_type = element_type.gsub!(/\A"|"\Z/, '') if element_type
  @element_types = element_type.split(",").map(&:strip)
end

#siteObject



95
96
97
# File 'lib/jekyll/archimate/matrix_tag.rb', line 95

def site
  @site ||= context.registers[:site]
end