mermaid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a1adee7a6d24996d2cfe5bdc3e2bf812fd8491d3a15dd900cc32632363beb6ac
4
+ data.tar.gz: a5d9f2ee2722d208202031ab780c9586691a7feec371b500ab60cf899fb34d22
5
+ SHA512:
6
+ metadata.gz: 450ccbce6c9bde4f918fca49c09761950d7f0b6b0f057bee6010a99a85ed43e8e585d6934d1db131b735c6e1c408d75960edab7a961011bf2a4bf19f47ebf2c0
7
+ data.tar.gz: 2c27efa7b199251b37b8d5d9ce52df250922dcb9124ed1a715b1b25a5c5d4da3ef044c48447a1668074f1c370b0e4aafe1a5a97616f4f64d159130cd04298114
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-01-23
4
+
5
+ - Draft release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Abdelkader Boudih
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Mermaid
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mermaid`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_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.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mermaid.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class BaseDiagram < Dry::Struct
5
+ module Types
6
+ include Dry.Types()
7
+ end
8
+
9
+ def to_s
10
+ generate
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class C4Diagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "C4Diagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class ClassDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "ClassDiagram is not implemented yet"
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class ERDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "ERDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class FlowchartDiagram::Link < Dry::Struct
5
+ attribute :from, FlowchartDiagram::Types::String
6
+ attribute :to, FlowchartDiagram::Types::String
7
+ attribute :label, FlowchartDiagram::Types::String.optional.default(nil)
8
+ attribute :type, FlowchartDiagram::Types::String.default('arrow_head')
9
+ .enum('arrow_head',
10
+ 'open_link',
11
+ 'text_link',
12
+ 'dotted',
13
+ 'thick',
14
+ 'invisible'
15
+ )
16
+
17
+ def representation
18
+ case type
19
+ when 'arrow_head'
20
+ if label.nil?
21
+ '-->'
22
+ else
23
+ "-->|#{label_representation}|"
24
+ end
25
+ end
26
+ end
27
+
28
+ def label_representation
29
+ ## if label is unicode return it with quotes
30
+ ## else return it without quotes
31
+ if label.nil?
32
+ ''
33
+ else
34
+ if label.ascii_only?
35
+ label
36
+ else
37
+ "\"#{label}\""
38
+ end
39
+ end
40
+ end
41
+
42
+ def to_s
43
+ [from, representation, to].join
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class FlowchartDiagram::Node < Dry::Struct
5
+ SHAPES = %w(default round stadium subroutine database circle double_circle asymmetric rhombus hexagon parallelogram parallelogram_alt trapezoid trapezoid_alt).freeze
6
+
7
+ SHAPE_FORMATS = {
8
+ 'default' => "%s[%s]", # A[Hard
9
+ 'round' => "%s(%s)", # A(Hard)
10
+ 'stadium' => "%s([%s])", # A([Hard])
11
+ 'subroutine' => "%s[[%s]]", # A([[Hard]])
12
+ 'database' => "%s[(%s)]", # A[(Hard)]
13
+ 'circle' => "%s((%s))", # A((Hard))
14
+ 'double_circle' => "%s(((%s)))", # A(((Hard)))
15
+ 'asymmetric' => "%s>%s]", # A>Hard]
16
+ 'rhombus' => "%s{%s}", # A{Hard}
17
+ 'hexagon' => "%s{{%s}}", # A{{Hard}}
18
+ 'parallelogram' => "%s[/%s/]", # A[/Hard/]
19
+ 'parallelogram_alt' => "%s[\\%s\\]", # A[\Hard\]
20
+ 'trapezoid' => "%s[/%s\\]", # A[/Hard\]
21
+ 'trapezoid_alt' => "%s[\\%s/]" # A[\Hard/]
22
+ }.freeze
23
+
24
+ attribute :id, FlowchartDiagram::Types::String
25
+ attribute :label, FlowchartDiagram::Types::String
26
+ attribute :shape, FlowchartDiagram::Types::String.default('default').enum(*SHAPES)
27
+
28
+ def to_s(show_label = true)
29
+ if show_label
30
+ format(SHAPE_FORMATS[shape], id, label)
31
+ else
32
+ id
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ module Mermaid
2
+ module FlowchartDiagram::Parser
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def parse(input)
9
+ lines = input.split("\n")
10
+ _, direction = lines.shift.split
11
+ nodes = []
12
+ links = []
13
+ lines.each do |line|
14
+ if line =~ /^(\S+)(?:\[(.*)\]|\((.*)\)|\{(.*)\})/
15
+ id = $1
16
+ label = $2 || $3 || $4
17
+ shape = $2 ? 'box' : $3 ? 'round' : 'decision'
18
+ nodes << Node.new(id: id, label: label, shape: shape)
19
+ elsif line =~ /^(\S+)\s+-->(?:\|(.*)\|\s+)?(\S+)/
20
+ from = $1
21
+ label = $2
22
+ to = $3
23
+ links << Link.new(from: from, to: to, label: label)
24
+ end
25
+ end
26
+ new(id: 'parsed', direction: direction, nodes: nodes, links: links)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class FlowchartDiagram < BaseDiagram
5
+ include Parser
6
+ NAME = 'flowchart'
7
+ Direction = Types::String.default('LR').enum('LR', 'RL', 'TB', 'BT')
8
+ attribute :id, Types::String
9
+ attribute :direction, Direction
10
+ attribute :nodes, Types::Array.of(Node)
11
+ attribute :links, Types::Array.of(Link)
12
+
13
+ def generate
14
+ diagram = "#{NAME} #{direction}\n"
15
+ labeled_nodes = Set.new
16
+ links.each do |link|
17
+ from_node = nodes.find { |node| node.id == link.from }
18
+ to_node = nodes.find { |node| node.id == link.to }
19
+ from_node_already_labeled = !labeled_nodes.include?(from_node)
20
+ to_node_already_labeled = !labeled_nodes.include?(to_node)
21
+ diagram += " #{from_node.to_s(from_node_already_labeled)} -->#{link.label ? "|#{link.label}|" : ''} #{to_node.to_s(to_node_already_labeled)}\n"
22
+ labeled_nodes << from_node if from_node.label
23
+ labeled_nodes << to_node if to_node.label
24
+ end
25
+ diagram
26
+ end
27
+
28
+ def inspect
29
+ "#<#{self.class.name}: Nodes: #{nodes.size}, Links: #{links.size}>"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class GanttDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "GanttDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class GitGraphDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "GitGraphDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class InfoFlowDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "InfoFlowDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class MindmapDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "MindmapDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class PieDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "PieDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class QuadrantDiagram < BaseDiagram
5
+
6
+ def initialize(*)
7
+ raise NotImplementedError, "QuadrantDiagram is not implemented yet"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class RequirementDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "RequirementDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class SankeyDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "SankeyDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class SequenceDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "SequenceDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class StateDiagram < BaseDiagram
5
+ def initialize(*)
6
+ raise NotImplementedError, "StateDiagram is not implemented yet"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class UserJourneyDiagram < BaseDiagram
5
+
6
+ def initialize(*)
7
+ raise NotImplementedError, "UserJourneyDiagram is not implemented yet"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mermaid
4
+ class XYDiagram < BaseDiagram
5
+
6
+ def initialize(*)
7
+ raise NotImplementedError, "XYDiagram is not implemented yet"
8
+ end
9
+ end
10
+ end
data/lib/mermaid.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'mermaid/version'
4
+ require 'zeitwerk'
5
+ require 'dry-types'
6
+ require 'dry-struct'
7
+
8
+ loader = Zeitwerk::Loader.for_gem
9
+ loader.inflector.inflect(
10
+ 'er_diagram' => 'ERDiagram',
11
+ 'xy_diagram' => 'XYDiagram'
12
+ )
13
+ loader.setup
14
+
15
+ module Mermaid
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mermaid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Abdelkader Boudih
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-types
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-struct
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ description: Generate Diagrams and Flowcharts with Mermaid
56
+ email:
57
+ - terminale@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - lib/mermaid.rb
67
+ - lib/mermaid/base_diagram.rb
68
+ - lib/mermaid/c4_diagram.rb
69
+ - lib/mermaid/class_diagram.rb
70
+ - lib/mermaid/er_diagram.rb
71
+ - lib/mermaid/flowchart_diagram.rb
72
+ - lib/mermaid/flowchart_diagram/link.rb
73
+ - lib/mermaid/flowchart_diagram/node.rb
74
+ - lib/mermaid/flowchart_diagram/parser.rb
75
+ - lib/mermaid/gantt_diagram.rb
76
+ - lib/mermaid/git_graph_diagram.rb
77
+ - lib/mermaid/info_flow_diagram.rb
78
+ - lib/mermaid/mindmap_diagram.rb
79
+ - lib/mermaid/pie_diagram.rb
80
+ - lib/mermaid/quadrant_diagram.rb
81
+ - lib/mermaid/requirement_diagram.rb
82
+ - lib/mermaid/sankey_diagram.rb
83
+ - lib/mermaid/sequence_diagram.rb
84
+ - lib/mermaid/state_diagram.rb
85
+ - lib/mermaid/user_journey_diagram.rb
86
+ - lib/mermaid/version.rb
87
+ - lib/mermaid/xy_diagram.rb
88
+ homepage: https://github.com/seuros/mermaid-ruby
89
+ licenses:
90
+ - MIT
91
+ metadata:
92
+ homepage_uri: https://github.com/seuros/mermaid-ruby
93
+ source_code_uri: https://github.com/seuros/mermaid-ruby
94
+ changelog_uri: https://github.com/seuros/mermaid-ruby/blob/master/CHANGELOG.md
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.1.0
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.4.10
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Generate Diagrams and Flowcharts with Mermaid
114
+ test_files: []