Sha256: 8f86f1a453897a8c04b75651791328e6e8b8d25d9a544125851e5a0352f50d38

Contents?: true

Size: 938 Bytes

Versions: 21

Compression:

Stored size: 938 Bytes

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?

      context.content_tag(:span, class: "bool-value #{key.dasherize}") do
        context.safe_concat(value.html_safe)
      end
    end
  end
end

ActiveAdminAddons::BoolBuilder.create_view_methods

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
activeadmin_addons-2.0.0.beta.3 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.10.1 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-2.0.0.beta.2 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-2.0.0.beta.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.10.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.9.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.8.3 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.8.2 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons_rails6-1.7.2 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.7.1 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.7.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.6.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.5.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.4.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.3.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.2.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.1.2 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.1.1 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.1.0 lib/activeadmin_addons/addons/bool_builder.rb
activeadmin_addons-1.0.1 lib/activeadmin_addons/addons/bool_builder.rb