Class: Jekyll::Archimate::ArchimateHook
- Inherits:
-
Object
- Object
- Jekyll::Archimate::ArchimateHook
- Defined in:
- lib/jekyll/archimate/archimate_hook.rb
Overview
Configuration variables: clean: clean destination directories before rendering layout: layout to use for the archimate navigator
Instance Attribute Summary collapse
-
#archimate_file ⇒ Object
readonly
Returns the value of attribute archimate_file.
-
#clean_generated_dirs ⇒ Object
readonly
Returns the value of attribute clean_generated_dirs.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #catalog_element(el) ⇒ Object
- #export_catalogs ⇒ Object
- #export_svgs ⇒ Object
- #export_unified_json ⇒ Object
- #generate ⇒ Object
-
#initialize(site, archimate_file) ⇒ ArchimateHook
constructor
A new instance of ArchimateHook.
- #svg_dest_dir ⇒ Object
- #svgs_need_export? ⇒ Boolean
Constructor Details
#initialize(site, archimate_file) ⇒ ArchimateHook
Returns a new instance of ArchimateHook.
182 183 184 185 186 187 188 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 182 def initialize(site, archimate_file) @site = site @archimate_file = archimate_file @clean_generated_dirs = @site.config.fetch('clean', false) @model = ArchimateCache.load_model(archimate_file.sub(site.source, "")) @site.data["archimate_model"] = @model end |
Instance Attribute Details
#archimate_file ⇒ Object (readonly)
Returns the value of attribute archimate_file.
180 181 182 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 180 def archimate_file @archimate_file end |
#clean_generated_dirs ⇒ Object (readonly)
Returns the value of attribute clean_generated_dirs.
177 178 179 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 177 def clean_generated_dirs @clean_generated_dirs end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
179 180 181 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 179 def model @model end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
178 179 180 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 178 def site @site end |
Instance Method Details
#catalog_element(el) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 239 def catalog_element(el) [:id, :name, :documentation, :type, :properties].each_with_object({}) do |sym, hash| hash[sym] = el.send(sym) end { "id" => el.id, "name" => el.name.to_s, "documentation" => el.documentation&.to_s, "type" => el.type, "properties" => el.properties.each_with_object({}) do |property, hash| hash[property.key.to_s] = property.value.to_s end } end |
#export_catalogs ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 220 def export_catalogs data = File.join(site.source, "_data") Dir.mkdir(data) unless Dir.exist?(data) archimate = File.join(data, "archimate") Dir.mkdir(archimate) unless Dir.exist?(archimate) catalog = File.join(archimate, "catalog.yml") File.open(catalog, "wb") do |file| file.write( model .elements .chunk { |el| el.type } .each_with_object({}) { |(type, els), hash| hash[type] = els.map { |el| catalog_element(el) } } .to_yaml ) end end |
#export_svgs ⇒ Object
213 214 215 216 217 218 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 213 def export_svgs return unless svgs_need_export? model.diagrams.each do |diagram| SvgFile.new(File.join(svg_dest_dir, "#{diagram.id}.svg")).write(diagram) end end |
#export_unified_json ⇒ Object
196 197 198 199 200 201 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 196 def export_unified_json dest_file = File.join(File.dirname(archimate_file), 'index.json') dest_mtime = File.exist?(dest_file) && File.mtime(dest_file) return unless !dest_mtime || File.mtime(archimate_file) > dest_mtime JsonFile.new(dest_file).write(UnifiedModel.new(model)) end |
#generate ⇒ Object
190 191 192 193 194 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 190 def generate export_svgs export_unified_json export_catalogs end |
#svg_dest_dir ⇒ Object
203 204 205 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 203 def svg_dest_dir @svg_dest_dir ||= File.join(File.dirname(archimate_file), 'svg') end |
#svgs_need_export? ⇒ Boolean
207 208 209 210 211 |
# File 'lib/jekyll/archimate/archimate_hook.rb', line 207 def svgs_need_export? Dir.mkdir(svg_dest_dir) unless Dir.exist?(svg_dest_dir) last_svg_mtime = Dir.glob(File.join(svg_dest_dir, "*.svg")).map { |svg_file| File.mtime(svg_file) }.max !last_svg_mtime || File.mtime(archimate_file) > last_svg_mtime end |