marmerdo 0.2.2 → 0.3.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 +14 -0
- data/lib/marmerdo/cli.rb +8 -1
- data/lib/marmerdo/domain_diagram_generator.rb +6 -3
- data/lib/marmerdo/markdown_parser.rb +4 -3
- data/lib/marmerdo/node.rb +17 -4
- data/lib/marmerdo/relationship.rb +5 -52
- data/lib/marmerdo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e2b0cdbcedf12f9dfb5911895a513b11eb2ec50ae992662726a42e6850a9b25
|
4
|
+
data.tar.gz: 14eab34bb7327b4577e305875dd8ceb38c4b481d9f430f4c2e46d380b21742c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a03c366404c619416df15a42309b1f35b50aacbc88c2341de3b2a1d19f07a9e1cfb5213504701e383839c408722a922b2ea45faf459ebc4443863d554a972fc7
|
7
|
+
data.tar.gz: f7656b060e14e70a3c084f34a95a3a379175d531693842b0975e3f7f6bc9ea2b804f99459f4e587c5181351c8517e8353e40d2cdaca60921f1fcb179f0d4efbf
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [0.3.1] - 2024-01-07
|
2
|
+
|
3
|
+
- 0.3.0がRubyGemsで反映されないため進めたバージョン。
|
4
|
+
- 変更はなし。
|
5
|
+
|
6
|
+
## [0.3.0] - 2024-01-07
|
7
|
+
|
8
|
+
- Add namespace support.
|
9
|
+
- inheritanceなどのキーワードのかわりに、直接Mermaid記法でRelationを記載するよう変更。
|
10
|
+
|
11
|
+
## [0.2.3] - 2023-12-25
|
12
|
+
|
13
|
+
- Add link_extension option.
|
14
|
+
|
1
15
|
## [0.2.2] - 2023-12-20
|
2
16
|
|
3
17
|
- 相対リンクが`./`から始まらないことがある問題を修正。
|
data/lib/marmerdo/cli.rb
CHANGED
@@ -9,9 +9,12 @@ module Marmerdo
|
|
9
9
|
class ArgumentError < Error; end
|
10
10
|
|
11
11
|
desc "generate SOURCE_GLOB OUTPUT_PATH", "Generate a mermaid diagram from markdown files"
|
12
|
+
option :link_extension, type: :boolean, default: true, desc: "Whether to write the file extension to the link."
|
12
13
|
def generate(source_glob, output_path)
|
13
14
|
raise ArgumentError, "You must provide a source glob and an output file" if source_glob.nil? || output_path.nil?
|
14
15
|
|
16
|
+
enable_link_extension = options[:link_extension]
|
17
|
+
|
15
18
|
nodes = Dir[source_glob].map do |source_path|
|
16
19
|
content = File.read(source_path)
|
17
20
|
node = Marmerdo::MarkdownParser.new(source_path, content).parse
|
@@ -23,7 +26,11 @@ module Marmerdo
|
|
23
26
|
|
24
27
|
puts "Writing domain diagram to #{output_path}."
|
25
28
|
|
26
|
-
domain_diagram = Marmerdo::DomainDiagramGenerator.new(
|
29
|
+
domain_diagram = Marmerdo::DomainDiagramGenerator.new(
|
30
|
+
output_path: output_path,
|
31
|
+
nodes: nodes,
|
32
|
+
enable_link_extension: enable_link_extension
|
33
|
+
).generate
|
27
34
|
output_content = OutputGenerator.new(output_path, domain_diagram).generate
|
28
35
|
File.write(output_path, output_content)
|
29
36
|
|
@@ -1,14 +1,17 @@
|
|
1
1
|
module Marmerdo
|
2
2
|
class DomainDiagramGenerator
|
3
|
-
def initialize(output_path:, nodes:)
|
3
|
+
def initialize(output_path:, nodes:, enable_link_extension:)
|
4
4
|
@output_path = output_path
|
5
5
|
@nodes = nodes
|
6
|
+
@enable_link_extension = enable_link_extension
|
6
7
|
end
|
7
8
|
|
8
9
|
# @return [String] mermaid class diagram
|
9
10
|
def generate
|
10
|
-
classes = @nodes.map(&:
|
11
|
-
links = @nodes.map
|
11
|
+
classes = @nodes.map(&:to_mermaid_str)
|
12
|
+
links = @nodes.map do |node|
|
13
|
+
node.generate_mermaid_link(@output_path, enable_link_extension: @enable_link_extension)
|
14
|
+
end
|
12
15
|
|
13
16
|
relationships = @nodes.flat_map do |node|
|
14
17
|
node.relationships.map do |relationship|
|
@@ -16,6 +16,7 @@ module Marmerdo
|
|
16
16
|
Node.new(
|
17
17
|
path: @path,
|
18
18
|
name: marmerdo_matter["name"] || File.basename(@path, ".*"),
|
19
|
+
namespace: marmerdo_matter["namespace"],
|
19
20
|
relationships: relationships
|
20
21
|
)
|
21
22
|
end
|
@@ -35,9 +36,9 @@ module Marmerdo
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def relationships
|
38
|
-
@relationships ||= marmerdo_matter
|
39
|
-
Relationship.new(
|
40
|
-
end
|
39
|
+
@relationships ||= marmerdo_matter["relationships"]&.map do |relationship|
|
40
|
+
Relationship.new(relationship)
|
41
|
+
end || []
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
data/lib/marmerdo/node.rb
CHANGED
@@ -6,19 +6,32 @@ module Marmerdo
|
|
6
6
|
attr_reader :path
|
7
7
|
# @return [Symbol]
|
8
8
|
attr_reader :name
|
9
|
+
# @return [Symbol, nil]
|
10
|
+
attr_reader :namespace
|
9
11
|
attr_accessor :relationships
|
10
12
|
|
11
|
-
def initialize(path:, name:, relationships:)
|
13
|
+
def initialize(path:, name:, namespace:, relationships:)
|
12
14
|
@path = path
|
13
15
|
@name = name.to_sym
|
16
|
+
@namespace = namespace&.to_sym
|
14
17
|
@relationships = relationships
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
"class #{name}"
|
20
|
+
def to_mermaid_str
|
21
|
+
str = "class #{name}"
|
22
|
+
|
23
|
+
return str if namespace.nil?
|
24
|
+
|
25
|
+
[
|
26
|
+
"namespace #{namespace} {",
|
27
|
+
str,
|
28
|
+
"}"
|
29
|
+
].join("\n")
|
19
30
|
end
|
20
31
|
|
21
|
-
def generate_mermaid_link(output_path)
|
32
|
+
def generate_mermaid_link(output_path, enable_link_extension:)
|
33
|
+
path = enable_link_extension ? @path : Pathname.new(@path).sub_ext("").to_s
|
34
|
+
|
22
35
|
output_dir = Pathname.new(output_path).dirname
|
23
36
|
relative_path = Pathname.new(path).relative_path_from(output_dir).to_s
|
24
37
|
relative_path = "./#{relative_path}" unless relative_path.start_with?("../")
|
@@ -2,62 +2,15 @@ require_relative "error"
|
|
2
2
|
|
3
3
|
module Marmerdo
|
4
4
|
class Relationship
|
5
|
-
|
5
|
+
# @return [String]
|
6
|
+
attr_accessor :str
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
composition
|
10
|
-
aggregation
|
11
|
-
association
|
12
|
-
link_solid
|
13
|
-
dependency
|
14
|
-
realization
|
15
|
-
link_dashed
|
16
|
-
].freeze
|
17
|
-
|
18
|
-
# https://mermaid.js.org/syntax/classDiagram.html#defining-relationship
|
19
|
-
# @return [Symbol]
|
20
|
-
attr_reader :type
|
21
|
-
|
22
|
-
# @return [Array<Symbol>]
|
23
|
-
attr_reader :to
|
24
|
-
|
25
|
-
def self.valid_type?(type)
|
26
|
-
TYPES.include?(type.to_sym)
|
27
|
-
end
|
28
|
-
|
29
|
-
def initialize(type:, to:)
|
30
|
-
@type = type.to_sym
|
31
|
-
@to = if to.is_a?(Array)
|
32
|
-
to.map(&:to_sym)
|
33
|
-
else
|
34
|
-
[to.to_sym]
|
35
|
-
end
|
8
|
+
def initialize(str)
|
9
|
+
@str = str
|
36
10
|
end
|
37
11
|
|
38
12
|
def to_mermaid_str(from)
|
39
|
-
|
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")
|
13
|
+
"#{from} #{str}"
|
61
14
|
end
|
62
15
|
end
|
63
16
|
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.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sijiaoh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: front_matter_parser
|