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 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.
-
#element_types ⇒ Object
readonly
Returns the value of attribute element_types.
-
#markup ⇒ Object
readonly
Returns the value of attribute markup.
Instance Method Summary collapse
- #cell_content(caller, callee) ⇒ Object
- #converter(context) ⇒ Object
-
#initialize(tag_name, markup, tokens) ⇒ MatrixTag
constructor
A new instance of MatrixTag.
- #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.
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
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
13 14 15 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 13 def caption @caption end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
12 13 14 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 12 def context @context end |
#element_types ⇒ Object (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 |
#markup ⇒ Object (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} → #{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 |
#converter(context) ⇒ Object
97 98 99 100 101 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 97 def converter(context) # Gather settings site = context.registers[:site] site.find_converter_instance(::Jekyll::Converters::Markdown) 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_rows ⇒ Object
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_table ⇒ Object
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> </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 94 95 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 80 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
103 104 105 |
# File 'lib/jekyll/archimate/matrix_tag.rb', line 103 def site @site ||= context.registers[:site] end |