Class: Jekyll::Archimate::CatalogTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::Archimate::CatalogTag
- 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
- #converter(context) ⇒ Object
- #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
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ CatalogTag
Returns a new instance of CatalogTag.
16 17 18 19 20 21 22 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 16 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.
11 12 13 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 11 def caption @caption end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
10 11 12 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 10 def context @context end |
#element_types ⇒ Object (readonly)
Returns the value of attribute element_types.
12 13 14 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 12 def element_types @element_types end |
#markup ⇒ Object (readonly)
Returns the value of attribute markup.
13 14 15 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 13 def markup @markup end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
14 15 16 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 14 def model @model end |
Instance Method Details
#converter(context) ⇒ Object
99 100 101 102 103 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 99 def converter(context) # Gather settings site = context.registers[:site] site.find_converter_instance(::Jekyll::Converters::Markdown) end |
#elements ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 49 def elements @element_types .map do |element_type| model .elements .select { |el| el.type == element_type } end .flatten .compact end |
#render(context) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 24 def render(context) @context = context @model = ArchimateCache.instance.model scan_attributes(context) render_table end |
#render_properties(props) ⇒ Object
73 74 75 76 77 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 73 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
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 60 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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 31 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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 79 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
105 106 107 |
# File 'lib/jekyll/archimate/catalog_tag.rb', line 105 def site @site ||= context.registers[:site] end |