marmerdo 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/lib/marmerdo/cli.rb +16 -9
- data/lib/marmerdo/domain_diagram_generator.rb +5 -2
- data/lib/marmerdo/markdown_parser.rb +4 -4
- data/lib/marmerdo/node.rb +14 -6
- data/lib/marmerdo/output_generator.rb +56 -0
- data/lib/marmerdo/relationship.rb +29 -23
- data/lib/marmerdo/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69476fe32f74a4b4a7081f5bf65ce187026b8e3afa257ad7b0c5b3622153bba4
|
4
|
+
data.tar.gz: 7a0c231bdd97fb8a7c68e003d618421b8b5839ddce6cd8672e1f895478f0dd74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08cb33a93c568b1e799aed8824a371d5716b521a6e8437727a304f59f1b806a1b6d56a7bef96cee1d6344fe8558b0db6fc86a5dd7fc002ce764ea54e48b5f9e9'
|
7
|
+
data.tar.gz: 24c9314b548c06974be900afbc46d0e7ab2a98c9a01b36dd936fddff2a676c87f64da9e80a0a87d1a98a153973b504a9bf98fb74eb1374f1dfc49da7c4550aae
|
data/CHANGELOG.md
CHANGED
data/lib/marmerdo/cli.rb
CHANGED
@@ -2,25 +2,32 @@ require "thor"
|
|
2
2
|
require_relative "error"
|
3
3
|
require_relative "markdown_parser"
|
4
4
|
require_relative "domain_diagram_generator"
|
5
|
+
require_relative "output_generator"
|
5
6
|
|
6
7
|
module Marmerdo
|
7
8
|
class Cli < Thor
|
8
9
|
class ArgumentError < Error; end
|
9
10
|
|
10
|
-
desc "generate SOURCE_GLOB
|
11
|
-
def generate(source_glob,
|
12
|
-
raise ArgumentError, "You must provide a source glob and an output file" if source_glob.nil? ||
|
11
|
+
desc "generate SOURCE_GLOB OUTPUT_PATH", "Generate a mermaid diagram from markdown files"
|
12
|
+
def generate(source_glob, output_path)
|
13
|
+
raise ArgumentError, "You must provide a source glob and an output file" if source_glob.nil? || output_path.nil?
|
13
14
|
|
14
15
|
nodes = Dir[source_glob].map do |source_path|
|
15
|
-
puts "Parsing #{source_path}"
|
16
|
-
name = File.basename(source_path, ".*")
|
17
16
|
content = File.read(source_path)
|
18
|
-
Marmerdo::MarkdownParser.new(
|
17
|
+
node = Marmerdo::MarkdownParser.new(source_path, content).parse
|
18
|
+
|
19
|
+
puts "Loaded #{node.name}." if node
|
20
|
+
|
21
|
+
node
|
19
22
|
end.compact
|
20
23
|
|
21
|
-
puts "Writing diagram to #{
|
22
|
-
|
23
|
-
|
24
|
+
puts "Writing domain diagram to #{output_path}."
|
25
|
+
|
26
|
+
domain_diagram = Marmerdo::DomainDiagramGenerator.new(output_path: output_path, nodes: nodes).generate
|
27
|
+
output_content = OutputGenerator.new(output_path, domain_diagram).generate
|
28
|
+
File.write(output_path, output_content)
|
29
|
+
|
30
|
+
puts "Done!"
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|
@@ -1,22 +1,25 @@
|
|
1
1
|
module Marmerdo
|
2
2
|
class DomainDiagramGenerator
|
3
|
-
def initialize(nodes)
|
3
|
+
def initialize(output_path:, nodes:)
|
4
|
+
@output_path = output_path
|
4
5
|
@nodes = nodes
|
5
6
|
end
|
6
7
|
|
7
8
|
# @return [String] mermaid class diagram
|
8
9
|
def generate
|
9
10
|
classes = @nodes.map(&:to_mermaid_line)
|
11
|
+
links = @nodes.map { |node| node.generate_mermaid_link(@output_path) }
|
10
12
|
|
11
13
|
relationships = @nodes.flat_map do |node|
|
12
14
|
node.relationships.map do |relationship|
|
13
|
-
relationship.
|
15
|
+
relationship.to_mermaid_str(node.name)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
[
|
18
20
|
"classDiagram",
|
19
21
|
classes,
|
22
|
+
links,
|
20
23
|
relationships
|
21
24
|
].flatten.join("\n")
|
22
25
|
end
|
@@ -4,8 +4,8 @@ require_relative "relationship"
|
|
4
4
|
|
5
5
|
module Marmerdo
|
6
6
|
class MarkdownParser
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(path, content)
|
8
|
+
@path = path
|
9
9
|
@content = content
|
10
10
|
end
|
11
11
|
|
@@ -14,8 +14,8 @@ module Marmerdo
|
|
14
14
|
return nil unless marmerdo_file?
|
15
15
|
|
16
16
|
Node.new(
|
17
|
-
|
18
|
-
|
17
|
+
path: @path,
|
18
|
+
name: marmerdo_matter["name"] || File.basename(@path, ".*"),
|
19
19
|
relationships: relationships
|
20
20
|
)
|
21
21
|
end
|
data/lib/marmerdo/node.rb
CHANGED
@@ -1,19 +1,27 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
module Marmerdo
|
2
4
|
class Node
|
3
|
-
# @return [Symbol
|
5
|
+
# @return [Symbol]
|
6
|
+
attr_reader :path
|
7
|
+
# @return [Symbol]
|
4
8
|
attr_reader :name
|
5
|
-
# @return [Symbol, nil]
|
6
|
-
attr_reader :namespace
|
7
9
|
attr_accessor :relationships
|
8
10
|
|
9
|
-
def initialize(
|
10
|
-
@
|
11
|
-
@
|
11
|
+
def initialize(path:, name:, relationships:)
|
12
|
+
@path = path
|
13
|
+
@name = name.to_sym
|
12
14
|
@relationships = relationships
|
13
15
|
end
|
14
16
|
|
15
17
|
def to_mermaid_line
|
16
18
|
"class #{name}"
|
17
19
|
end
|
20
|
+
|
21
|
+
def generate_mermaid_link(output_path)
|
22
|
+
output_dir = Pathname.new(output_path).dirname
|
23
|
+
relative_path = Pathname.new(path).relative_path_from(output_dir).to_s
|
24
|
+
"link #{name} \"#{relative_path}\""
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "error"
|
2
|
+
|
3
|
+
module Marmerdo
|
4
|
+
# This class generates a markdown or mermaid file from a mermaid diagram.
|
5
|
+
class OutputGenerator
|
6
|
+
WARNING_COMMENT = "This file was generated by Marmerdo. Do not edit it manually.".freeze
|
7
|
+
|
8
|
+
class UnknownOutputExtensionError < Error
|
9
|
+
def initialize(output_extension)
|
10
|
+
super("Unknown output extension #{output_extension}.\nSupported filetypes are markdown and mermaid.")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(output_path, domain_diagram)
|
15
|
+
@output_path = output_path
|
16
|
+
@domain_diagram = domain_diagram
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String]
|
20
|
+
def generate
|
21
|
+
case output_filetype
|
22
|
+
when :markdown
|
23
|
+
[
|
24
|
+
"<!-- #{WARNING_COMMENT} -->",
|
25
|
+
"",
|
26
|
+
"```mermaid",
|
27
|
+
@domain_diagram,
|
28
|
+
"```"
|
29
|
+
].join("\n")
|
30
|
+
when :mermaid
|
31
|
+
[
|
32
|
+
"%% #{WARNING_COMMENT}",
|
33
|
+
"",
|
34
|
+
@domain_diagram
|
35
|
+
].join("\n")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def output_extension
|
42
|
+
File.extname(@output_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def output_filetype
|
46
|
+
case output_extension
|
47
|
+
when ".markdown", ".md"
|
48
|
+
:markdown
|
49
|
+
when ".mermaid", ".mmd"
|
50
|
+
:mermaid
|
51
|
+
else
|
52
|
+
raise UnknownOutputExtensionError, output_extension
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -19,7 +19,7 @@ module Marmerdo
|
|
19
19
|
# @return [Symbol]
|
20
20
|
attr_reader :type
|
21
21
|
|
22
|
-
# @return [Symbol]
|
22
|
+
# @return [Array<Symbol>]
|
23
23
|
attr_reader :to
|
24
24
|
|
25
25
|
def self.valid_type?(type)
|
@@ -28,30 +28,36 @@ module Marmerdo
|
|
28
28
|
|
29
29
|
def initialize(type:, to:)
|
30
30
|
@type = type.to_sym
|
31
|
-
@to = to.
|
31
|
+
@to = if to.is_a?(Array)
|
32
|
+
to.map(&:to_sym)
|
33
|
+
else
|
34
|
+
[to.to_sym]
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
38
|
+
def to_mermaid_str(from)
|
39
|
+
to.map do |t|
|
40
|
+
case type
|
41
|
+
when :inheritance
|
42
|
+
"#{t} <|-- #{from}"
|
43
|
+
when :composition
|
44
|
+
"#{t} *-- #{from}"
|
45
|
+
when :aggregation
|
46
|
+
"#{t} o-- #{from}"
|
47
|
+
when :association
|
48
|
+
"#{from} --> #{t}"
|
49
|
+
when :link_solid
|
50
|
+
"#{from} -- #{t}"
|
51
|
+
when :dependency
|
52
|
+
"#{from} ..> #{t}"
|
53
|
+
when :realization
|
54
|
+
"#{from} ..|> #{t}"
|
55
|
+
when :link_dashed
|
56
|
+
"#{from} .. #{t}"
|
57
|
+
else
|
58
|
+
raise UnknownRelationshipType
|
59
|
+
end
|
60
|
+
end.join("\n")
|
55
61
|
end
|
56
62
|
end
|
57
63
|
end
|
data/lib/marmerdo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marmerdo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sijiaoh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: front_matter_parser
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/marmerdo/error.rb
|
62
62
|
- lib/marmerdo/markdown_parser.rb
|
63
63
|
- lib/marmerdo/node.rb
|
64
|
+
- lib/marmerdo/output_generator.rb
|
64
65
|
- lib/marmerdo/relationship.rb
|
65
66
|
- lib/marmerdo/version.rb
|
66
67
|
- marmerdo.gemspec
|