jekyll-archimate 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Archimate
5
+ # Persists an ArchiMate diagram to a file
6
+ class SvgFile
7
+ def initialize(filename)
8
+ @filename = filename
9
+ end
10
+
11
+ def write(diagram)
12
+ File.open(@filename, "wb") do |svg_file|
13
+ svg_file.write(::Archimate::Svg::Diagram.new(diagram).to_svg)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Archimate
5
+ # This is the top level object used by the web Archimate Navigator
6
+ class UnifiedModel
7
+ attr_reader :model
8
+
9
+ def initialize(model)
10
+ @model = model
11
+ end
12
+
13
+ def to_h
14
+ {
15
+ entities: entities,
16
+ folders: folders
17
+ }
18
+ end
19
+
20
+ def elements
21
+ model.elements.map { |element| ElementEntity.new(element, model: model).to_h }
22
+ end
23
+
24
+ def relationships
25
+ model.relationships.map { |relationship| RelationshipEntity.new(relationship, model: model).to_h }
26
+ end
27
+
28
+ def diagrams
29
+ model.diagrams.map { |diagram| DiagramEntity.new(diagram).to_h }
30
+ end
31
+
32
+ def entities
33
+ [ModelEntity.new(model).to_h].concat(
34
+ elements
35
+ ).concat(
36
+ relationships
37
+ ).concat(
38
+ diagrams
39
+ )
40
+ end
41
+
42
+ def folders
43
+ [Folder.new(model.organizations.last).to_h]
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  module Archimate
3
- VERSION = "0.2.2"
5
+ VERSION = "0.2.3"
4
6
  end
5
7
  end
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.2
4
+ version: 0.2.3
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-25 00:00:00.000000000 Z
11
+ date: 2017-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -101,9 +101,21 @@ files:
101
101
  - lib/jekyll/archimate/application_interaction_matrix_tag.rb
102
102
  - lib/jekyll/archimate/archimate_cache.rb
103
103
  - lib/jekyll/archimate/archimate_diagram_tag.rb
104
- - lib/jekyll/archimate/archimate_hook.rb
104
+ - lib/jekyll/archimate/archimate_generator.rb
105
+ - lib/jekyll/archimate/archimate_index_generator.rb
106
+ - lib/jekyll/archimate/archimate_svg_generator.rb
105
107
  - lib/jekyll/archimate/catalog_tag.rb
108
+ - lib/jekyll/archimate/conditional_file.rb
109
+ - lib/jekyll/archimate/diagram_entity.rb
110
+ - lib/jekyll/archimate/element_entity.rb
111
+ - lib/jekyll/archimate/entity_base.rb
112
+ - lib/jekyll/archimate/folder.rb
113
+ - lib/jekyll/archimate/json_file.rb
106
114
  - lib/jekyll/archimate/matrix_tag.rb
115
+ - lib/jekyll/archimate/model_entity.rb
116
+ - lib/jekyll/archimate/relationship_entity.rb
117
+ - lib/jekyll/archimate/svg_file.rb
118
+ - lib/jekyll/archimate/unified_model.rb
107
119
  - lib/jekyll/archimate/version.rb
108
120
  homepage: https://github.com/mmorga/jekyll-archimate
109
121
  licenses: []
@@ -1,265 +0,0 @@
1
- # frozen_string_literal: true
2
- require "archimate"
3
- require "yaml"
4
-
5
- module Jekyll
6
- module Archimate
7
- # Removes all keys that have null or empty values
8
- def self.hash_purge(hash)
9
- hash.delete_if { |_, value| !value || (value.is_a?(String) && value.empty?) }
10
- end
11
-
12
- # Base class for ArchiMate Entities: Model, Diagram, Element, Relationship
13
- class EntityBase
14
- attr_reader :entity
15
- attr_reader :model
16
-
17
- def initialize(entity, model: nil)
18
- @entity = entity
19
- @model = model
20
- end
21
-
22
- def to_h
23
- Archimate.hash_purge(attr_hash)
24
- end
25
-
26
- def attr_hash
27
- {
28
- id: entity.id,
29
- name: entity.name,
30
- documentation: entity.documentation&.to_h,
31
- properties: entity.properties.map(&:to_h)
32
- }
33
- end
34
- end
35
-
36
- # Represents the overall model
37
- class ModelEntity < EntityBase
38
- def attr_hash
39
- super.merge(
40
- type: "Model"
41
- )
42
- end
43
- end
44
-
45
- # Represents an ArchiMate Element
46
- class ElementEntity < EntityBase
47
- def attr_hash
48
- super.merge(
49
- type: "Element",
50
- element_type: entity.type,
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)
53
- )
54
- end
55
- end
56
-
57
- # Represents an ArchiMate Relationship
58
- class RelationshipEntity < EntityBase
59
- def attr_hash
60
- super.merge(
61
- type: "Relationship",
62
- relationship_type: entity.type,
63
- source: entity.source&.id,
64
- target: entity.target&.id,
65
- views: model.diagrams.select { |dia| dia.relationship_ids.include?(entity.id) }.map(&:id)
66
- )
67
- end
68
- end
69
-
70
- # Represents an ArchiMate Diagram
71
- class DiagramEntity < EntityBase
72
- def attr_hash
73
- super.merge(
74
- type: "Diagram",
75
- path: "svg/#{entity.id}.svg",
76
- viewpoint: entity.viewpoint,
77
- elements: entity.elements.map(&:id),
78
- relationships: entity.relationships.map(&:id),
79
- views: []
80
- )
81
- end
82
- end
83
-
84
- # Represents an ArchiMate Organizing Folder
85
- class Folder
86
- attr_reader :folder
87
-
88
- def initialize(folder)
89
- @folder = folder
90
- end
91
-
92
- # This item check is necessary because some models seem to contain
93
- # an item that is a string rather than an element of some sort.
94
- def items
95
- folder.items.map { |item| item.is_a?(String) ? item : item.id }
96
- end
97
-
98
- def to_h
99
- Archimate.hash_purge(
100
- id: folder.id,
101
- name: folder.name.to_s,
102
- folders: folder.organizations.map { |child| Folder.new(child).to_h },
103
- diagrams: items
104
- )
105
- end
106
- end
107
-
108
- # This is the top level object used by the web Archimate Navigator
109
- class UnifiedModel
110
- attr_reader :model
111
-
112
- def initialize(model)
113
- @model = model
114
- end
115
-
116
- def to_h
117
- {
118
- entities: entities,
119
- folders: folders
120
- }
121
- end
122
-
123
- def elements
124
- model.elements.map { |element| ElementEntity.new(element, model: model).to_h }
125
- end
126
-
127
- def relationships
128
- model.relationships.map { |relationship| RelationshipEntity.new(relationship, model: model).to_h }
129
- end
130
-
131
- def diagrams
132
- model.diagrams.map { |diagram| DiagramEntity.new(diagram).to_h }
133
- end
134
-
135
- def entities
136
- [ModelEntity.new(model).to_h].concat(
137
- elements).concat(
138
- relationships).concat(
139
- diagrams)
140
- end
141
-
142
- def folders
143
- [Folder.new(model.organizations.last).to_h]
144
- end
145
- end
146
-
147
- # Writes any object that can be hashified (with to_h) to a JSON file
148
- class JsonFile
149
- def initialize(filename)
150
- @filename = filename
151
- end
152
-
153
- def write(obj)
154
- File.open(@filename, "wb") do |file|
155
- file.write(JSON.generate(obj.to_h))
156
- end
157
- end
158
- end
159
-
160
- # Persists an ArchiMate diagram to a file
161
- class SvgFile
162
- def initialize(filename)
163
- @filename = filename
164
- end
165
-
166
- def write(diagram)
167
- File.open(@filename, "wb") do |svg_file|
168
- svg_file.write(::Archimate::Svg::Diagram.new(diagram).to_svg)
169
- end
170
- end
171
- end
172
-
173
- # Configuration variables:
174
- # clean: clean destination directories before rendering
175
- # layout: layout to use for the archimate navigator
176
- class ArchimateHook
177
- attr_reader :clean_generated_dirs
178
- attr_reader :site
179
- attr_reader :model
180
- attr_reader :archimate_file
181
-
182
- def initialize(site, archimate_file)
183
- @site = site
184
- @archimate_file = archimate_file
185
- @clean_generated_dirs = @site.config.fetch('clean', false)
186
- @model = ArchimateCache.load_model(archimate_file.sub(site.source, ""))
187
- @site.data["archimate_model"] = @model
188
- end
189
-
190
- def generate
191
- export_svgs
192
- export_unified_json
193
- export_catalogs
194
- end
195
-
196
- def export_unified_json
197
- dest_file = File.join(File.dirname(archimate_file), 'index.json')
198
- dest_mtime = File.exist?(dest_file) && File.mtime(dest_file)
199
- return unless !dest_mtime || File.mtime(archimate_file) > dest_mtime
200
- JsonFile.new(dest_file).write(UnifiedModel.new(model))
201
- end
202
-
203
- def svg_dest_dir
204
- @svg_dest_dir ||= File.join(File.dirname(archimate_file), 'svg')
205
- end
206
-
207
- def svgs_need_export?
208
- Dir.mkdir(svg_dest_dir) unless Dir.exist?(svg_dest_dir)
209
- last_svg_mtime = Dir.glob(File.join(svg_dest_dir, "*.svg")).map { |svg_file| File.mtime(svg_file) }.max
210
- !last_svg_mtime || File.mtime(archimate_file) > last_svg_mtime
211
- end
212
-
213
- def export_svgs
214
- return unless svgs_need_export?
215
- model.diagrams.each do |diagram|
216
- SvgFile.new(File.join(svg_dest_dir, "#{diagram.id}.svg")).write(diagram)
217
- end
218
- end
219
-
220
- def export_catalogs
221
- data = File.join(site.source, "_data")
222
- Dir.mkdir(data) unless Dir.exist?(data)
223
- archimate = File.join(data, "archimate")
224
- Dir.mkdir(archimate) unless Dir.exist?(archimate)
225
- catalog = File.join(archimate, "catalog.yml")
226
- File.open(catalog, "wb") do |file|
227
- file.write(
228
- model
229
- .elements
230
- .chunk { |el| el.type }
231
- .each_with_object({}) { |(type, els), hash|
232
- hash[type] = els.map { |el| catalog_element(el) }
233
- }
234
- .to_yaml
235
- )
236
- end
237
- end
238
-
239
- def catalog_element(el)
240
- [:id, :name, :documentation, :type, :properties].each_with_object({}) do |sym, hash|
241
- hash[sym] = el.send(sym)
242
- end
243
- {
244
- "id" => el.id,
245
- "name" => el.name.to_s,
246
- "documentation" => el.documentation&.to_s,
247
- "type" => el.type,
248
- "properties" => el.properties.each_with_object({}) do |property, hash|
249
- hash[property.key.to_s] = property.value.to_s
250
- end
251
- }
252
- end
253
- end
254
- end
255
- end
256
-
257
- Jekyll::Hooks.register :site, :pre_render do |site|
258
- Jekyll.logger.info "ArchiMate Generator..."
259
- Dir.glob("#{site.source}/**/*.archimate").each do |archimate_file|
260
- unless archimate_file.start_with?(site.dest) || archimate_file.sub(site.source, "").start_with?("/_")
261
- Jekyll.logger.info " processing: #{archimate_file}"
262
- Jekyll::Archimate::ArchimateHook.new(site, archimate_file).generate
263
- end
264
- end
265
- end