Class: Jekyll::Archimate::MatrixTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::Archimate::MatrixTag
- Defined in:
- lib/jekyll/archimate/matrix_tag.rb
Overview
Insert a diagram from the ArchiMate model.
{% matrix type:"Principle" | caption:"Principles Catalog" %}
{% matrix source:"ApplicationComponent" | target:"ApplicationComponent" | }
Instance Attribute Summary collapse
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#element_types ⇒ Object
readonly
Returns the value of attribute element_types.
-
#markup ⇒ Object
readonly
Returns the value of attribute markup.
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
- #converter(context) ⇒ Object
-
#initialize(tag_name, markup, tokens) ⇒ MatrixTag
constructor
A new instance of MatrixTag.
- #matrix_data ⇒ Object
- #render(context) ⇒ Object
- #render_rows ⇒ Object
- #render_table ⇒ Object
- #scan_attributes(context) ⇒ Object
- #site ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ MatrixTag
Returns a new instance of MatrixTag.
15 16 17 18 19 20 21 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 15 def initialize(tag_name, markup, tokens) @markup = markup @context = nil @caption = nil @element_types = [] super end |
Instance Attribute Details
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
10 11 12 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 10 def caption @caption end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 9 def context @context end |
#element_types ⇒ Object (readonly)
Returns the value of attribute element_types.
11 12 13 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 11 def element_types @element_types end |
#markup ⇒ Object (readonly)
Returns the value of attribute markup.
12 13 14 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 12 def markup @markup 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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 37 def application_interaction model = site.data["archimate_model"] derived_relations_engine = ::Archimate::DerivedRelations.new(model) concrete_rels = model.relationships.select { |rel| rel.type == "ServingRelationship" && rel.source.type == "ApplicationComponent" && rel.target.type == "ApplicationComponent" } derived_rels = derived_relations_engine.derived_relations( model.elements.select { |el| el.type == "ApplicationComponent" }, lambda { |rel| rel.weight >= ::Archimate::DataModel::Serving::WEIGHT }, lambda { |el| el.type == "ApplicationComponent" }, lambda { |el| el.type == "ApplicationComponent" } ) @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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 99 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} → #{}#{callee.name} #{"(derived)" if derived}" cell = " <td>\n <a href=\"#\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"\#{tooltip}\">\n <span class=\"\#{span_class}\">↵ calls</span>\n </a>\n </td>\n END\n end\nend\n" |
#converter(context) ⇒ Object
134 135 136 137 138 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 134 def converter(context) # Gather settings site = context.registers[:site] site.find_converter_instance(::Jekyll::Converters::Markdown) end |
#matrix_data ⇒ Object
60 61 62 63 64 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 60 def matrix_data model = site.data["archimate_model"] derived_relations_engine = ::Archimate::DerivedRelations.new(model) end |
#render(context) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 23 def render(context) @context = context scan_attributes(context) application_interaction render_table end |
#render_rows ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 87 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_table ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 66 def render_table " <table class=\"table table-condensed table-hover table-striped\">\n <caption>\#{caption}</caption>\n <thead>\n <tr>\n <th> </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
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 117 def scan_attributes(context) @converter = converter(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 |
#site ⇒ Object
140 141 142 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 140 def site @site ||= context.registers[:site] end |