Sha256: f217d6b89038e483d2b29dc671a7ee1c7e798ae84b76c6465c67a638f608738e

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

module Comfy
  module Admin
    module CmsHelper
      # Wrapper around Comfy::FormBuilder
      def comfy_form_with(**options, &block)
        form_options = options.merge(builder: ComfortableMediaSurfer::FormBuilder)
        form_options[:bootstrap]  = { layout: :horizontal }
        form_options[:local]      = true
        bootstrap_form_with(**form_options, &block)
      end

      def comfy_admin_partial(path, params = {})
        render path, params
      rescue ActionView::MissingTemplate
        if ComfortableMediaSurfer.config.reveal_cms_partials
          content_tag(:div, class: 'comfy-admin-partial') do
            path
          end
        end
      end

      # Injects some content somewhere inside cms admin area
      def cms_hook(name, options = {})
        ComfortableMediaSurfer::ViewHooks.render(name, self, options)
      end

      # @param [String] fragment_id
      # @param [ActiveStorage::Blob] attachment
      # @param [Boolean] multiple
      # @return [String] {{ cms:page_file_link #{fragment_id}, ... }}
      def cms_page_file_link_tag(fragment_id:, attachment:, multiple:)
        filename  = ", filename: \"#{attachment.filename}\""  if multiple
        as        = ', as: image'                             if attachment.image?
        "{{ cms:page_file_link #{fragment_id}#{filename}#{as} }}"
      end

      # @param [Comfy::Cms::File] file
      # @return [String] {{ cms:file_link #{file.id}, ... }}
      def cms_file_link_tag(file)
        if file.attachment.image?
          "{{ cms:image #{file.label} }}"
        else
          "{{ cms:file_link #{file.id} }}"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comfortable_media_surfer-3.0.0 app/helpers/comfy/admin/cms_helper.rb