rails_erd_viewer 0.1.1 → 0.1.2

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.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsErdViewer
4
+ class ApplicationController < ActionController::Base
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsErdViewer
4
+ # RailsErd::ErdController
5
+ class ErdController < RailsErdViewer::ApplicationController
6
+ def index
7
+ @schema = fetch_schema
8
+ end
9
+
10
+ private
11
+
12
+ def fetch_schema
13
+ schema_file_path = Rails.root.join('tmp/application_schema.sql')
14
+
15
+ raise RailsErdViewer::MissingErdSchemaError unless File.exist?(schema_file_path)
16
+
17
+ schema_data = File.read(schema_file_path)
18
+ Base64.encode64(schema_data)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,55 @@
1
+ <html lang="en">
2
+ <head>
3
+ <meta charset="utf-8" />
4
+ <title>Rails ERD Viewer</title>
5
+ <%= javascript_include_tag 'rails_erd_viewer/application' %>
6
+ <%= csrf_meta_tags %>
7
+ </head>
8
+ <body style="margin: 0;">
9
+
10
+ <erd-editor automatic-layout system-dark-mode enable-theme-builder></erd-editor>
11
+ <script>
12
+ const checkModuleSupport = () => 'supports' in HTMLScriptElement
13
+ ? HTMLScriptElement.supports('module')
14
+ : 'noModule' in document.createElement('script');
15
+
16
+ const createScript = (src) => {
17
+ return checkModuleSupport()
18
+ ? import(src)
19
+ : new Promise((resolve, reject) => {
20
+ const script = document.createElement('script');
21
+ script.onload = () => resolve();
22
+ script.onerror = () => reject();
23
+ script.src = src;
24
+ document.body.appendChild(script);
25
+ });
26
+ };
27
+
28
+ const loader = (src, fallback) => {
29
+ return createScript(src).catch(() => createScript(fallback));
30
+ };
31
+
32
+ const sql = atob(`<%= @schema.to_s %>`)
33
+ const editor = document.querySelector('erd-editor');
34
+
35
+ if (checkModuleSupport()) {
36
+ const scripts = [[
37
+ 'https://cdn.jsdelivr.net/npm/@dineug/erd-editor/+esm',
38
+ ], [
39
+ 'https://cdn.jsdelivr.net/npm/@dineug/erd-editor-shiki-worker/+esm',
40
+ ]].map(([src, fallback]) => loader(src, fallback));
41
+
42
+ Promise.all(scripts)
43
+ .then(([{ setGetShikiServiceCallback }, { getShikiService }]) => setGetShikiServiceCallback(getShikiService))
44
+ .then(() => editor.setSchemaSQL(sql));
45
+ } else {
46
+ const scripts = [[
47
+ 'https://cdn.jsdelivr.net/npm/vuerd/dist/vuerd.min.js',
48
+ ]].map(([src, fallback]) => loader(src, fallback));
49
+
50
+ Promise.all(scripts).then(() => editor.loadSQLDDL(sql));
51
+ }
52
+ </script>
53
+
54
+ </body>
55
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ mount RailsErdViewer::Engine => '/erd-viewer', as: 'rails_erd_viewer_engine'
5
+ get 'erd-viewer' => 'rails_erd_viewer/erd#index'
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsErdViewer
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_erd_viewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phelipe Tussolini
@@ -19,11 +19,16 @@ extensions: []
19
19
  extra_rdoc_files:
20
20
  - README.md
21
21
  files:
22
- - CHANGELOG.md
23
- - Gemfile
24
- - LICENSE
25
22
  - README.md
26
- - Rakefile
23
+ - app/assets/javascripts/rails_erd_viewer/application.js
24
+ - app/assets/javascripts/rails_erd_viewer/erd-editor-shiki-worker.esm.js
25
+ - app/assets/javascripts/rails_erd_viewer/erd-editor.esm.js
26
+ - app/assets/javascripts/rails_erd_viewer/panzoom.min.js
27
+ - app/assets/javascripts/rails_erd_viewer/vuerd.min.js
28
+ - app/controllers/rails_erd_viewer/application_controller.rb
29
+ - app/controllers/rails_erd_viewer/erd_controller.rb
30
+ - app/views/rails_erd_viewer/erd/index.html.erb
31
+ - config/routes.rb
27
32
  - lib/rails_erd_viewer.rb
28
33
  - lib/rails_erd_viewer/engine.rb
29
34
  - lib/rails_erd_viewer/railtie.rb
@@ -31,7 +36,6 @@ files:
31
36
  - lib/rails_erd_viewer/version.rb
32
37
  - lib/tasks/db.rake
33
38
  - lib/tasks/generate_erd.rake
34
- - rails_erd_viewer.gemspec
35
39
  homepage: https://github.com/wptussolini/rails-erd
36
40
  licenses:
37
41
  - MIT
data/CHANGELOG.md DELETED
@@ -1,3 +0,0 @@
1
- # Changelog
2
- ## 0.1.1 (18-Nov-24)
3
- * Initial release
data/Gemfile DELETED
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'http://rubygems.org'
4
- gemspec
5
-
6
- group :development, :test do
7
- case rails_version = ENV.fetch('RAILS_VERSION', nil)
8
- when nil
9
- gem 'rails'
10
- when 'edge'
11
- gem 'rails', github: 'rails/rails'
12
- else
13
- gem 'rails', "~> #{rails_version}.0"
14
- end
15
-
16
- gem 'codecov'
17
- gem 'rails-controller-testing'
18
- gem 'rake'
19
- gem 'rspec'
20
- gem 'rspec-rails'
21
- gem 'rubocop'
22
- gem 'rubocop-performance'
23
- gem 'rubocop-rails'
24
- gem 'rubocop-rake'
25
- gem 'rubocop-rspec'
26
- gem 'rubocop-rspec_rails'
27
- gem 'simplecov'
28
- gem 'sprockets-rails'
29
- gem 'sqlite3'
30
- end
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Lokalise team, Ilya Bodrov
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rake'
4
- begin
5
- require 'bundler/setup'
6
- Bundler::GemHelper.install_tasks
7
- rescue LoadError
8
- puts 'although not required, bundler is recommended for running the tests'
9
- end
10
- task default: :spec
11
-
12
- require 'rspec/core/rake_task'
13
- RSpec::Core::RakeTask.new(:spec)
14
-
15
- require 'rubocop/rake_task'
16
- RuboCop::RakeTask.new do |task|
17
- task.requires << 'rubocop-performance'
18
- task.requires << 'rubocop-rspec'
19
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path('lib/rails_erd_viewer/version', __dir__)
4
- Gem::Specification.new do |spec|
5
- spec.name = 'rails_erd_viewer'
6
- spec.version = RailsErdViewer::VERSION
7
- spec.authors = ['Phelipe Tussolini']
8
- spec.email = ['wp.tussolini@gmail.com']
9
- spec.summary = 'A gem to visualize Entity-Relationship Diagram from your rails application.'
10
- spec.description = 'RailsERD Viewer helps developers visualize ERDs, making database relationships clearer.'
11
- spec.homepage = 'https://github.com/wptussolini/rails-erd'
12
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
13
- spec.license = 'MIT'
14
- spec.platform = Gem::Platform::RUBY
15
- spec.required_ruby_version = '>= 2.5.0'
16
- spec.files = Dir['README.md', 'LICENSE',
17
- 'CHANGELOG.md', 'lib/**/*.rb',
18
- 'lib/**/*.rake',
19
- 'rails_erd_viewer.gemspec', '.github/*.md',
20
- 'Gemfile', 'Rakefile']
21
- spec.extra_rdoc_files = ['README.md']
22
- spec.metadata['rubygems_mfa_required'] = 'true'
23
- end