lib/js_dependency/mermaid/root.rb in js_dependency-0.2.3.1 vs lib/js_dependency/mermaid/root.rb in js_dependency-0.3.0

- old
+ new

@@ -13,12 +13,23 @@ def add(parent, child) @list << NodesLink.new(parent, child) end - def export(name_level: 1) + def export(name_level: 1, src_path: nil) + nodes_links = if src_path + src_pathname = Pathname.new(src_path).realpath + @list.map do |nodes_link| + NodesLink.new(nodes_link.parent.exist? ? nodes_link.parent.relative_path_from(src_pathname.to_s) : nodes_link.parent.to_s, + nodes_link.child.exist? ? nodes_link.child.relative_path_from(src_pathname.to_s) : nodes_link.child.to_s) + end + else + @list + end str = "flowchart #{orientation}\n" - str + @list.uniq { |link| "#{link.parent}__#{link.child}" }.sort_by { |link| "#{link.parent}__#{link.child}" }.map do |link| + str + nodes_links.uniq do |link| + "#{link.parent}__#{link.child}" + end.sort_by { |link| "#{link.parent}__#{link.child}" }.map do |link| "#{link.parent_module_name(name_level)} --> #{link.child_module_name(name_level)}" end.join("\n") end end end