8000 Add a new config option by shifakhan · Pull Request #117 · koedame/rails-mermaid_erd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add a new config option #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/example.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# result path
# default "mermaid_erd/index.html"
result_path: doc/erd.html
all_models_selected: false
1 change: 1 addition & 0 deletions lib/rails-mermaid_erd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def configuration
version = VERSION
app_name = ::Rails.application.class.try(:parent_name) || ::Rails.application.class.try(:module_parent_name)
logo = File.read(File.expand_path("./assets/logo.svg", __dir__))
configuration = RailsMermaidErd.configuration
erb = ERB.new(File.read(File.expand_path("./templates/index.html.erb", __dir__)))
result_html = erb.result(binding)

Expand Down
13 changes: 11 additions & 2 deletions lib/rails-mermaid_erd/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
require "yaml"

class RailsMermaidErd::Configuration
attr_accessor :result_path
attr_accessor :result_path, :all_models_selected

def initialize
config = {
result_path: "mermaid_erd/index.html"
result_path: "mermaid_erd/index.html",
all_models_selected: true,
}

config_file = Rails.root.join("config/mermaid_erd.yml")
Expand All @@ -14,6 +15,14 @@ def initialize
config = config.merge(custom_config)
end

@all_models_selected = config[:all_models_selected]
@result_path = config[:result_path]
end

def to_json
{
allModelsSelected: @all_models_selected,
resultPath: @result_path
}.to_json
end
end
10 changes: 7 additions & 3 deletions lib/templates/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
<script src="https://unpkg.com/vue@3.2.40/dist/vue.global.js"></script>

<script>window.SCHEMA_DATA=<%= result.to_json %></script>
<script>window.CONFIG_DATA=<%= configuration.to_json %></script>
<script>
window.i18n = {
en: {
Expand Down Expand Up @@ -351,6 +352,7 @@
...window.SCHEMA_DATA,
Models: window.SCHEMA_DATA.Models.sort((a, b) => a.ModelName < b.ModelName ? -1 : 1)
}
const configData = { ...window.CONFIG_DATA }
const selectModels = Vue.ref([])
const isPreviewRelations = Vue.ref(false)
const isShowRelationComment = Vue.ref(false)
Expand Down Expand Up @@ -406,9 +408,11 @@

const reset = () => {
selectModels.value = []
schemaData.Models.forEach((model) => {
selectModels.value.push(model.ModelName)
})
if (configData.allModelsSelected) {
schemaData.Models.forEach((model) => {
selectModels.value.push(model.ModelName)
})
}
isPreviewRelations.value = false
isShowRelationComment.value = false
isShowKey.value = false
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/files/configurations/valid.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# result path
# default "mermaid_erd/index.html"
result_path: doc/erd.html
all_models_selected: false
2 changes: 2 additions & 0 deletions spec/rails-mermaid_erd/configration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
context "when the config file does not exist" do
it "return default config value" do
expect(configuration.result_path).to eq("mermaid_erd/index.html")
expect(configuration.all_models_selected).to eq(true)
end
end

Expand All @@ -18,6 +19,7 @@
end
it "return overwrite config value" do
expect(configuration.result_path).to eq("doc/erd.html")
expect(configuration.all_models_selected).to eq(false)
end
end
end
0