class Asciidoctor::Standoc::Datamodel::DiagramPreprocessor
Constants
- BLOCK_END_REGEXP
- BLOCK_START_REGEXP
- MARCO_REGEXP
- TEMPLATES_PATH
Public Instance Methods
process(document, reader)
click to toggle source
search document for block `datamodel_diagram`
read include derectives that goes after that in block and transform into plantuml block
# File lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb, line 17 def process(document, reader) input_lines = reader.readlines.to_enum Reader.new(processed_lines(document, input_lines)) end
Private Instance Methods
format_import_directives(imports, include_path)
click to toggle source
# File lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb, line 63 def format_import_directives(imports, include_path) imports .each_with_object({}) do |(import_name, values), res| full_model_name = import_name.split("/").join content = import_format(include_path, import_name, values) res[content["name"] || full_model_name] = content end.compact end
import_format(include_path, import_name, values)
click to toggle source
# File lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb, line 51 def import_format(include_path, import_name, values) include_content = File.read(File.join( include_path, "#{import_name}.yml", )) content = YAML.safe_load(include_content) if values content["skipSection"] = values["skipSection"] end content end
model_type(imports, type)
click to toggle source
# File lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb, line 83 def model_type(imports, type) imports .select do |_name, elem| elem["modelType"] == type end end
parse_datamodel_marco(yaml_path, include_path, document)
click to toggle source
# File lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb, line 35 def parse_datamodel_marco(yaml_path, include_path, document) include_path ||= File.join(File.dirname(yaml_path), "..", "models") include_path = yaml_relative_path(include_path, document) yaml_relative_to_doc_path = yaml_relative_path(yaml_path, document) view_hash = YAML.safe_load(File.read(yaml_relative_to_doc_path)) plantuml_representations(view_hash, yaml_relative_to_doc_path, include_path) end
plantuml_representations(view_hash, view_path, include_path)
click to toggle source
# File lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb, line 90 def plantuml_representations(view_hash, view_path, include_path) yaml_directory = File.dirname(view_path) all_imports = format_import_directives(view_hash["imports"], include_path) prepare_view_hash(view_hash, all_imports) Asciidoctor::Datamodel::PlantumlRenderer .new(view_hash, File.join(yaml_directory, "..")) .render .split("\n") end
prepare_view_hash(view_hash, all_imports)
click to toggle source
# File lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb, line 72 def prepare_view_hash(view_hash, all_imports) view_hash.merge!( "classes" => model_type(all_imports, "class"), "enums" => model_type(all_imports, "enum"), "relations" => view_hash["relations"] || [], "fidelity" => (view_hash["fidelity"] || {}) .merge!("classes" => model_type(all_imports, "class")), ) end
processed_lines(document, input_lines)
click to toggle source
# File lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb, line 24 def processed_lines(document, input_lines) input_lines.each_with_object([]) do |line, result| if match = line.match(MARCO_REGEXP) result .push(*parse_datamodel_marco(match[1], match[2], document)) else result.push(line) end end end
yaml_relative_path(file_path, document)
click to toggle source
# File lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb, line 45 def yaml_relative_path(file_path, document) docfile = document.attributes["docfile"] || "." docfile_directory = File.dirname(docfile) document.path_resolver.system_path(file_path, docfile_directory) end