Sha256: f16134b6c38e9cabab3c38318d224b4bc198720b0c100aac14f2881f63ccf2ce

Contents?: true

Size: 1.29 KB

Versions: 22

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This class contains helpers needed in order for component settings to
    # properly render.
    module SettingsHelper
      TYPES = {
        boolean: :check_box,
        integer: :number_field,
        string: :text_field,
        text: :text_area
      }.freeze

      # Public: Renders a form field that matches a settings attribute's
      # type.
      #
      # form      - The form in which to render the field.
      # attribute - The Settings::Attribute instance with the
      #             description of the attribute.
      # name      - The name of the field.
      # options   - Extra options to be passed to the field helper.
      #
      # Returns a rendered form field.
      def settings_attribute_input(form, attribute, name, options = {})
        if attribute.translated?
          form.send(:translated, form_method_for_attribute(attribute), name, options.merge(tabs_id: "#{options[:tabs_prefix]}-#{name}-tabs"))
        else
          form.send(form_method_for_attribute(attribute), name, options)
        end
      end

      private

      def form_method_for_attribute(attribute)
        return :editor if attribute.type.to_sym == :text && attribute.editor?
        TYPES[attribute.type.to_sym]
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
decidim-admin-0.17.2 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.17.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.16.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.17.0 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.16.0 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.15.2 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.15.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.15.0 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.14.4 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.14.3 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.14.2 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.14.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.13.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.12.2 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.13.0 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.12.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.13.0.pre1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.12.0 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.11.2 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.12.0.pre app/helpers/decidim/admin/settings_helper.rb