Class: Jekyll::Archimate::CatalogTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::Archimate::CatalogTag
- Includes:
- MarkupConverter
- Defined in:
- lib/jekyll/archimate/catalog_tag.rb
Overview
Insert a diagram from the ArchiMate model.
{% element_catalog type:"Principle" | caption:"Principles Catalog" %}
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.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #elements ⇒ Object
-
#initialize(tag_name, markup, tokens) ⇒ CatalogTag
constructor
A new instance of CatalogTag.
- #render(context) ⇒ Object
- #render_properties(props) ⇒ Object
- #render_rows(elements) ⇒ Object
- #render_table ⇒ Object
- #scan_attributes(context) ⇒ Object
- #site ⇒ Object
Methods included from MarkupConverter
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ CatalogTag
Returns a new instance of CatalogTag.
18 19 20 21 22 23 24 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 18 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.
13 14 15 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 13 def caption @caption end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
12 13 14 |
# File 'lib/jekyll/archimate/catalog_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/catalog_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/catalog_tag.rb', line 15 def markup @markup end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
16 17 18 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 16 def model @model end |
Instance Method Details
#elements ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 51 def elements @element_types .map do |element_type| model .elements .select { |el| el.type == element_type } end .flatten .compact end |
#render(context) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 26 def render(context) @context = context @model = ArchimateCache.instance.model scan_attributes(context) render_table end |
#render_properties(props) ⇒ Object
75 76 77 78 79 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 75 def render_properties(props) return "" if props.empty? "<dl>" + props.map { |k, v| "<dt>#{k}</dt><dd>#{v}</dd>" }.join("") + "</dl>" end |
#render_rows(elements) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 62 def render_rows(elements) return "<tr><td colspan=\"3\">No Items</td></tr>" if elements.empty? elements.map do |element| <<-TABLE_ROW <tr> <td><span class="badge badge-primary">#{element.type}</span> #{element.name}</td> <td>#{@converter.convert(element.documentation.to_s).gsub(%r{</?p[^>]*>}, '').chomp if element.documentation}</td> <td>#{render_properties(element.properties)}</td> </tr> TABLE_ROW end.join("") end |
#render_table ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 33 def render_table <<-TABLE.gsub(/^ {6}/, '') <table> <caption>#{caption}</caption> <thead> <tr> <th>Name</th> <th>Documentation</th> <th>Properties</th> </tr> </thead> <tbody> #{render_rows(elements)} </tbody> </table> TABLE end |
#scan_attributes(context) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 81 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/, '') # @caption = @converter.convert(caption).gsub(/<\/?p[^>]*>/, '').chomp if @caption @caption = @converter.convert(caption).gsub(%r{</?p[^>]*>}, '').chomp if @caption element_type = attributes['type'] element_type = element_type.gsub!(/\A"|"\Z/, '') if element_type @element_types = element_type.split(",").map(&:strip) end |
#site ⇒ Object
101 102 103 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 101 def site @site ||= context.registers[:site] end |