diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0db4f40..4007d3a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -81,18 +81,23 @@ module ApplicationHelper end.join.html_safe end - def image_button_to(name, image = nil, options = nil, html_options = {}) - html_options[:class] = class_names(html_options[:class], 'button') - image_element_to(:button, name, image, options, html_options) - end + [:button_to, :link_to, :link_to_unless_current].each do |method_name| + class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 + def image_#{method_name}(name, image = nil, options = nil, html_options = {}, &block) + name = svg_tag("pictograms/\#{image}") + name if image - def image_link_to(name, image = nil, options = nil, html_options = {}) - html_options[:class] = class_names(html_options[:class], 'button') - image_element_to(:link, name, image, options, html_options) - end + html_options[:class] = class_names( + html_options[:class], + 'button', + dangerous: html_options[:method] == :delete + ) + if html_options[:onclick]&.is_a? Hash + html_options[:onclick] = "return confirm('\#{html_options[:onclick][:confirm]}');" + end - def image_tab_to(name, image = nil, options = nil, html_options = {}) - image_element_to(:link, name, image, options, html_options) + send :#{method_name}, name, options, html_options, &block + end + RUBY_EVAL end def render_errors(record) @@ -120,24 +125,6 @@ module ApplicationHelper private - def image_element_to(type, name, image = nil, options = nil, html_options = {}) - current = html_options.delete(:current) - current = nil unless url_for(options) == request.path - return '' if current == :hide - - name = svg_tag("pictograms/#{image}") + name if image - html_options[:class] = class_names( - html_options[:class], - active: current == :active, - dangerous: html_options[:method] == :delete - ) - if html_options[:onclick]&.is_a? Hash - html_options[:onclick] = "return confirm('#{html_options[:onclick][:confirm]}');" - end - - send "#{type}_to", name, options, html_options - end - # Converts value to HTML formatted scientific notation def scientifize(d) sign, coefficient, base, exponent = d.split diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 705632d..06d918c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -26,8 +26,8 @@
<% if user_signed_in? %> - <%= image_link_to current_user.email, "account-wrench-outline", - edit_user_registration_path, current: :hide %> + <%= image_link_to_unless_current(current_user.email, "account-wrench-outline", + edit_user_registration_path) {} %> <% if current_user_disguised? %> <%= image_link_to t(".revert"), "incognito-off", revert_users_path %> <% else %> @@ -35,9 +35,9 @@ method: :delete %> <% end %> <% else %> - <%= image_link_to t(:sign_in), "login", new_user_session_path, current: :hide %> - <%= image_link_to t(:register), "account-plus-outline", new_user_registration_path, - current: :hide %> + <%= image_link_to_unless_current(t(:sign_in), "login", new_user_session_path) {} %> + <%= image_link_to_unless_current(t(:register), "account-plus-outline", + new_user_registration_path) {} %> <% end %>