rails-mermaid_erd 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- 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: cce6becd48bcb6564461895181cb51023a6a88618acc1ee65996caa9c9892e5e
|
4
|
+
data.tar.gz: 566638d6ec6644c215aea40b22a28e384a1f1bf74976495fd986c8d0dfd1cd1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f4b5b920839d132162f6677e6618025cabd1f847f77c8aa009b4fb90ec9a20f56ed71ff2c0a0d73998e85bf71942a56b42f4c853266e7ea19ea0233f5e74e49
|
7
|
+
data.tar.gz: 03a23a3621647de5bfa82576434b1f21da48f7711ab8c7b1d9b3a1a8e68ae4ad42d196312ec3cd2f9e427e1755ec3cb5b50bb96b8312ed8deacd5df1c6935d0b
|
data/README.md
CHANGED
@@ -48,8 +48,8 @@ This file is not required for Git management, so you can add it to `.gitignore`
|
|
48
48
|
mermaid_erd
|
49
49
|
```
|
50
50
|
|
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.
|
51
|
+
`<app_root>/mermaid_erd/index.html` is a single HTML file.
|
52
|
+
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
53
|
|
54
54
|
It would be very smart to generate it automatically using CI.
|
55
55
|
|
@@ -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.0
|
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-06-25 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.4.10
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: Generate Mermaid ERD for Ruby on Rails
|