Sha256: 153b0bf9b5274bf47da2bdf32bae7449949b1ef25c99d26aeb0d26bbdf2ef171

Contents?: true

Size: 1.29 KB

Versions: 38

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This class contains helpers needed in order for feature 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

38 entries across 38 versions & 2 rubygems

Version Path
decidim-admin-0.10.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.10.0 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.9.3 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.9.2 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.9.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.9.0 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.8.4 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.8.3 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.8.2 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.8.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.8.0 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.7.4 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.7.3 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.7.2 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.7.1 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.7.0 app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.6.8 app/helpers/decidim/admin/settings_helper.rb
decidim-0.6.8 decidim-admin/app/helpers/decidim/admin/settings_helper.rb
decidim-admin-0.6.7 app/helpers/decidim/admin/settings_helper.rb
decidim-0.6.7 decidim-admin/app/helpers/decidim/admin/settings_helper.rb