From 638737d98976e3c636b69c6b609c839dcfd16a0e Mon Sep 17 00:00:00 2001 From: Niklas Bichinger Date: Wed, 8 Jul 2020 13:21:56 +0200 Subject: [PATCH 1/5] only html_safe() when hint translation is present --- app/views/alchemy/admin/sites/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/alchemy/admin/sites/_form.html.erb b/app/views/alchemy/admin/sites/_form.html.erb index 69f26e3315..c153fa955d 100644 --- a/app/views/alchemy/admin/sites/_form.html.erb +++ b/app/views/alchemy/admin/sites/_form.html.erb @@ -1,5 +1,5 @@ <%= alchemy_form_for site, url: alchemy.admin_sites_path(site, search_filter_params) do |f| %> - <%= f.input :host, hint: resource_handler.help_text_for(name: :host).html_safe %> + <%= f.input :host, hint: resource_handler.help_text_for(name: :host).try(:html_safe) %> <%= f.input :name %> <%= f.input :public %> <%= f.input :aliases, hint: resource_handler.help_text_for(name: :aliases), input_html: {rows: 4} %> From b0b5b9d3d25aa33003984283671403084b42a251 Mon Sep 17 00:00:00 2001 From: Niklas Bichinger Date: Wed, 8 Jul 2020 13:23:34 +0200 Subject: [PATCH 2/5] allow "hint: false" in elements.yml --- app/helpers/alchemy/admin/base_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/alchemy/admin/base_helper.rb b/app/helpers/alchemy/admin/base_helper.rb index 617390178f..81ac45204f 100644 --- a/app/helpers/alchemy/admin/base_helper.rb +++ b/app/helpers/alchemy/admin/base_helper.rb @@ -376,7 +376,7 @@ def render_hint_for(element) content_tag :span, class: "hint-with-icon" do render_icon("question-circle") + - content_tag(:span, element.hint.html_safe, class: "hint-bubble") + content_tag(:span, element.hint.try(:html_safe), class: "hint-bubble") end end From dccd6e9b92f434b73fed9e7f72567844d77379c8 Mon Sep 17 00:00:00 2001 From: Niklas Bichinger Date: Sun, 12 Jul 2020 00:44:45 +0200 Subject: [PATCH 3/5] Revert "allow "hint: false" in elements.yml" This reverts commit b0b5b9d3d25aa33003984283671403084b42a251. --- app/helpers/alchemy/admin/base_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/alchemy/admin/base_helper.rb b/app/helpers/alchemy/admin/base_helper.rb index 81ac45204f..617390178f 100644 --- a/app/helpers/alchemy/admin/base_helper.rb +++ b/app/helpers/alchemy/admin/base_helper.rb @@ -376,7 +376,7 @@ def render_hint_for(element) content_tag :span, class: "hint-with-icon" do render_icon("question-circle") + - content_tag(:span, element.hint.try(:html_safe), class: "hint-bubble") + content_tag(:span, element.hint.html_safe, class: "hint-bubble") end end From 1aa06ac539be2d065e6605c00f4970c76d020c84 Mon Sep 17 00:00:00 2001 From: Niklas Bichinger Date: Sun, 12 Jul 2020 01:53:03 +0200 Subject: [PATCH 4/5] return nil (instead of false) for missing help text translations --- app/views/alchemy/admin/sites/_form.html.erb | 2 +- lib/alchemy/resource.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/alchemy/admin/sites/_form.html.erb b/app/views/alchemy/admin/sites/_form.html.erb index c153fa955d..e02c5801e5 100644 --- a/app/views/alchemy/admin/sites/_form.html.erb +++ b/app/views/alchemy/admin/sites/_form.html.erb @@ -1,5 +1,5 @@ <%= alchemy_form_for site, url: alchemy.admin_sites_path(site, search_filter_params) do |f| %> - <%= f.input :host, hint: resource_handler.help_text_for(name: :host).try(:html_safe) %> + <%= f.input :host, hint: resource_handler.help_text_for(name: :host)&.html_safe %> <%= f.input :name %> <%= f.input :public %> <%= f.input :aliases, hint: resource_handler.help_text_for(name: :aliases), input_html: {rows: 4} %> diff --git a/lib/alchemy/resource.rb b/lib/alchemy/resource.rb index c7326b54d0..3f5ea1cc92 100644 --- a/lib/alchemy/resource.rb +++ b/lib/alchemy/resource.rb @@ -210,7 +210,7 @@ def engine_name @module_definition && @module_definition["engine_name"] end - # Returns a help text for resource's form + # Returns a help text for resource's form or nil if no help text is available # # === Example: # @@ -223,7 +223,7 @@ def engine_name def help_text_for(attribute) ::I18n.translate!(attribute[:name], scope: [:alchemy, :resource_help_texts, resource_name]) rescue ::I18n::MissingTranslationData - false + nil end # Return attributes that should be viewable but not editable. From a5d7b2476f8318a8014cc8522d3fdf66ab74deac Mon Sep 17 00:00:00 2001 From: Niklas Bichinger Date: Tue, 14 Jul 2020 13:50:10 +0200 Subject: [PATCH 5/5] added tests --- spec/dummy/config/locales/alchemy.en.yml | 3 +++ spec/libraries/resource_spec.rb | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/spec/dummy/config/locales/alchemy.en.yml b/spec/dummy/config/locales/alchemy.en.yml index b9c3fa300a..adb8b12518 100644 --- a/spec/dummy/config/locales/alchemy.en.yml +++ b/spec/dummy/config/locales/alchemy.en.yml @@ -26,3 +26,6 @@ en: essence_text: This content type (Essence) represents a simple line of text default_content_texts: welcome: Welcome to my site + resource_help_texts: + party: + name: Party diff --git a/spec/libraries/resource_spec.rb b/spec/libraries/resource_spec.rb index 3f95ebbf44..1114721219 100644 --- a/spec/libraries/resource_spec.rb +++ b/spec/libraries/resource_spec.rb @@ -395,5 +395,14 @@ module Alchemy expect(resource.in_engine?).to eq(true) end end + + describe "#help_text_for" do + it "should return a text as string for an attribute" do + expect(resource.help_text_for(name: :name)).to eq("Party") + end + it "should return nil for a nonexistent attribute" do + expect(resource.help_text_for(name: :nonexistent_attribute_dummy)).to be_nil + end + end end end