Class: Jekyll::Archimate::ApplicationInteractionMatrixTag

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

Overview

Insert a diagram from the ArchiMate model.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ ApplicationInteractionMatrixTag

Returns a new instance of ApplicationInteractionMatrixTag.



14
15
16
17
18
19
20
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 14

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

Instance Attribute Details

#captionObject (readonly)

Returns the value of attribute caption.



10
11
12
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 10

def caption
  @caption
end

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 8

def context
  @context
end

#markupObject (readonly)

Returns the value of attribute markup.



9
10
11
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 9

def markup
  @markup
end

#plateauObject (readonly)

Returns the value of attribute plateau.



11
12
13
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 11

def plateau
  @plateau
end

Instance Method Details

#application_interactionObject

Here I want all of the Serving relationships between 2 app components included or derived.

attrs: source_selector: Element selector for source elements target_selector: Element selector for target elements relationship_selector



36
37
38
39
40
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
70
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 36

def application_interaction
  model = site.data["archimate_model"]
  dr_engine = ::Archimate::DerivedRelations.new(model)

  relationship_filter = lambda { |rel| rel.weight >= ::Archimate::DataModel::Serving::WEIGHT }

  plateau_today = dr_engine.element_by_name(plateau)
  today_rels = model.relationships.select do |rel|
    rel.source.id == plateau_today.id &&
      %w{CompositionRelationship AggregationRelationship}.include?(rel.type) &&
      rel.target.type == "ApplicationComponent"
  end
  today_apps = today_rels.map { |rel| rel.target }
  source_filter = lambda { |el|  }
  target_filter = lambda { |el| today_apps.map(&:id).include?(el.id) }
  stop_filter = lambda { |el| el.type == "ApplicationComponent" }

  concrete_rels = model.relationships.select { |rel|
    rel.type == "ServingRelationship" &&
      today_apps.include?(rel.source.id) &&
      today_apps.include?(rel.target.id)
  }

  derived_rels = dr_engine.derived_relations(
    today_apps,
    relationship_filter,
    target_filter,
    stop_filter
  )

  @all_rels = [concrete_rels, derived_rels].flatten

  @callers = @all_rels.map(&:source).uniq.sort { |a, b| a.name.to_s <=> b.name.to_s }
  @callees = @all_rels.map(&:target).uniq.sort { |a, b| a.name.to_s <=> b.name.to_s }
end

#cell_content(caller, callee) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 111

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

#matrix_dataObject



72
73
74
75
76
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 72

def matrix_data
  model = site.data["archimate_model"]
  dr_engine = ::Archimate::DerivedRelations.new(model)

end

#render(context) ⇒ Object



22
23
24
25
26
27
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 22

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

#render_rowsObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 99

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

#render_tableObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 78

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

#scan_attributes(context) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 129

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/, '')
  @plateau = attributes['plateau']&.gsub!(/\A"|"\Z/, '')
end

#siteObject



142
143
144
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 142

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