Class: Jekyll::Archimate::ApplicationInteractionMatrixTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::Archimate::ApplicationInteractionMatrixTag
- 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" }
Constant Summary collapse
- EMPTY_CELL =
"<td></td>"
Instance Attribute Summary collapse
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#markup ⇒ Object
readonly
Returns the value of attribute markup.
-
#plateau ⇒ Object
readonly
Returns the value of attribute plateau.
Instance Method Summary collapse
-
#application_interaction ⇒ Object
Here I want all of the Serving relationships between 2 app components included or derived.
- #cell_content(caller, callee) ⇒ Object
-
#initialize(tag_name, markup, tokens) ⇒ ApplicationInteractionMatrixTag
constructor
A new instance of ApplicationInteractionMatrixTag.
- #render(context) ⇒ Object
- #render_rows ⇒ Object
- #render_table ⇒ Object
- #scan_attributes(context) ⇒ Object
- #site ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ ApplicationInteractionMatrixTag
Returns a new instance of ApplicationInteractionMatrixTag.
17 18 19 20 21 22 23 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 17 def initialize(tag_name, markup, tokens) @markup = markup @context = nil @caption = nil @plateau = nil super end |
Instance Attribute Details
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
14 15 16 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 14 def caption @caption end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
12 13 14 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 12 def context @context end |
#markup ⇒ Object (readonly)
Returns the value of attribute markup.
13 14 15 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 13 def markup @markup end |
#plateau ⇒ Object (readonly)
Returns the value of attribute plateau.
15 16 17 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 15 def plateau @plateau end |
Instance Method Details
#application_interaction ⇒ Object
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
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 71 72 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 39 def application_interaction model = ArchimateCache.instance.model dr_engine = ::Archimate::DerivedRelations.new(model) relationship_filter = ->(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(&:target) target_filter = ->(el) { today_apps.map(&:id).include?(el.id) } stop_filter = ->(el) { el.type == "ApplicationComponent" } concrete_rels = model.relationships.select do |rel| rel.type == "ServingRelationship" && today_apps.include?(rel.source.id) && today_apps.include?(rel.target.id) end 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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 107 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} → #{callee.name} #{'(derived)' if derived}" <<~TABLE_CELL <td> <a href="#" data-toggle="tooltip" data-placement="top" title="#{tooltip}"> <span class="#{span_class}">↵ calls</span> </a> </td> TABLE_CELL end |
#render(context) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 25 def render(context) @context = context scan_attributes(context) application_interaction render_table end |
#render_rows ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 95 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_table ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 74 def render_table <<~TABLE <table class="table table-condensed table-hover table-striped"> <caption>#{caption}</caption> <thead> <tr> <th> </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
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 122 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 |
#site ⇒ Object
135 136 137 |
# File 'lib/jekyll/archimate/application_interaction_matrix_tag.rb', line 135 def site @site ||= context.registers[:site] end |