rails-mermaid_erd 0.4.2 → 0.5.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 +4 -4
- data/README.md +13 -3
- data/lib/rails-mermaid_erd/builder.rb +5 -3
- data/lib/rails-mermaid_erd/version.rb +1 -1
- data/lib/templates/index.html.erb +62 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27a3b346f33bfc899475fc0c00f6c512bf8ba1e1e028c3518c24496e5eb3e016
|
4
|
+
data.tar.gz: d0317f33acd321ed8b9a3b2bc5bb818b02593bba6c002925973f629fbfc110c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09d7df6654042f5a327a18cf9ddfb7f4c43bb41717ff3ed937cb5dc95aed8d502d983000c2b31970370e2532fba62acda6506d9ff5dd0c073ae1f1db1fc7705c'
|
7
|
+
data.tar.gz: 020f4ba3e58cfbbe8cd77a28414138073ba248eccfdef2ec3a55cf19a068ffa8913f1dc526bc2c5b7a23e35faca7265db4bbce34dee86d4f2e3f78feff737129
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ The editor is a single HTML file, so the entire editor can be shared.
|
|
21
21
|
Add this line to your application's Gemfile:
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
gem "rails-mermaid_erd", group: :development
|
24
|
+
gem "rails-mermaid_erd", group: :development, require: false
|
25
25
|
```
|
26
26
|
|
27
27
|
And then execute:
|
@@ -30,6 +30,16 @@ And then execute:
|
|
30
30
|
$ bundle install
|
31
31
|
```
|
32
32
|
|
33
|
+
Add this line to your application's Rakefile:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
begin
|
37
|
+
require "rails-mermaid_erd"
|
38
|
+
rescue LoadError
|
39
|
+
# Do nothing.
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
33
43
|
## Usage
|
34
44
|
|
35
45
|
Run rake task `mermaid_erd` will generate `<app_root>/mermaid_erd/index.html`.
|
@@ -48,8 +58,8 @@ This file is not required for Git management, so you can add it to `.gitignore`
|
|
48
58
|
mermaid_erd
|
49
59
|
```
|
50
60
|
|
51
|
-
`<app_root>/mermaid_erd/index.html` is single HTML file.
|
52
|
-
If you share this file, it can be used by those who do not have Ruby on Rails environment. Or, you can upload the file to a web server and share it with the same URL.
|
61
|
+
`<app_root>/mermaid_erd/index.html` is a single HTML file.
|
62
|
+
If you share this file, it can be used by those who do not have a Ruby on Rails environment. Or, you can upload the file to a web server and share it with the same URL.
|
53
63
|
|
54
64
|
It would be very smart to generate it automatically using CI.
|
55
65
|
|
@@ -14,8 +14,10 @@ class RailsMermaidErd::Builder
|
|
14
14
|
next if defined_model.name.include?("HABTM_")
|
15
15
|
next if defined_model.table_name.blank?
|
16
16
|
|
17
|
+
table_name = defined_model.table_name
|
17
18
|
model = {
|
18
|
-
TableName:
|
19
|
+
TableName: table_name,
|
20
|
+
TableComment: ::ActiveRecord::Base.connection.table_comment(table_name.to_sym) || "",
|
19
21
|
ModelName: defined_model.name,
|
20
22
|
IsModelExist: true,
|
21
23
|
Columns: []
|
@@ -91,12 +93,12 @@ class RailsMermaidErd::Builder
|
|
91
93
|
|
92
94
|
reverse_relation = result[:Relations].find { |r| r[:RightModelName] == model[:ModelName] && r[:LeftModelName] == reflection_model_name }
|
93
95
|
if reverse_relation
|
94
|
-
if (::Rails.application.config.active_record.belongs_to_required_by_default && reflection.options[:optional]) || (!::Rails.application.config.active_record.belongs_to_required_by_default && !reflection.options[:
|
96
|
+
if (::Rails.application.config.active_record.belongs_to_required_by_default && reflection.options[:optional]) || (!::Rails.application.config.active_record.belongs_to_required_by_default && !reflection.options[:required])
|
95
97
|
reverse_relation[:LeftValue] = "|o"
|
96
98
|
end
|
97
99
|
reverse_relation[:Comment] = "#{reverse_relation[:Comment]}, BT:#{reflection.name}"
|
98
100
|
else
|
99
|
-
right_value = if (::Rails.application.config.active_record.belongs_to_required_by_default && reflection.options[:optional]) || (!::Rails.application.config.active_record.belongs_to_required_by_default && !reflection.options[:
|
101
|
+
right_value = if (::Rails.application.config.active_record.belongs_to_required_by_default && reflection.options[:optional]) || (!::Rails.application.config.active_record.belongs_to_required_by_default && !reflection.options[:required])
|
100
102
|
"o|"
|
101
103
|
else
|
102
104
|
"||"
|
@@ -228,7 +228,27 @@
|
|
228
228
|
<button @click="tab = 'erd'" :class="`text-xs py-1 px-2 rounded hover:bg-white focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-900 ${tab === 'erd' ? 'bg-white text-gray-900' : 'bg-gray-400 text-gray-900'}`">{{i18n[language]["tab"]["erd"]}}</button>
|
229
229
|
<button @click="tab = 'code'" :class="`text-xs py-1 px-2 rounded hover:bg-white focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-900 ${tab === 'code' ? 'bg-white text-gray-900' : 'bg-gray-400 text-gray-900'}`">{{i18n[language]["tab"]["code"]}}</button>
|
230
230
|
</div>
|
231
|
-
<div v-show="tab === 'erd'" class="px-4 w-full min-h-[calc(100vh-56px-32px-56px)]
|
231
|
+
<div v-show="tab === 'erd'" class="px-4 w-full min-h-[calc(100vh-56px-32px-56px)] relative overflow-hidden">
|
232
|
+
<div class="absolute inset-0" :style="zoomStyle" ref="zoomArea">
|
233
|
+
<div id="preview"></div>
|
234
|
+
</div>
|
235
|
+
|
236
|
+
<div class="absolute bottom-0 right-0 p-4 space-x-4 flex">
|
237
|
+
<div class="space-x-2 flex items-center">
|
238
|
+
<button class="text-xs py-1 px-2 rounded hover:bg-white focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-900 bg-gray-400 text-gray-900" @click="zoomIn">+</button>
|
239
|
+
<button class="text-xs py-1 px-2 rounded hover:bg-white focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-900 bg-gray-400 text-gray-900" @click="zoomOut">-</button>
|
240
|
+
</div>
|
241
|
+
<div class="flex items-center space-x-2">
|
242
|
+
<button class="text-xs py-1 px-2 rounded hover:bg-white focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-900 bg-gray-400 text-gray-900" @click="moveLeft">←</button>
|
243
|
+
<div class="flex flex-col space-y-8">
|
244
|
+
<button class="text-xs py-1 px-2 rounded hover:bg-white focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-900 bg-gray-400 text-gray-900" @click="moveUp">↑</button>
|
245
|
+
<button class="text-xs py-1 px-2 rounded hover:bg-white focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-900 bg-gray-400 text-gray-900" @click="moveDown">↓</button>
|
246
|
+
</div>
|
247
|
+
<button class="text-xs py-1 px-2 rounded hover:bg-white focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-900 bg-gray-400 text-gray-900" @click="moveRight">→</button>
|
248
|
+
</div>
|
249
|
+
</div>
|
250
|
+
|
251
|
+
</div>
|
232
252
|
<textarea v-show="tab === 'code'" class="px-4 bg-gray-900 text-gray-300 font-mono w-full text-xs min-h-[calc(100vh-56px-32px-56px)] border-0 focus:ring-0" readonly v-model="mermaidErd"></textarea>
|
233
253
|
</div>
|
234
254
|
</div>
|
@@ -338,6 +358,37 @@
|
|
338
358
|
const isShowComment = Vue.ref(false)
|
339
359
|
const isHideColumns = Vue.ref(false)
|
340
360
|
|
361
|
+
const scale = Vue.ref(1)
|
362
|
+
const posX = Vue.ref(0)
|
363
|
+
const posY = Vue.ref(0)
|
364
|
+
const zoomArea = Vue.ref(null)
|
365
|
+
|
366
|
+
const zoomStyle = Vue.computed(() => {
|
367
|
+
return {
|
368
|
+
transform: `scale(${scale.value}) translate(${posX.value}px, ${posY.value}px)`,
|
369
|
+
transformOrigin: 'top left'
|
370
|
+
}
|
371
|
+
})
|
372
|
+
|
373
|
+
const zoomIn = () => {
|
374
|
+
scale.value = Math.min(scale.value + 0.1, 3)
|
375
|
+
}
|
376
|
+
|
377
|
+
const zoomOut = () => {
|
378
|
+
scale.value = Math.max(scale.value - 0.1, 0.5)
|
379
|
+
}
|
380
|
+
|
381
|
+
const move = (dx, dy) => {
|
382
|
+
const step = 10 / scale.value
|
383
|
+
posX.value += dx * step
|
384
|
+
posY.value += dy * step
|
385
|
+
}
|
386
|
+
|
387
|
+
const moveUp = () => move(0, -10)
|
388
|
+
const moveDown = () => move(0, 10)
|
389
|
+
const moveLeft = () => move(-10, 0)
|
390
|
+
const moveRight = () => move(10, 0)
|
391
|
+
|
341
392
|
const restoreFromHash = () => {
|
342
393
|
try {
|
343
394
|
const h = location.hash.substr(1, location.hash.length)
|
@@ -427,6 +478,7 @@
|
|
427
478
|
|
428
479
|
filteredData.value.Models.forEach(model => {
|
429
480
|
lines.push(` %% table name: ${model.TableName}`)
|
481
|
+
lines.push(` %% table comment: ${model.TableComment}`)
|
430
482
|
lines.push(` ${model.ModelName.replace(/:/g, '-')} {`)
|
431
483
|
|
432
484
|
if (!isHideColumns.value) {
|
@@ -473,7 +525,7 @@
|
|
473
525
|
const filterText = Vue.ref('')
|
474
526
|
|
475
527
|
const reRender = () => {
|
476
|
-
mermaid.initialize({theme: 'dark'})
|
528
|
+
mermaid.initialize({theme: 'dark', maxTextSize: 99999999})
|
477
529
|
mermaid.init()
|
478
530
|
graph.value = mermaid.mermaidAPI.render("mermaid-erd", mermaidErd.value);
|
479
531
|
document.getElementById('preview').innerHTML = graph.value
|
@@ -597,6 +649,14 @@
|
|
597
649
|
tab,
|
598
650
|
updateHash,
|
599
651
|
isHideColumns,
|
652
|
+
zoomStyle,
|
653
|
+
zoomArea,
|
654
|
+
zoomIn,
|
655
|
+
zoomOut,
|
656
|
+
moveUp,
|
657
|
+
moveDown,
|
658
|
+
moveLeft,
|
659
|
+
moveRight
|
600
660
|
}
|
601
661
|
}
|
602
662
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-mermaid_erd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 肥溜め
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
|
-
rubygems_version: 3.
|
134
|
+
rubygems_version: 3.5.22
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Generate Mermaid ERD for Ruby on Rails
|