Sha256: abb6dc684bd83be6d18577959ba28d0a012d39a3090a13a0038254f65e938725

Contents?: true

Size: 1.44 KB

Versions: 13

Compression:

Stored size: 1.44 KB

Contents

module ActiveAdminAddons
  class BoolBuilder < CustomBuilder
    DEFAULT_BOOLEAN_TRUE = '&#x2714;'
    DEFAULT_BOOLEAN_FALSE = '&#x2717;'

    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?

      value.html_safe

      #
      # model_i18n = "activeadmin.addons.boolean.models.#{model_name}.#{key}"
      # default_i18n = "activeadmin.addons.boolean.default.#{key}"
      #
      # I18n.t(model_i18n, default: I18n.t(default_i18n, default: last_default)).html_safe
    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

13 entries across 13 versions & 1 rubygems

Version Path
activeadmin_addons-0.6.4 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.6.3 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.6.2 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.6.1 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.6.0 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.5.0 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.4.0 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.3.4 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.3.3 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.3.2 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.3.1 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.3.0 lib/activeadmin_addons/addons/bool_values.rb
activeadmin_addons-0.2.8 lib/activeadmin_addons/addons/bool_values.rb