Skip to content

Commit

Permalink
Merge pull request #1888 from bichinger/fix-false-hint-translations
Browse files Browse the repository at this point in the history
Fix missing help_text_text translations
  • Loading branch information
tvdeyen authored Jul 14, 2020
2 parents d0457f8 + a5d7b24 commit 896cef6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/sites/_form.html.erb
Original file line number Diff line number Diff line change
@@ -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)&.html_safe %>
<%= f.input :name %>
<%= f.input :public %>
<%= f.input :aliases, hint: resource_handler.help_text_for(name: :aliases), input_html: {rows: 4} %>
Expand Down
4 changes: 2 additions & 2 deletions lib/alchemy/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
#
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions spec/dummy/config/locales/alchemy.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions spec/libraries/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 896cef6

Please sign in to comment.