Sha256: f6e82909590602ce3fe4f8046f7c757fcef902492cc2272b0496612608d115ae

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module PagesCore
  module Admin
    class FormBuilder < PagesCore::FormBuilder
      include DynamicImage::Helper

      def rich_text_area(attr, options = {})
        @template.rich_text_area_tag(
          "#{object_name}[#{attr}]",
          object.send(attr),
          options
        )
      end

      def image_uploader(attr, options = {})
        @template.image_uploader_tag(
          "#{object_name}[#{foreign_key(attr)}]",
          object.send(attr),
          options
        )
      end

      def labelled_rich_text_area(attribute, label_text = nil, options = {})
        labelled_field(attribute, label_text, options) do |opts|
          rich_text_area(attribute, opts)
        end
      end

      def labelled_image_uploader(attribute, label_text = nil, options = {})
        labelled_field(attribute, label_text, options) do |opts|
          image_uploader(attribute, opts)
        end
      end

      private

      def foreign_key(attr)
        object.class.reflections[attr.to_s].options[:foreign_key] ||
          "#{attr}_id".to_sym
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
pages_core-3.10.2 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.10.1 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.9.2 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.9.1 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.9.0 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.8.3 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.8.2 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.8.1 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.8.0 app/helpers/pages_core/admin/form_builder.rb
pages_core-3.7.0 app/helpers/pages_core/admin/form_builder.rb