From fcaf1c7e79c1f2c9e5f95fd032e363ffc84b35e1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 8 Jun 2017 15:41:49 +0200 Subject: TableBuilder: Extract column header code to a new method Give this bit of code a better name. Update relevant TODOs. Refs #3479 --- app/helpers/table_builder_helper.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 161ffb17c..ee79fb4d1 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -195,11 +195,15 @@ module TableBuilderHelper pics = content_tag :span, pic1 + pic2, class: 'orderers' # This snake cases and downcases the class name. Should use the ActiveSupport method to do this - # TODO: Maybe give this whole thing a name so it's clearer what's going on. Also, figure out a way to maybe explicitise the dynamicness of getting the model type from the `collection`. - # TODO: move these two lines to a new method called `column_header_label` and rename `pics` to something like `icons` or arrow icons or some such - obj = collection.model.to_s.gsub('Chouette::', '').scan(/[A-Z][a-z]+/).join('_').downcase + # TODO: figure out a way to maybe explicitise the dynamicness of getting the model type from the `collection`. + # TODO: rename `pics` to something like `icons` or arrow icons or some such - (I18n.t("activerecord.attributes.#{obj}.#{key}") + pics).html_safe + (column_header_label(collection.model, key) + pics).html_safe end end + + def column_header_label(model, field) + model_underscored = model.to_s.gsub('Chouette::', '').scan(/[A-Z][a-z]+/).join('_').downcase + I18n.t("activerecord.attributes.#{model_underscored}.#{field}") + end end -- cgit v1.2.3