From 80eda0e9400ed032a17a05fe7382c0aaeb994bd5 Mon Sep 17 00:00:00 2001 From: Koki Oyatsu Date: Tue, 23 Jul 2024 22:17:28 +0900 Subject: [PATCH] Add (head|body) custom script settings. --- .devcontainer/devcontainer.json | 14 ++++---- Gemfile | 8 ++--- Gemfile.lock | 32 +------------------ .../dashboard_controller.rb | 3 +- app/models/setting.rb | 5 ++- .../dashboard/index.html.erb | 4 ++- app/views/layouts/application.html.erb | 4 +++ config/locales/simple_form.en.yml | 5 +++ config/locales/simple_form.ja.yml | 2 ++ 9 files changed, 32 insertions(+), 45 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 00eb496..e3ab3d6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -42,13 +42,16 @@ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "eslint.workingDirectories": [{ "mode": "auto" }], - "rubyLsp.rubyVersionManager": "none" + "rubyLsp.erbSupport": false, + "rubyLsp.rubyVersionManager": "none", + "[ruby]": { + "editor.defaultFormatter": "Shopify.ruby-lsp", + "editor.semanticHighlighting.enabled": true + } }, - // Add the IDs of extensions you want installed when the container is created. "extensions": [ + // Add the IDs of extensions you want installed when the container is created. "cschleiden.vscode-github-actions", - "msjsdiag.debugger-for-chrome", - "firefox-devtools.vscode-firefox-debug", "editorconfig.editorconfig", "vscode-icons-team.vscode-icons", "Shopify.ruby-lsp", @@ -56,8 +59,7 @@ "esbenp.prettier-vscode", "stylelint.vscode-stylelint", "mikestead.dotenv", - "mhutchie.git-graph", - "eamodio.gitlens" + "mhutchie.git-graph" ] } } diff --git a/Gemfile b/Gemfile index 9e1f3d1..227f9d8 100644 --- a/Gemfile +++ b/Gemfile @@ -37,7 +37,7 @@ group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console # Ruby fast debugger - base + CLI (https://github.com/deivid-rodriguez/byebug) - gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem 'byebug', platforms: %i[mri mingw x64_mingw] end group :development do @@ -51,8 +51,6 @@ group :development do gem 'spring' # Makes spring watch files using the listen gem. (https://github.com/jonleighton/spring-watcher-listen) gem 'spring-watcher-listen', '~> 2.0.0' - # Solargraph for Ruby (http://solargraph.org) - gem 'solargraph' # Automatic Ruby code style checking tool. (https://github.com/rubocop-hq/rubocop) gem 'rubocop' # An IRB alternative and runtime developer console (http://pryrepl.org) @@ -85,7 +83,7 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem # Timezone Data for TZInfo (http://tzinfo.github.io) -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] # Flexible authentication solution for Rails with Warden (https://github.com/plataformatec/devise) gem 'devise' @@ -120,5 +118,5 @@ gem 'omniauth-google-oauth2', '~> 0.8' gem 'config' -gem 'kaminari', '~> 1.2' gem 'gravatar_image_tag' +gem 'kaminari', '~> 1.2' diff --git a/Gemfile.lock b/Gemfile.lock index 3f6683c..fa2163f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,10 +83,8 @@ GEM annotate_gem (0.0.14) bundler (>= 1.1) ast (2.4.2) - backport (1.2.0) base64 (0.2.0) bcrypt (3.1.20) - benchmark (0.3.0) bigdecimal (3.1.8) bindex (0.8.1) builder (3.3.0) @@ -119,9 +117,7 @@ GEM warden (~> 1.2.3) devise-i18n (1.12.1) devise (>= 4.9.0) - diff-lcs (1.5.1) drb (2.2.1) - e2mmap (0.1.0) erubi (1.13.0) faraday (2.10.0) faraday-net_http (>= 2.0, < 3.2) @@ -142,7 +138,6 @@ GEM irb (1.14.0) rdoc (>= 4.0.0) reline (>= 0.4.2) - jaro_winkler (1.6.0) jbuilder (2.12.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) @@ -161,10 +156,6 @@ GEM activerecord kaminari-core (= 1.2.2) kaminari-core (1.2.2) - kramdown (2.4.0) - rexml - kramdown-parser-gfm (1.1.0) - kramdown (~> 2.0) language_server-protocol (3.17.0.3) launchy (3.0.1) addressable (~> 2.8) @@ -246,7 +237,7 @@ GEM method_source (~> 1.0) psych (5.1.2) stringio - public_suffix (6.0.0) + public_suffix (6.0.1) puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) @@ -302,7 +293,6 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.11.1) ffi (~> 1.0) - rbs (2.8.4) rdoc (6.7.0) psych (>= 4.0.0) regexp_parser (2.9.2) @@ -313,8 +303,6 @@ GEM responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - reverse_markdown (2.1.1) - nokogiri rexml (3.3.2) strscan rolify (6.0.1) @@ -358,22 +346,6 @@ GEM snaky_hash (2.0.1) hashie version_gem (~> 1.1, >= 1.1.1) - solargraph (0.50.0) - backport (~> 1.2) - benchmark - bundler (~> 2.0) - diff-lcs (~> 1.4) - e2mmap - jaro_winkler (~> 1.5) - kramdown (~> 2.3) - kramdown-parser-gfm (~> 1.1) - parser (~> 3.0) - rbs (~> 2.0) - reverse_markdown (~> 2.0) - rubocop (~> 1.38) - thor (~> 1.0) - tilt (~> 2.0) - yard (~> 0.9, >= 0.9.24) spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) @@ -421,7 +393,6 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - yard (0.9.36) zeitwerk (2.6.16) PLATFORMS @@ -460,7 +431,6 @@ DEPENDENCIES selenium-webdriver sequenced simple_form - solargraph spring spring-watcher-listen (~> 2.0.0) sqlite3 (~> 1.4) diff --git a/app/controllers/application_settings/dashboard_controller.rb b/app/controllers/application_settings/dashboard_controller.rb index 31f29bd..66d35d1 100644 --- a/app/controllers/application_settings/dashboard_controller.rb +++ b/app/controllers/application_settings/dashboard_controller.rb @@ -13,7 +13,8 @@ def update end private + def settings_params - params.require(:settings).permit(:site_title) + params.require(:settings).permit(:site_title, :head_custom_script, :body_custom_script) end end diff --git a/app/models/setting.rb b/app/models/setting.rb index 460f225..0ab2542 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -11,7 +11,7 @@ # RailsSettings Model class Setting < RailsSettings::Base - cache_prefix { "v1" } + cache_prefix { 'v2' } # Define your fields # field :host, type: :string, default: "http://localhost:3000" @@ -24,4 +24,7 @@ class Setting < RailsSettings::Base field :installed, type: :boolean, default: false field :site_title, type: :string, default: '' + + field :head_custom_script, type: :string, default: '' + field :body_custom_script, type: :string, default: '' end diff --git a/app/views/application_settings/dashboard/index.html.erb b/app/views/application_settings/dashboard/index.html.erb index d6c38f2..e506c64 100644 --- a/app/views/application_settings/dashboard/index.html.erb +++ b/app/views/application_settings/dashboard/index.html.erb @@ -13,6 +13,8 @@
<%= simple_form_for :settings, url: application_settings_path do |f| %> <%= f.input :site_title, as: :string, input_html: { value: Setting.site_title } %> + <%= f.input :head_custom_script, as: :text, input_html: { value: Setting.head_custom_script, rows: 5 } %> + <%= f.input :body_custom_script, as: :text, input_html: { value: Setting.body_custom_script, rows: 5 } %>
<%= f.submit nil, class: 'btn btn-primary' %>
@@ -22,4 +24,4 @@
- \ No newline at end of file + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c084a92..7ffe34a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,6 +5,8 @@ <% custom_title << @project.title if @project.present? %> <% custom_title << Setting.site_title if Setting.site_title.present? %> + <%= raw(Setting.head_custom_script) if Setting.head_custom_script.present? %> + <%# %> <% if custom_title.present? %> @@ -30,5 +32,7 @@ <% end %> <%= yield %> + + <%= raw(Setting.body_custom_script) if Setting.body_custom_script.present? %> diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 2374383..de01851 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -10,6 +10,11 @@ en: # html: '*' error_notification: default_message: "Please review the problems below:" + labels: + settings: + site_title: 'サイト名' + head_custom_script: ' custom script' + body_custom_script: ' custom script' # Examples # labels: # defaults: diff --git a/config/locales/simple_form.ja.yml b/config/locales/simple_form.ja.yml index 1150ca1..3edaf20 100644 --- a/config/locales/simple_form.ja.yml +++ b/config/locales/simple_form.ja.yml @@ -13,6 +13,8 @@ ja: labels: settings: site_title: 'サイト名' + head_custom_script: ' カスタムスクリプト' + body_custom_script: ' カスタムスクリプト' # Examples # labels: # defaults: