jekyll-archimate 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1390d11ccf52bae0ba50f6f22bd1dec103f2465e
|
4
|
+
data.tar.gz: 792d680dea4b6dbb6a95f91276d14d7df09ee373
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6f9b4030f007efb4ca456029abb00721af40180c67ea6ca96ebc81814ec10115c7c8261e8cd4cef66601ae2ae509d9aa46f608c175ed34f2f5378774171df4
|
7
|
+
data.tar.gz: 0730d88c6bd3b3067b1d797cb913a19dc8cecab7307ba9695a06b79ed66b02ad05f76ef423084e314a1826c7822fa3f62cf6f7f11d14867651dca99ecf453960
|
data/lib/jekyll-archimate.rb
CHANGED
@@ -3,5 +3,6 @@ require "jekyll"
|
|
3
3
|
require "jekyll/archimate/version"
|
4
4
|
require "jekyll/archimate/archimate_cache"
|
5
5
|
require "jekyll/archimate/archimate_diagram_tag"
|
6
|
-
require "jekyll/archimate/
|
6
|
+
require "jekyll/archimate/catalog_tag"
|
7
|
+
require "jekyll/archimate/matrix_tag"
|
7
8
|
require "jekyll/archimate/archimate_hook"
|
@@ -6,15 +6,17 @@ module Jekyll
|
|
6
6
|
module Archimate
|
7
7
|
# Removes all keys that have null or empty values
|
8
8
|
def self.hash_purge(hash)
|
9
|
-
hash.delete_if { |_, value| !value || value.empty? }
|
9
|
+
hash.delete_if { |_, value| !value || (value.is_a?(String) && value.empty?) }
|
10
10
|
end
|
11
11
|
|
12
12
|
# Base class for ArchiMate Entities: Model, Diagram, Element, Relationship
|
13
13
|
class EntityBase
|
14
14
|
attr_reader :entity
|
15
|
+
attr_reader :model
|
15
16
|
|
16
|
-
def initialize(entity)
|
17
|
+
def initialize(entity, model: nil)
|
17
18
|
@entity = entity
|
19
|
+
@model = model
|
18
20
|
end
|
19
21
|
|
20
22
|
def to_h
|
@@ -25,7 +27,7 @@ module Jekyll
|
|
25
27
|
{
|
26
28
|
id: entity.id,
|
27
29
|
name: entity.name,
|
28
|
-
documentation: entity.documentation
|
30
|
+
documentation: entity.documentation&.to_h,
|
29
31
|
properties: entity.properties.map(&:to_h)
|
30
32
|
}
|
31
33
|
end
|
@@ -46,8 +48,8 @@ module Jekyll
|
|
46
48
|
super.merge(
|
47
49
|
type: "Element",
|
48
50
|
element_type: entity.type,
|
49
|
-
relationships:
|
50
|
-
views:
|
51
|
+
relationships: model.relationships.select { |rel| rel.source&.id == entity.id || rel.target&.id == entity.id }.map(&:id),
|
52
|
+
views: model.diagrams.select { |dia| dia.element_ids.include?(entity.id) }.map(&:id)
|
51
53
|
)
|
52
54
|
end
|
53
55
|
end
|
@@ -58,9 +60,9 @@ module Jekyll
|
|
58
60
|
super.merge(
|
59
61
|
type: "Relationship",
|
60
62
|
relationship_type: entity.type,
|
61
|
-
source: entity.source,
|
62
|
-
target: entity.target,
|
63
|
-
views:
|
63
|
+
source: entity.source&.id,
|
64
|
+
target: entity.target&.id,
|
65
|
+
views: model.diagrams.select { |dia| dia.relationship_ids.include?(entity.id) }.map(&:id)
|
64
66
|
)
|
65
67
|
end
|
66
68
|
end
|
@@ -96,7 +98,7 @@ module Jekyll
|
|
96
98
|
def to_h
|
97
99
|
Archimate.hash_purge(
|
98
100
|
id: folder.id,
|
99
|
-
name: folder.name,
|
101
|
+
name: folder.name.to_s,
|
100
102
|
folders: folder.organizations.map { |child| Folder.new(child).to_h },
|
101
103
|
diagrams: items
|
102
104
|
)
|
@@ -119,11 +121,11 @@ module Jekyll
|
|
119
121
|
end
|
120
122
|
|
121
123
|
def elements
|
122
|
-
model.elements.map { |element| ElementEntity.new(element).to_h }
|
124
|
+
model.elements.map { |element| ElementEntity.new(element, model: model).to_h }
|
123
125
|
end
|
124
126
|
|
125
127
|
def relationships
|
126
|
-
model.relationships.map { |relationship| RelationshipEntity.new(relationship).to_h }
|
128
|
+
model.relationships.map { |relationship| RelationshipEntity.new(relationship, model: model).to_h }
|
127
129
|
end
|
128
130
|
|
129
131
|
def diagrams
|
@@ -182,6 +184,7 @@ module Jekyll
|
|
182
184
|
@archimate_file = archimate_file
|
183
185
|
@clean_generated_dirs = @site.config.fetch('clean', false)
|
184
186
|
@model = ArchimateCache.load_model(archimate_file.sub(site.source, ""))
|
187
|
+
@site.data["archimate_model"] = @model
|
185
188
|
end
|
186
189
|
|
187
190
|
def generate
|
@@ -240,7 +243,7 @@ module Jekyll
|
|
240
243
|
{
|
241
244
|
"id" => el.id,
|
242
245
|
"name" => el.name.to_s,
|
243
|
-
"documentation" => el.documentation
|
246
|
+
"documentation" => el.documentation&.to_s,
|
244
247
|
"type" => el.type,
|
245
248
|
"properties" => el.properties.each_with_object({}) do |property, hash|
|
246
249
|
hash[property.key.to_s] = property.value.to_s
|
@@ -251,7 +254,7 @@ module Jekyll
|
|
251
254
|
end
|
252
255
|
end
|
253
256
|
|
254
|
-
Jekyll::Hooks.register :site, :
|
257
|
+
Jekyll::Hooks.register :site, :pre_render do |site|
|
255
258
|
Jekyll.logger.info "ArchiMate Generator..."
|
256
259
|
Dir.glob("#{site.source}/**/*.archimate").each do |archimate_file|
|
257
260
|
unless archimate_file.start_with?(site.dest) || archimate_file.sub(site.source, "").start_with?("/_")
|
@@ -4,7 +4,7 @@ module Jekyll
|
|
4
4
|
#
|
5
5
|
# {% element_catalog type:"Principle" | caption:"Principles Catalog" %}
|
6
6
|
#
|
7
|
-
class
|
7
|
+
class CatalogTag < Liquid::Tag
|
8
8
|
attr_reader :context
|
9
9
|
attr_reader :caption
|
10
10
|
attr_reader :element_types
|
@@ -95,5 +95,5 @@ module Jekyll
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
Liquid::Template.register_tag("
|
98
|
+
Liquid::Template.register_tag("catalog", Jekyll::Archimate::CatalogTag)
|
99
99
|
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Archimate
|
3
|
+
# Insert a diagram from the ArchiMate model.
|
4
|
+
#
|
5
|
+
# {% matrix type:"Principle" | caption:"Principles Catalog" %}
|
6
|
+
# {% matrix source:"ApplicationComponent" | target:"ApplicationComponent" | }
|
7
|
+
#
|
8
|
+
class MatrixTag < Liquid::Tag
|
9
|
+
attr_reader :context
|
10
|
+
attr_reader :caption
|
11
|
+
attr_reader :element_types
|
12
|
+
attr_reader :markup
|
13
|
+
|
14
|
+
|
15
|
+
def initialize(tag_name, markup, tokens)
|
16
|
+
@markup = markup
|
17
|
+
@context = nil
|
18
|
+
@caption = nil
|
19
|
+
@element_types = []
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def render(context)
|
24
|
+
@context = context
|
25
|
+
scan_attributes(context)
|
26
|
+
application_interaction
|
27
|
+
render_table
|
28
|
+
end
|
29
|
+
|
30
|
+
# Here I want all of the Serving relationships between 2 app components
|
31
|
+
# included or derived.
|
32
|
+
#
|
33
|
+
# attrs:
|
34
|
+
# source_selector: Element selector for source elements
|
35
|
+
# target_selector: Element selector for target elements
|
36
|
+
# relationship_selector
|
37
|
+
def application_interaction
|
38
|
+
model = site.data["archimate_model"]
|
39
|
+
derived_relations_engine = ::Archimate::DerivedRelations.new(model)
|
40
|
+
|
41
|
+
concrete_rels = model.relationships.select { |rel|
|
42
|
+
rel.type == "ServingRelationship" &&
|
43
|
+
rel.source.type == "ApplicationComponent" &&
|
44
|
+
rel.target.type == "ApplicationComponent"
|
45
|
+
}
|
46
|
+
|
47
|
+
derived_rels = derived_relations_engine.derived_relations(
|
48
|
+
model.elements.select { |el| el.type == "ApplicationComponent" },
|
49
|
+
lambda { |rel| rel.weight >= ::Archimate::DataModel::Serving::WEIGHT },
|
50
|
+
lambda { |el| el.type == "ApplicationComponent" },
|
51
|
+
lambda { |el| el.type == "ApplicationComponent" }
|
52
|
+
)
|
53
|
+
|
54
|
+
@all_rels = [concrete_rels, derived_rels].flatten
|
55
|
+
|
56
|
+
@callers = @all_rels.map(&:source).uniq.sort { |a, b| a.name.to_s <=> b.name.to_s }
|
57
|
+
@callees = @all_rels.map(&:target).uniq.sort { |a, b| a.name.to_s <=> b.name.to_s }
|
58
|
+
end
|
59
|
+
|
60
|
+
def matrix_data
|
61
|
+
model = site.data["archimate_model"]
|
62
|
+
derived_relations_engine = ::Archimate::DerivedRelations.new(model)
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
def render_table
|
67
|
+
<<~END
|
68
|
+
<table class="table table-condensed table-hover table-striped">
|
69
|
+
<caption>#{caption}</caption>
|
70
|
+
<thead>
|
71
|
+
<tr>
|
72
|
+
<th> </th>
|
73
|
+
<th class="success" scope="col" colspan="#{@callers.size}">Callers</th>
|
74
|
+
</tr>
|
75
|
+
<tr>
|
76
|
+
<th class="info" scope="col">Callees</th>
|
77
|
+
#{@callers.map { |ac| "<th class=\"success\" scope=\"col\" style=\"text-transform: capitalize\">#{ac.name}</th>" }.join("\n")}
|
78
|
+
</tr>
|
79
|
+
</thead>
|
80
|
+
<tbody>
|
81
|
+
#{render_rows.strip}
|
82
|
+
</tbody>
|
83
|
+
</table>
|
84
|
+
END
|
85
|
+
end
|
86
|
+
|
87
|
+
def render_rows
|
88
|
+
return "<tr><td>No Items</td></tr>" if @callees.empty?
|
89
|
+
@callees.map do |callee|
|
90
|
+
<<~END
|
91
|
+
<tr>
|
92
|
+
<th class="info" scope="row">#{callee.name}</th>
|
93
|
+
#{@callers.map { |caller| cell_content(caller, callee) }.join("")}
|
94
|
+
</tr>
|
95
|
+
END
|
96
|
+
end.join("")
|
97
|
+
end
|
98
|
+
|
99
|
+
def cell_content(caller, callee)
|
100
|
+
rels = @all_rels.select { |rel| rel.source == caller && rel.target == callee }
|
101
|
+
if rels.empty?
|
102
|
+
"<td></td>"
|
103
|
+
else
|
104
|
+
derived = rels.all? { |rel| rel.derived }
|
105
|
+
span_class = derived ? "text-danger" : "text-primary"
|
106
|
+
tooltip = "#{caller.name} → #{}#{callee.name} #{"(derived)" if derived}"
|
107
|
+
cell = <<~END
|
108
|
+
<td>
|
109
|
+
<a href="#" data-toggle="tooltip" data-placement="top" title="#{tooltip}">
|
110
|
+
<span class="#{span_class}">↵ calls</span>
|
111
|
+
</a>
|
112
|
+
</td>
|
113
|
+
END
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def scan_attributes(context)
|
118
|
+
@converter = converter(context)
|
119
|
+
|
120
|
+
# Render any liquid variables
|
121
|
+
markup = Liquid::Template.parse(@markup).render(context)
|
122
|
+
|
123
|
+
# Extract tag attributes
|
124
|
+
attributes = {}
|
125
|
+
markup.scan(Liquid::TagAttributes) do |key, value|
|
126
|
+
attributes[key] = value
|
127
|
+
end
|
128
|
+
@caption = attributes['caption']&.gsub!(/\A"|"\Z/, '')
|
129
|
+
element_type = attributes['type']
|
130
|
+
element_type = element_type.gsub!(/\A"|"\Z/, '') if element_type
|
131
|
+
@element_types = element_type.split(",").map(&:strip)
|
132
|
+
end
|
133
|
+
|
134
|
+
def converter(context)
|
135
|
+
# Gather settings
|
136
|
+
site = context.registers[:site]
|
137
|
+
site.find_converter_instance(::Jekyll::Converters::Markdown)
|
138
|
+
end
|
139
|
+
|
140
|
+
def site
|
141
|
+
@site ||= context.registers[:site]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
Liquid::Template.register_tag("matrix", Jekyll::Archimate::MatrixTag)
|
148
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-archimate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Morga
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -101,7 +101,8 @@ files:
|
|
101
101
|
- lib/jekyll/archimate/archimate_cache.rb
|
102
102
|
- lib/jekyll/archimate/archimate_diagram_tag.rb
|
103
103
|
- lib/jekyll/archimate/archimate_hook.rb
|
104
|
-
- lib/jekyll/archimate/
|
104
|
+
- lib/jekyll/archimate/catalog_tag.rb
|
105
|
+
- lib/jekyll/archimate/matrix_tag.rb
|
105
106
|
- lib/jekyll/archimate/version.rb
|
106
107
|
homepage: https://github.com/mmorga/jekyll-archimate
|
107
108
|
licenses: []
|