diff options
| author | Teddy Wing | 2017-06-08 15:41:49 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-08 15:41:49 +0200 |
| commit | fcaf1c7e79c1f2c9e5f95fd032e363ffc84b35e1 (patch) | |
| tree | b29a118b84ee7cc4f6e66c7ef60f307ec15bc660 /app | |
| parent | 01417ebaeec1150be5ce976c70322ef4f91e22af (diff) | |
| download | chouette-core-fcaf1c7e79c1f2c9e5f95fd032e363ffc84b35e1.tar.bz2 | |
TableBuilder: Extract column header code to a new method
Give this bit of code a better name. Update relevant TODOs.
Refs #3479
Diffstat (limited to 'app')
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 12 |
1 files 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 |
