marmerdo 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75e6024f088234f63afcedd06d33ca186beb1b13f0736b39f015027341930b7a
4
- data.tar.gz: 6366471bac61e54a3203fa00f9076902e1312314668052f2382e3c13ceef19a3
3
+ metadata.gz: 8e2b0cdbcedf12f9dfb5911895a513b11eb2ec50ae992662726a42e6850a9b25
4
+ data.tar.gz: 14eab34bb7327b4577e305875dd8ceb38c4b481d9f430f4c2e46d380b21742c0
5
5
  SHA512:
6
- metadata.gz: d8c2114f14742c25fde0c4b8c455a843fbd28af00cad65a1a45a09d57f74575d116366daa2a05367a32f720edd31f153eacf403b718de74c35fef9df780784bc
7
- data.tar.gz: 8c042444b75adff10d17cc72d4c882ccb70cf1274a7ba0bbba1aa263b27a1fe4dde4863a1d325a72308f5b2be0015bf1ca9a22b6fc6549a8db735b67754e5b2a
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(output_path: output_path, nodes: nodes).generate
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(&:to_mermaid_line)
11
- links = @nodes.map { |node| node.generate_mermaid_link(@output_path) }
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.filter { |k| Relationship::TYPES.include?(k.to_sym) }.map do |type, to|
39
- Relationship.new(type: type, to: to)
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 to_mermaid_line
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
- class UnknownRelationshipType < Error; end
5
+ # @return [String]
6
+ attr_accessor :str
6
7
 
7
- TYPES = %i[
8
- inheritance
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
- 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")
13
+ "#{from} #{str}"
61
14
  end
62
15
  end
63
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Marmerdo
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.1"
5
5
  end
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.2.2
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: 2023-12-20 00:00:00.000000000 Z
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