Sha256: 1a052bcb476f814cc7d107777fee279befa9242367aa428d3f38eda06f4f42b7
Contents?: true
Size: 1.29 KB
Versions: 9
Compression:
Stored size: 1.29 KB
Contents
module ActiveAdminAddons class BoolBuilder < CustomBuilder DEFAULT_BOOLEAN_TRUE = '✔' DEFAULT_BOOLEAN_FALSE = '✗' def render if data i18n_lookup('true_value', DEFAULT_BOOLEAN_TRUE) else i18n_lookup('false_value', DEFAULT_BOOLEAN_FALSE) end end private def i18n_lookup(key, last_default) model_name = model.class.model_name.i18n_key scope = "activeadmin.addons.boolean" value = I18n.t("models.#{model_name}.#{attribute}.#{key}", default: '', scope: scope) value = I18n.t("models.#{model_name}.#{key}", default: '', scope: scope) if value.empty? value = I18n.t("default.#{key}", default: last_default, scope: scope) if value.empty? context.content_tag(:span, class: "bool-value #{key.dasherize}") do context.safe_concat(value.html_safe) end end end module BoolValues module ::ActiveAdmin module Views class TableFor def bool_column(*args, &block) column(*args) { |model| BoolBuilder.render(self, model, *args, &block) } end end class AttributesTable def bool_row(*args, &block) row(*args) { |model| BoolBuilder.render(self, model, *args, &block) } end end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems