marmerdo 0.0.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a85efc4c3e7d9abe175ad1ae273f069b58c0408484290794a3e48d710ab9b2c
4
- data.tar.gz: 0fe01c14fb23b07262b6263b3199efa10418a866b09a1e5ca7626d0381b644b4
3
+ metadata.gz: 8428d0053c598bd51bf6c6adad87c8039e8609f10abb36b2a1b1851cbf73550b
4
+ data.tar.gz: cd7a5dd6f1450b262921c65400047112c830a6f77260505558bdb40598a7a5d5
5
5
  SHA512:
6
- metadata.gz: 54e4fa9d7fdc2c383b74030f1a268ad9674fa8cd2182078e7878856665857a7c0a332b557d62980a8de9a17e251a96a8d7dae204b8122af9a7f9952830a561ad
7
- data.tar.gz: 0ab9af832c42fee5f0847195ce57595a171e257e8fd22505f46125531c64032c43ff3b1e189882ba2d6d7de0d8223e16aa5c2a24078816ddef22ab58523ddf42
6
+ metadata.gz: bfc719b5f4b91525bb768e0bf055cb81af55a8c79db3ca21c550ff177eeafb26f833bb4ca3c652fb65fa0f98ee5d38da2bb12d2c2f5fc8f7a9c410a239bba4b3
7
+ data.tar.gz: 5f287f8fbc54dc4e820af010fe8fd6c3026c0cb558587401425353e3b4f9d0eab56d22b37b93fdb0d371221196b4ae1db2dc975ab590313ea3bd2c679e9b3abf
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.6
3
+ NewCops: enable
3
4
 
4
5
  Style/StringLiterals:
5
6
  Enabled: true
data/CHANGELOG.md CHANGED
@@ -1 +1,9 @@
1
- ## [Unreleased]
1
+ ## [0.2.0] - 2023-12-18
2
+
3
+ - 警告コメントを追加。
4
+ - Markdowサポートを追加。
5
+ - classにMarkdownファイルへのリンクを追加。
6
+
7
+ ## [0.1.0] - 2023-12-18
8
+
9
+ - 最低限の機能を備えた初期リリース。
data/CODE_OF_CONDUCT.md CHANGED
@@ -39,7 +39,7 @@ This Code of Conduct applies within all community spaces, and also applies when
39
39
 
40
40
  ## Enforcement
41
41
 
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at sijiaoh@outlook.com. All complaints will be reviewed and investigated promptly and fairly.
43
43
 
44
44
  All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
45
 
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2023 TODO: Write your name
3
+ Copyright (c) 2023 sijiaoh
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -4,15 +4,13 @@
4
4
 
5
5
  ## Installation
6
6
 
7
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
-
9
7
  Install the gem and add to the application's Gemfile by executing:
10
8
 
11
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
9
+ $ bundle add marmerdo
12
10
 
13
11
  If bundler is not being used to manage dependencies, install the gem by executing:
14
12
 
15
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
13
+ $ gem install marmerdo
16
14
 
17
15
  ## Usage
18
16
 
data/lib/marmerdo/cli.rb CHANGED
@@ -1,10 +1,33 @@
1
1
  require "thor"
2
+ require_relative "error"
3
+ require_relative "markdown_parser"
4
+ require_relative "domain_diagram_generator"
5
+ require_relative "output_generator"
2
6
 
3
7
  module Marmerdo
4
8
  class Cli < Thor
5
- desc "generate", "Generate domain diagram from markdown docs."
6
- def generate
7
- puts "Hello World!"
9
+ class ArgumentError < Error; end
10
+
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?
14
+
15
+ nodes = Dir[source_glob].map do |source_path|
16
+ content = File.read(source_path)
17
+ node = Marmerdo::MarkdownParser.new(source_path, content).parse
18
+
19
+ puts "Loaded #{node.name}." if node
20
+
21
+ node
22
+ end.compact
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!"
8
31
  end
9
32
  end
10
33
  end
@@ -1,12 +1,14 @@
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|
@@ -17,6 +19,7 @@ module Marmerdo
17
19
  [
18
20
  "classDiagram",
19
21
  classes,
22
+ links,
20
23
  relationships
21
24
  ].flatten.join("\n")
22
25
  end
@@ -0,0 +1,3 @@
1
+ module Marmerdo
2
+ class Error < StandardError; end
3
+ end
@@ -4,28 +4,38 @@ require_relative "relationship"
4
4
 
5
5
  module Marmerdo
6
6
  class MarkdownParser
7
- def initialize(name, content)
8
- @name = name
7
+ def initialize(path, content)
8
+ @path = path
9
9
  @content = content
10
10
  end
11
11
 
12
- # @return [Node]
12
+ # @return [Node, nil] the parsed node or nil if the file has no marmerdo front matter.
13
13
  def parse
14
+ return nil unless marmerdo_file?
15
+
14
16
  Node.new(
15
- name: front_matter["name"] || @name,
16
- namespace: front_matter["namespace"],
17
+ path: @path,
18
+ name: marmerdo_matter["name"] || File.basename(@path, ".*"),
17
19
  relationships: relationships
18
20
  )
19
21
  end
20
22
 
21
23
  private
22
24
 
25
+ def marmerdo_file?
26
+ front_matter.key?("marmerdo")
27
+ end
28
+
23
29
  def front_matter
24
- @front_matter ||= FrontMatterParser::Parser.new(:md).call(@content).front_matter
30
+ @front_matter ||= FrontMatterParser::Parser.new(:md).call(@content).front_matter || {}
31
+ end
32
+
33
+ def marmerdo_matter
34
+ @marmerdo_matter ||= front_matter["marmerdo"] || {}
25
35
  end
26
36
 
27
37
  def relationships
28
- @relationships ||= front_matter.filter { |k, _| Relationship::TYPES.include?(k.to_sym) }.map do |type, to|
38
+ @relationships ||= marmerdo_matter.filter { |k| Relationship::TYPES.include?(k.to_sym) }.map do |type, to|
29
39
  Relationship.new(type: type, to: to)
30
40
  end
31
41
  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, nil]
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(name:, namespace:, relationships:)
10
- @name = name&.to_sym
11
- @namespace = namespace&.to_sym
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
@@ -1,3 +1,5 @@
1
+ require_relative "error"
2
+
1
3
  module Marmerdo
2
4
  class Relationship
3
5
  class UnknownRelationshipType < Error; end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Marmerdo
4
- VERSION = "0.0.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/marmerdo.rb CHANGED
@@ -4,6 +4,5 @@ require_relative "marmerdo/version"
4
4
  require_relative "marmerdo/cli"
5
5
 
6
6
  module Marmerdo
7
- class Error < StandardError; end
8
7
  # Your code goes here...
9
8
  end
data/marmerdo.gemspec CHANGED
@@ -36,4 +36,6 @@ Gem::Specification.new do |spec|
36
36
 
37
37
  # For more information and examples about making a new gem, check out our
38
38
  # guide at: https://bundler.io/guides/creating_gem.html
39
+
40
+ spec.metadata["rubygems_mfa_required"] = "true"
39
41
  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.0.0
4
+ version: 0.2.0
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-17 00:00:00.000000000 Z
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
@@ -58,8 +58,10 @@ files:
58
58
  - lib/marmerdo.rb
59
59
  - lib/marmerdo/cli.rb
60
60
  - lib/marmerdo/domain_diagram_generator.rb
61
+ - lib/marmerdo/error.rb
61
62
  - lib/marmerdo/markdown_parser.rb
62
63
  - lib/marmerdo/node.rb
64
+ - lib/marmerdo/output_generator.rb
63
65
  - lib/marmerdo/relationship.rb
64
66
  - lib/marmerdo/version.rb
65
67
  - marmerdo.gemspec
@@ -71,6 +73,7 @@ metadata:
71
73
  homepage_uri: https://github.com/sijiaoh/marmerdo
72
74
  source_code_uri: https://github.com/sijiaoh/marmerdo
73
75
  changelog_uri: https://github.com/sijiaoh/marmerdo/blob/main/CHANGELOG.md
76
+ rubygems_mfa_required: 'true'
74
77
  post_install_message:
75
78
  rdoc_options: []
76
79
  require_paths: